From 1d8eeafdc3d8de542114dc135089345eed450c69 Mon Sep 17 00:00:00 2001 From: Alex Grebenyuk Date: Fri, 22 Nov 2024 05:30:31 -0500 Subject: [PATCH] Hide toolbar for AFK posts (#23850) --- .../Reader/Cards/ReaderPostCell.swift | 20 ++++++++++++++++--- .../Cards/ReaderPostCellViewModel.swift | 5 +++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift index 7842267e7b51..d16f15279b1a 100644 --- a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift @@ -1,6 +1,7 @@ import SwiftUI import UIKit import Combine +import WordPressShared final class ReaderPostCell: ReaderStreamBaseCell { private let view = ReaderPostCellView() @@ -71,6 +72,7 @@ private final class ReaderPostCellView: UIView { let imageView = AsyncImageView() // Footer + private lazy var toolbarView = UIStackView(buttons.allButtons) let buttons = ReaderPostToolbarButtons() private lazy var postPreview = UIStackView(axis: .vertical, alignment: .leading, spacing: 12, [ @@ -89,6 +91,7 @@ private final class ReaderPostCellView: UIView { private var viewModel: ReaderPostCellViewModel? // important: has to retain + private var toolbarViewHeightConstraint: NSLayoutConstraint? private var imageViewConstraints: [NSLayoutConstraint] = [] private var cancellables: [AnyCancellable] = [] @@ -106,6 +109,11 @@ private final class ReaderPostCellView: UIView { } func prepareForReuse() { + if let constraint = toolbarViewHeightConstraint { + constraint.isActive = false + toolbarView.isHidden = false + toolbarViewHeightConstraint = nil + } cancellables = [] avatarView.prepareForReuse() imageView.prepareForReuse() @@ -141,7 +149,6 @@ private final class ReaderPostCellView: UIView { // These seems to be an issue with `lineBreakMode` in `UIButton.Configuration` // and `.firstLineBaseline`, so reserving to `.center`. let headerView = UIStackView(alignment: .center, [buttonAuthor, dot, timeLabel]) - let toolbarView = UIStackView(buttons.allButtons) for view in [avatarView, headerView, postPreview, buttonMore, toolbarView] { addSubview(view) @@ -294,8 +301,15 @@ private final class ReaderPostCellView: UIView { imageView.setImage(with: imageURL, size: preferredCoverSize) } - configureToolbar(with: viewModel.toolbar) - configureToolbarAccessibility(with: viewModel.toolbar) + if !viewModel.isToolbarHidden { + configureToolbar(with: viewModel.toolbar) + configureToolbarAccessibility(with: viewModel.toolbar) + } else { + let constraint = toolbarView.heightAnchor.constraint(equalToConstant: 12) + constraint.isActive = true + toolbarView.isHidden = true + toolbarViewHeightConstraint = constraint + } } private var preferredCoverSize: CGSize? { diff --git a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCellViewModel.swift b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCellViewModel.swift index 95c8e0995ff0..0c725e10b6ef 100644 --- a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCellViewModel.swift +++ b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCellViewModel.swift @@ -12,6 +12,7 @@ final class ReaderPostCellViewModel { let imageURL: URL? // Footer (Buttons) + private(set) var isToolbarHidden = false let toolbar: ReaderPostToolbarViewModel weak var viewController: ReaderStreamViewController? @@ -36,7 +37,11 @@ final class ReaderPostCellViewModel { self.title = post.titleForDisplay() ?? "" self.details = post.contentPreviewForDisplay() ?? "" self.imageURL = post.featuredImageURLForDisplay() + self.toolbar = ReaderPostToolbarViewModel.make(post: post) + if isP2 && post.primaryTag == "afk" { + self.isToolbarHidden = true + } if isP2 { self.avatarURL = post.authorAvatarURL.flatMap(URL.init)