From 10594d1eb67153e775102877b8da7912ec75e61a Mon Sep 17 00:00:00 2001 From: CMK Date: Wed, 24 Feb 2021 18:41:40 +0800 Subject: [PATCH] feat: store view state to prevent redundant image rending --- Mastodon/Diffiable/Section/StatusSection.swift | 1 + .../HomeTimeline/HomeTimelineViewController.swift | 11 ++--------- Mastodon/Scene/Share/View/Content/StatusView.swift | 5 ++++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Mastodon/Diffiable/Section/StatusSection.swift b/Mastodon/Diffiable/Section/StatusSection.swift index 4cc19bdc..64b49ad2 100644 --- a/Mastodon/Diffiable/Section/StatusSection.swift +++ b/Mastodon/Diffiable/Section/StatusSection.swift @@ -96,6 +96,7 @@ extension StatusSection { // set content warning let isStatusTextSensitive = statusContentWarningAttribute?.isStatusTextSensitive ?? (toot.reblog ?? toot).sensitive + cell.statusView.isStatusTextSensitive = isStatusTextSensitive cell.statusView.updateContentWarningDisplay(isHidden: !isStatusTextSensitive) cell.statusView.contentWarningTitle.text = (toot.reblog ?? toot).spoilerText.flatMap { spoilerText in guard !spoilerText.isEmpty else { return nil } diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift index 906708fa..125ce854 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift @@ -200,14 +200,7 @@ extension HomeTimelineViewController: UITableViewDelegate { return ceil(frame.height) } - - func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { - if let cell = cell as? StatusTableViewCell { - DispatchQueue.main.async { - cell.statusView.drawContentWarningImageView() - } - } - } + } // MARK: - ContentOffsetAdjustableTimelineViewControllerDelegate @@ -227,7 +220,7 @@ extension HomeTimelineViewController: TimelineMiddleLoaderTableViewCellDelegate viewModel.loadMiddleSateMachineList .receive(on: DispatchQueue.main) .sink { [weak self] ids in - guard let self = self else { return } + guard let _ = self else { return } if let stateMachine = ids[upperTimelineIndexObjectID] { guard let state = stateMachine.currentState else { assertionFailure() diff --git a/Mastodon/Scene/Share/View/Content/StatusView.swift b/Mastodon/Scene/Share/View/Content/StatusView.swift index 1bedb945..d52def46 100644 --- a/Mastodon/Scene/Share/View/Content/StatusView.swift +++ b/Mastodon/Scene/Share/View/Content/StatusView.swift @@ -22,6 +22,7 @@ final class StatusView: UIView { static let contentWarningBlurRadius: CGFloat = 12 weak var delegate: StatusViewDelegate? + var isStatusTextSensitive = false let headerContainerStackView = UIStackView() @@ -281,7 +282,9 @@ extension StatusView { } func drawContentWarningImageView() { - guard activeTextLabel.frame != .zero, let text = activeTextLabel.text, !text.isEmpty else { + guard activeTextLabel.frame != .zero, + isStatusTextSensitive, + let text = activeTextLabel.text, !text.isEmpty else { cleanUpContentWarning() return }