Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader: Hide toolbar for AFK posts #23850

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = ImageView()

// 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 @@ -292,8 +299,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