From eda552c7c996ac0c1a0339c6bf4413977a377675 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 30 Mar 2024 15:17:26 -0400 Subject: [PATCH] Add pointer interactions to gallery controls --- .../GalleryVC/GalleryItemViewController.swift | 8 +++++ .../Gallery/VideoControlsViewController.swift | 4 +++ .../Gallery/VideoOverlayViewController.swift | 33 ++++++++++++++----- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift index 29a7dd31..c8c10953 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift @@ -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) diff --git a/Tusker/Screens/Gallery/VideoControlsViewController.swift b/Tusker/Screens/Gallery/VideoControlsViewController.swift index 77f340db..526b266d 100644 --- a/Tusker/Screens/Gallery/VideoControlsViewController.swift +++ b/Tusker/Screens/Gallery/VideoControlsViewController.swift @@ -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) { diff --git a/Tusker/Screens/Gallery/VideoOverlayViewController.swift b/Tusker/Screens/Gallery/VideoOverlayViewController.swift index b22e78ca..07b606d8 100644 --- a/Tusker/Screens/Gallery/VideoOverlayViewController.swift +++ b/Tusker/Screens/Gallery/VideoOverlayViewController.swift @@ -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))) + } +}