feat: store view state to prevent redundant image rending

This commit is contained in:
CMK 2021-02-24 18:41:40 +08:00
parent 2988e71611
commit 10594d1eb6
3 changed files with 7 additions and 10 deletions

View File

@ -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 }

View File

@ -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()

View File

@ -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
}