From f28751872d661e7f2a9887d943c8390196f56862 Mon Sep 17 00:00:00 2001 From: shannon Date: Tue, 17 Dec 2024 15:08:13 -0500 Subject: [PATCH] Adjust HitTestExpandedButton to MinimumHitTargetButton, which enforces minimum hit target size of 44x44 Contributes to IOS-143 --- .../View/DiscoveryIntroBannerView.swift | 4 ++-- .../NotificationView/NotificationView.swift | 2 +- ...ofileFieldAddEntryCollectionViewCell.swift | 2 +- .../ProfileFieldEditCollectionViewCell.swift | 2 +- .../View/Button/HitTestExpandedButton.swift | 18 ----------------- .../View/Button/MinimumHitTargetButton.swift | 20 +++++++++++++++++++ .../View/Content/StatusAuthorView.swift | 6 ++---- .../MastodonUI/View/Content/StatusView.swift | 2 +- 8 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 MastodonSDK/Sources/MastodonUI/View/Button/HitTestExpandedButton.swift create mode 100644 MastodonSDK/Sources/MastodonUI/View/Button/MinimumHitTargetButton.swift diff --git a/Mastodon/Scene/Discovery/View/DiscoveryIntroBannerView.swift b/Mastodon/Scene/Discovery/View/DiscoveryIntroBannerView.swift index 4f53f0f55..f0762870a 100644 --- a/Mastodon/Scene/Discovery/View/DiscoveryIntroBannerView.swift +++ b/Mastodon/Scene/Discovery/View/DiscoveryIntroBannerView.swift @@ -30,8 +30,8 @@ public final class DiscoveryIntroBannerView: UIView { return label }() - let closeButton: HitTestExpandedButton = { - let button = HitTestExpandedButton(type: .system) + let closeButton: MinimumHitTargetButton = { + let button = MinimumHitTargetButton(type: .system) button.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal) button.tintColor = Asset.Colors.Label.secondary.color return button diff --git a/Mastodon/Scene/Notification/NotificationView/NotificationView.swift b/Mastodon/Scene/Notification/NotificationView/NotificationView.swift index 6a98dc4ad..28fa03969 100644 --- a/Mastodon/Scene/Notification/NotificationView/NotificationView.swift +++ b/Mastodon/Scene/Notification/NotificationView/NotificationView.swift @@ -86,7 +86,7 @@ public final class NotificationView: UIView { public let dateLabel = MetaLabel(style: .statusUsername) public let menuButton: UIButton = { - let button = HitTestExpandedButton(type: .system) + let button = MinimumHitTargetButton(type: .system) button.tintColor = Asset.Colors.Label.secondary.color let image = UIImage(systemName: "ellipsis", withConfiguration: UIImage.SymbolConfiguration(font: .systemFont(ofSize: 15))) button.setImage(image, for: .normal) diff --git a/Mastodon/Scene/Profile/About/Cell/ProfileFieldAddEntryCollectionViewCell.swift b/Mastodon/Scene/Profile/About/Cell/ProfileFieldAddEntryCollectionViewCell.swift index e71e3fad7..ff4c40967 100644 --- a/Mastodon/Scene/Profile/About/Cell/ProfileFieldAddEntryCollectionViewCell.swift +++ b/Mastodon/Scene/Profile/About/Cell/ProfileFieldAddEntryCollectionViewCell.swift @@ -21,7 +21,7 @@ final class ProfileFieldAddEntryCollectionViewCell: UICollectionViewCell { let containerStackView = UIStackView() let editButton: UIButton = { - let button = HitTestExpandedButton(type: .custom) + let button = MinimumHitTargetButton(type: .custom) button.setImage(ProfileFieldAddEntryCollectionViewCell.insertButtonImage, for: .normal) button.contentMode = .center button.tintColor = .systemGreen diff --git a/Mastodon/Scene/Profile/About/Cell/ProfileFieldEditCollectionViewCell.swift b/Mastodon/Scene/Profile/About/Cell/ProfileFieldEditCollectionViewCell.swift index 7cc00ec5c..1aa7b53eb 100644 --- a/Mastodon/Scene/Profile/About/Cell/ProfileFieldEditCollectionViewCell.swift +++ b/Mastodon/Scene/Profile/About/Cell/ProfileFieldEditCollectionViewCell.swift @@ -29,7 +29,7 @@ final class ProfileFieldEditCollectionViewCell: UICollectionViewCell { let containerStackView = UIStackView() let editButton: UIButton = { - let button = HitTestExpandedButton(type: .custom) + let button = MinimumHitTargetButton(type: .custom) button.setImage(ProfileFieldEditCollectionViewCell.removeButtonImage, for: .normal) button.contentMode = .center button.tintColor = .systemRed diff --git a/MastodonSDK/Sources/MastodonUI/View/Button/HitTestExpandedButton.swift b/MastodonSDK/Sources/MastodonUI/View/Button/HitTestExpandedButton.swift deleted file mode 100644 index c07d1d8d0..000000000 --- a/MastodonSDK/Sources/MastodonUI/View/Button/HitTestExpandedButton.swift +++ /dev/null @@ -1,18 +0,0 @@ -// -// HitTestExpandedButton.swift -// Mastodon -// -// Created by sxiaojian on 2021/2/1. -// - -import UIKit - -public final class HitTestExpandedButton: UIButton { - - public var expandEdgeInsets = UIEdgeInsets(top: -10, left: -10, bottom: -10, right: -10) - - public override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { - return bounds.inset(by: expandEdgeInsets).contains(point) - } - -} diff --git a/MastodonSDK/Sources/MastodonUI/View/Button/MinimumHitTargetButton.swift b/MastodonSDK/Sources/MastodonUI/View/Button/MinimumHitTargetButton.swift new file mode 100644 index 000000000..25ac41ca7 --- /dev/null +++ b/MastodonSDK/Sources/MastodonUI/View/Button/MinimumHitTargetButton.swift @@ -0,0 +1,20 @@ +// +// HitTestExpandedButton.swift +// Mastodon +// +// Created by sxiaojian on 2021/2/1. +// + +import UIKit + +public final class MinimumHitTargetButton: UIButton { + + public var minimumTappableSize: CGSize = CGSize(width: 44, height: 44) + + public override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { + let sizeDiff = CGSize(width: minimumTappableSize.width - bounds.width, height: minimumTappableSize.height - bounds.height) + let expandedBounds = bounds.insetBy(dx: min(0, -(sizeDiff.width / 2)), dy: min(0, -(sizeDiff.height / 2))) + return expandedBounds.contains(point) + } + +} diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift index e460116d0..18c74d19d 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift @@ -41,8 +41,7 @@ public class StatusAuthorView: UIStackView { public let dateLabel = MetaLabel(style: .statusUsername) public let menuButton: UIButton = { - let button = HitTestExpandedButton(type: .system) - button.expandEdgeInsets = UIEdgeInsets(top: -20, left: -10, bottom: -10, right: -10) + let button = MinimumHitTargetButton(type: .system) button.tintColor = Asset.Colors.Label.secondary.color let image = UIImage(systemName: "ellipsis", withConfiguration: UIImage.SymbolConfiguration(font: .systemFont(ofSize: 15))) button.setImage(image, for: .normal) @@ -51,8 +50,7 @@ public class StatusAuthorView: UIStackView { }() public let contentSensitiveeToggleButton: UIButton = { - let button = HitTestExpandedButton(type: .system) - button.expandEdgeInsets = UIEdgeInsets(top: -20, left: -10, bottom: -10, right: -10) + let button = MinimumHitTargetButton(type: .system) button.tintColor = Asset.Colors.Label.secondary.color button.imageView?.contentMode = .scaleAspectFit let image = UIImage(systemName: "eye.slash.fill") diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift index 84e561250..2a7266141 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift @@ -394,7 +394,7 @@ public final class StatusView: UIView { return label }() let pollVoteButton: UIButton = { - let button = HitTestExpandedButton() + let button = MinimumHitTargetButton() button.titleLabel?.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 14, weight: .semibold)) button.setTitle(L10n.Common.Controls.Status.Poll.vote, for: .normal) button.setTitleColor(Asset.Colors.Brand.blurple.color, for: .normal)