From 41e1b75c62248c64349513bb969ab31462ec78db Mon Sep 17 00:00:00 2001 From: CMK Date: Mon, 18 Apr 2022 16:15:24 +0800 Subject: [PATCH] feat: add sensitive hint label for status media --- Localization/app.json | 1 + .../NotificationTimelineViewController.swift | 23 ++++++ .../Container/MediaGridContainerView.swift | 66 +++++------------ .../View/Content/StatusView+ViewModel.swift | 1 + .../Control/ContentWarningOverlayView.swift | 70 +++++-------------- 5 files changed, 61 insertions(+), 100 deletions(-) diff --git a/Localization/app.json b/Localization/app.json index 548c5ada..6c4aae7a 100644 --- a/Localization/app.json +++ b/Localization/app.json @@ -129,6 +129,7 @@ "show_post": "Show Post", "show_user_profile": "Show user profile", "content_warning": "Content Warning", + "sensitive_content": "Sensitive Content", "media_content_warning": "Tap anywhere to reveal", "tap_to_reveal": "Tap to reveal", "poll": { diff --git a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController.swift b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController.swift index bdb4d05c..16130251 100644 --- a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController.swift +++ b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController.swift @@ -39,6 +39,8 @@ final class NotificationTimelineViewController: UIViewController, NeedsDependenc return tableView }() + let cellFrameCache = NSCache() + deinit { os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function) } @@ -122,6 +124,16 @@ extension NotificationTimelineViewController { } +// MARK: - CellFrameCacheContainer +extension NotificationTimelineViewController: CellFrameCacheContainer { + func keyForCache(tableView: UITableView, indexPath: IndexPath) -> NSNumber? { + guard let diffableDataSource = viewModel.diffableDataSource else { return nil } + guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return nil } + let key = NSNumber(value: item.hashValue) + return key + } +} + extension NotificationTimelineViewController { @objc private func refreshControlValueChanged(_ sender: UIRefreshControl) { @@ -162,6 +174,13 @@ extension NotificationTimelineViewController: UITableViewDelegate, AutoGenerateT // sourcery:end + func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { + guard let frame = retrieveCellFrame(tableView: tableView, indexPath: indexPath) else { + return 300 + } + return ceil(frame.height) + } + func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { guard let item = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { return @@ -172,6 +191,10 @@ extension NotificationTimelineViewController: UITableViewDelegate, AutoGenerateT await viewModel.loadMore(item: item) } } + + func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { + cacheCellFrame(tableView: tableView, didEndDisplaying: cell, forRowAt: indexPath) + } } diff --git a/MastodonSDK/Sources/MastodonUI/View/Container/MediaGridContainerView.swift b/MastodonSDK/Sources/MastodonUI/View/Container/MediaGridContainerView.swift index cb9c53f3..e3359fb5 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Container/MediaGridContainerView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Container/MediaGridContainerView.swift @@ -48,22 +48,7 @@ public final class MediaGridContainerView: UIView { return mediaViews }() - -// let sensitiveToggleButtonBlurVisualEffectView: UIVisualEffectView = { -// let visualEffectView = UIVisualEffectView(effect: ContentWarningOverlayView.blurVisualEffect) -// visualEffectView.layer.masksToBounds = true -// visualEffectView.layer.cornerRadius = MediaGridContainerView.sensitiveToggleButtonSize.width / 2 -// visualEffectView.layer.cornerCurve = .continuous -// return visualEffectView -// }() -// let sensitiveToggleButtonVibrancyVisualEffectView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: ContentWarningOverlayView.blurVisualEffect)) -// let sensitiveToggleButton: HitTestExpandedButton = { -// let button = HitTestExpandedButton(type: .system) -// button.contentEdgeInsets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4) -// button.imageView?.contentMode = .scaleAspectFit -// button.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal) -// return button -// }() + let contentWarningOverlay = ContentWarningOverlayView() public override init(frame: CGRect) { super.init(frame: frame) @@ -86,7 +71,8 @@ public final class MediaGridContainerView: UIView { extension MediaGridContainerView { private func _init() { -// sensitiveToggleButton.addTarget(self, action: #selector(MediaGridContainerView.sensitiveToggleButtonDidPressed(_:)), for: .touchUpInside) + contentWarningOverlay.isUserInteractionEnabled = false + contentWarningOverlay.isHidden = true } } @@ -112,8 +98,8 @@ extension MediaGridContainerView { let mediaView = _mediaViews[0] layout.layout(in: self, mediaView: mediaView) -// layoutSensitiveToggleButton() -// bringSubviewToFront(sensitiveToggleButtonBlurVisualEffectView) + layoutContentWarningOverlay() + bringSubviewToFront(contentWarningOverlay) return mediaView } @@ -124,8 +110,8 @@ extension MediaGridContainerView { let mediaViews = Array(_mediaViews[0..