Add pointer interactions to gallery controls

This commit is contained in:
Shadowfacts 2024-03-30 15:17:26 -04:00
parent 841c08be2c
commit eda552c7c9
3 changed files with 37 additions and 8 deletions

View File

@ -97,6 +97,10 @@ class GalleryItemViewController: UIViewController {
shareConfig.image = UIImage(systemName: "square.and.arrow.up")
shareButton = UIButton(configuration: shareConfig)
shareButton.addTarget(self, action: #selector(shareButtonPressed), for: .touchUpInside)
shareButton.isPointerInteractionEnabled = true
shareButton.pointerStyleProvider = { button, effect, shape in
return UIPointerStyle(effect: .highlight(effect.preview), shape: .roundedRect(button.frame))
}
shareButton.translatesAutoresizingMaskIntoConstraints = false
updateShareButton()
topControlsView.addSubview(shareButton)
@ -108,6 +112,10 @@ class GalleryItemViewController: UIViewController {
closeConfig.image = UIImage(systemName: "xmark")
let closeButton = UIButton(configuration: closeConfig)
closeButton.addTarget(self, action: #selector(closeButtonPressed), for: .touchUpInside)
closeButton.isPointerInteractionEnabled = true
closeButton.pointerStyleProvider = { button, effect, shape in
return UIPointerStyle(effect: .highlight(effect.preview), shape: .roundedRect(button.frame))
}
closeButton.translatesAutoresizingMaskIntoConstraints = false
topControlsView.addSubview(closeButton)

View File

@ -348,6 +348,8 @@ private class MuteButton: UIControl {
imageView.centerXAnchor.constraint(equalTo: centerXAnchor),
imageView.centerYAnchor.constraint(equalTo: centerYAnchor),
])
addInteraction(UIPointerInteraction(delegate: nil))
}
required init?(coder: NSCoder) {
@ -395,6 +397,8 @@ private class MenuButton: UIControl {
isContextMenuInteractionEnabled = true
showsMenuAsPrimaryAction = true
addInteraction(UIPointerInteraction(delegate: nil))
}
required init?(coder: NSCoder) {

View File

@ -158,6 +158,8 @@ private class VideoOverlayButton: UIControl {
imageView.topAnchor.constraint(equalTo: topAnchor, constant: 8),
imageView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8),
])
addInteraction(UIPointerInteraction(delegate: self))
}
required init?(coder: NSCoder) {
@ -175,19 +177,23 @@ private class VideoOverlayButton: UIControl {
}
override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
UIView.animate(withDuration: 0.2) {
self.backgroundView.alpha = 1
self.backgroundView.transform = CGAffineTransform(scaleX: 1/0.8, y: 1/0.8)
self.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
if touch.type != .indirectPointer {
UIView.animate(withDuration: 0.2) {
self.backgroundView.alpha = 1
self.backgroundView.transform = CGAffineTransform(scaleX: 1/0.8, y: 1/0.8)
self.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
}
}
return super.beginTracking(touch, with: event)
}
override func endTracking(_ touch: UITouch?, with event: UIEvent?) {
UIView.animate(withDuration: 0.2) {
self.backgroundView.alpha = 0
self.backgroundView.transform = .identity
self.transform = .identity
if touch?.type != .indirectPointer {
UIView.animate(withDuration: 0.2) {
self.backgroundView.alpha = 0
self.backgroundView.transform = .identity
self.transform = .identity
}
}
}
@ -198,3 +204,14 @@ private class VideoOverlayButton: UIControl {
return true
}
}
extension VideoOverlayButton: UIPointerInteractionDelegate {
func pointerInteraction(_ interaction: UIPointerInteraction, regionFor request: UIPointerRegionRequest, defaultRegion: UIPointerRegion) -> UIPointerRegion? {
return UIPointerRegion(rect: bounds)
}
func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
let preview = UITargetedPreview(view: self)
return UIPointerStyle(effect: .highlight(preview), shape: .path(UIBezierPath(ovalIn: frame)))
}
}