Skip to content

Commit

Permalink
Hide toolbar for AFK posts (#23850)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Nov 22, 2024
1 parent e50120a commit 1d8eeaf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
20 changes: 17 additions & 3 deletions WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import SwiftUI
import UIKit
import Combine
import WordPressShared

final class ReaderPostCell: ReaderStreamBaseCell {
private let view = ReaderPostCellView()
Expand Down Expand Up @@ -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, [
Expand All @@ -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] = []

Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class ReaderPostCellViewModel {
let imageURL: URL?

// Footer (Buttons)
private(set) var isToolbarHidden = false
let toolbar: ReaderPostToolbarViewModel

weak var viewController: ReaderStreamViewController?
Expand All @@ -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)
Expand Down

0 comments on commit 1d8eeaf

Please sign in to comment.