From 13d47eabff41cc1e740232fb80438cf07fe06ae8 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Tue, 24 Jan 2023 15:10:12 -0500 Subject: [PATCH] =?UTF-8?q?Add=20pointer=20interactions=20where=20it?= =?UTF-8?q?=E2=80=99s=20easy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Discovery/View/DiscoveryIntroBannerView.swift | 2 ++ ...storySectionHeaderCollectionReusableView.swift | 2 ++ .../MastodonUI/View/Button/AvatarButton.swift | 14 ++++++++++++++ .../MastodonUI/View/Button/HUDButton.swift | 1 + .../View/Button/HighlightDimmableButton.swift | 1 + .../View/Button/RoundedEdgesButton.swift | 15 ++++++++++++++- .../View/Content/StatusAuthorView.swift | 2 ++ .../View/Content/StatusCardControl.swift | 10 ++++++++++ .../View/Content/StatusMetricView.swift | 2 ++ 9 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Mastodon/Scene/Discovery/View/DiscoveryIntroBannerView.swift b/Mastodon/Scene/Discovery/View/DiscoveryIntroBannerView.swift index 4925410624..b71447129b 100644 --- a/Mastodon/Scene/Discovery/View/DiscoveryIntroBannerView.swift +++ b/Mastodon/Scene/Discovery/View/DiscoveryIntroBannerView.swift @@ -38,6 +38,8 @@ public final class DiscoveryIntroBannerView: UIView { let button = HitTestExpandedButton(type: .system) button.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal) button.tintColor = Asset.Colors.Label.secondary.color + button.isPointerInteractionEnabled = true + button.pointerStyleProvider = { _, effect, _ in UIPointerStyle(effect: .lift(effect.preview)) } return button }() diff --git a/Mastodon/Scene/Search/SearchDetail/SearchHistory/Cell/SearchHistorySectionHeaderCollectionReusableView.swift b/Mastodon/Scene/Search/SearchDetail/SearchHistory/Cell/SearchHistorySectionHeaderCollectionReusableView.swift index 4af94304fb..0db2802595 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchHistory/Cell/SearchHistorySectionHeaderCollectionReusableView.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchHistory/Cell/SearchHistorySectionHeaderCollectionReusableView.swift @@ -32,6 +32,8 @@ final class SearchHistorySectionHeaderCollectionReusableView: UICollectionReusab let button = UIButton(type: .system) button.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal) button.tintColor = Asset.Colors.Label.secondary.color + button.isPointerInteractionEnabled = true + button.pointerStyleProvider = { _, effect, _ in UIPointerStyle(effect: .lift(effect.preview)) } return button }() diff --git a/MastodonSDK/Sources/MastodonUI/View/Button/AvatarButton.swift b/MastodonSDK/Sources/MastodonUI/View/Button/AvatarButton.swift index d970ac69cf..da0f0d75f0 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Button/AvatarButton.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Button/AvatarButton.swift @@ -33,6 +33,8 @@ open class AvatarButton: UIControl { avatarImageView.translatesAutoresizingMaskIntoConstraints = false addSubview(avatarImageView) avatarImageView.pinToParent() + + addInteraction(UIPointerInteraction(delegate: self)) isAccessibilityElement = true accessibilityLabel = L10n.Common.Controls.Status.showUserProfile @@ -56,6 +58,18 @@ open class AvatarButton: UIControl { } +extension AvatarButton: UIPointerInteractionDelegate { + public func pointerInteraction(_ interaction: UIPointerInteraction, regionFor request: UIPointerRegionRequest, defaultRegion: UIPointerRegion) -> UIPointerRegion? { + defaultRegion + } + public func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? { + UIPointerStyle( + effect: .automatic(UITargetedPreview(view: self)), + shape: UIPointerShape.roundedRect(avatarImageView.bounds, radius: avatarImageView.layer.cornerRadius) + ) + } +} + extension AvatarButton { public override var intrinsicContentSize: CGSize { diff --git a/MastodonSDK/Sources/MastodonUI/View/Button/HUDButton.swift b/MastodonSDK/Sources/MastodonUI/View/Button/HUDButton.swift index 26dda32d65..6cf8477b33 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Button/HUDButton.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Button/HUDButton.swift @@ -52,6 +52,7 @@ public class HUDButton: UIView { button.translatesAutoresizingMaskIntoConstraints = false vibrancyView.contentView.addSubview(button) button.pinToParent() + button.pointerStyleProvider = { _, _, _ in UIPointerStyle(effect: .lift(UITargetedPreview(view: self))) } NSLayoutConstraint.activate([ heightAnchor.constraint(equalToConstant: HUDButton.height).priority(.defaultHigh), ]) diff --git a/MastodonSDK/Sources/MastodonUI/View/Button/HighlightDimmableButton.swift b/MastodonSDK/Sources/MastodonUI/View/Button/HighlightDimmableButton.swift index c956c60410..629dad0bcf 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Button/HighlightDimmableButton.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Button/HighlightDimmableButton.swift @@ -36,5 +36,6 @@ final public class HighlightDimmableButton: UIButton { extension HighlightDimmableButton { private func _init() { adjustsImageWhenHighlighted = false + isPointerInteractionEnabled = true } } diff --git a/MastodonSDK/Sources/MastodonUI/View/Button/RoundedEdgesButton.swift b/MastodonSDK/Sources/MastodonUI/View/Button/RoundedEdgesButton.swift index 1fd6080917..a49c2f6eea 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Button/RoundedEdgesButton.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Button/RoundedEdgesButton.swift @@ -14,12 +14,25 @@ open class RoundedEdgesButton: UIButton { setNeedsDisplay() } } + + open override func willMove(toWindow newWindow: UIWindow?) { + super.willMove(toWindow: newWindow) + + isPointerInteractionEnabled = true + } open override func layoutSubviews() { super.layoutSubviews() layer.masksToBounds = true - layer.cornerRadius = cornerRadius > .zero ? cornerRadius : bounds.height * 0.5 + let radius = cornerRadius > .zero ? cornerRadius : bounds.height * 0.5 + layer.cornerRadius = radius + pointerStyleProvider = { _, _, _ in + UIPointerStyle( + effect: .lift(UITargetedPreview(view: self)), + shape: .roundedRect(self.frame, radius: radius) + ) + } } } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift index ef40ab7fc5..72d26906ce 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift @@ -48,6 +48,7 @@ public class StatusAuthorView: UIStackView { let image = UIImage(systemName: "ellipsis", withConfiguration: UIImage.SymbolConfiguration(font: .systemFont(ofSize: 15))) button.setImage(image, for: .normal) button.accessibilityLabel = L10n.Common.Controls.Status.Actions.menu + button.isPointerInteractionEnabled = true return button }() @@ -59,6 +60,7 @@ public class StatusAuthorView: UIStackView { button.imageView?.clipsToBounds = false let image = UIImage(systemName: "eye.slash.fill", withConfiguration: UIImage.SymbolConfiguration(font: .systemFont(ofSize: 15))) button.setImage(image, for: .normal) + button.isPointerInteractionEnabled = true return button }() diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift index 530ceea209..1c4ebd00a2 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift @@ -129,6 +129,7 @@ public final class StatusCardControl: UIControl { ]) addInteraction(UIContextMenuInteraction(delegate: self)) + addInteraction(UIPointerInteraction(delegate: self)) } required init?(coder: NSCoder) { @@ -305,6 +306,15 @@ extension StatusCardControl { } } +extension StatusCardControl: UIPointerInteractionDelegate { + public func pointerInteraction(_ interaction: UIPointerInteraction, regionFor request: UIPointerRegionRequest, defaultRegion: UIPointerRegion) -> UIPointerRegion? { + defaultRegion + } + public func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? { + UIPointerStyle(effect: .highlight(UITargetedPreview(view: self))) + } +} + private extension StatusCardControl { enum Layout: Equatable { case compact diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusMetricView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusMetricView.swift index d5f6a07096..294870b2b3 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusMetricView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusMetricView.swift @@ -51,6 +51,7 @@ public final class StatusMetricView: UIView { let button = UIButton(type: .system) button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 15, weight: .semibold)) button.setTitle("0 reblog", for: .normal) + button.isPointerInteractionEnabled = true return button }() @@ -59,6 +60,7 @@ public final class StatusMetricView: UIView { let button = UIButton(type: .system) button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 15, weight: .semibold)) button.setTitle("0 favorite", for: .normal) + button.isPointerInteractionEnabled = true return button }()