From 2d1117ff1eb165ad574399dcf7c6a3eb6505ca2a Mon Sep 17 00:00:00 2001 From: kean Date: Tue, 10 Dec 2024 10:22:22 -0500 Subject: [PATCH 1/2] Remove makeSelectedBackgroundView --- .../ViewRelated/Reader/Cards/ReaderCrossPostCell.swift | 2 -- .../Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift | 6 ------ 2 files changed, 8 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderCrossPostCell.swift b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderCrossPostCell.swift index 7dd1a5314e68..368416212308 100644 --- a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderCrossPostCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderCrossPostCell.swift @@ -32,8 +32,6 @@ final class ReaderCrossPostCell: ReaderStreamBaseCell { setupStyle() setupLayout() - - selectedBackgroundView = ReaderPostCell.makeSelectedBackgroundView() } required init?(coder: NSCoder) { diff --git a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift index d16f15279b1a..8cd3ddb6bc4d 100644 --- a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift @@ -23,12 +23,6 @@ final class ReaderPostCell: ReaderStreamBaseCell { ]) } - static func makeSelectedBackgroundView() -> UIView { - let view = UIView() - view.backgroundColor = UIColor.opaqueSeparator.withAlphaComponent(0.2) - return view - } - required init?(coder: NSCoder) { fatalError("Not implemented") } From ede3bbc27769cc6ceb39350029fa10eaa651dd9e Mon Sep 17 00:00:00 2001 From: kean Date: Tue, 10 Dec 2024 10:28:52 -0500 Subject: [PATCH 2/2] Fix layout for cross-post cells --- .../Reader/Cards/ReaderCrossPostCell.swift | 49 +++++++++++++++++-- .../Reader/Cards/ReaderPostCell.swift | 1 - 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderCrossPostCell.swift b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderCrossPostCell.swift index 368416212308..1f3fa9f6e941 100644 --- a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderCrossPostCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderCrossPostCell.swift @@ -1,8 +1,49 @@ import Foundation import AutomatticTracks import WordPressShared +import WordPressUI final class ReaderCrossPostCell: ReaderStreamBaseCell { + private let view = ReaderCrossPostView() + private var contentViewConstraints: [NSLayoutConstraint] = [] + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.addSubview(view) + view.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + view.topAnchor.constraint(equalTo: contentView.topAnchor), + view.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).withPriority(999), + ]) + } + + required init?(coder: NSCoder) { + fatalError("Not implemented") + } + + override func prepareForReuse() { + super.prepareForReuse() + + view.prepareForReuse() + } + + func configure(with post: ReaderPost) { + view.configure(with: post) + } + + override func didUpdateCompact(_ isCompact: Bool) { + setNeedsUpdateConstraints() + } + + override func updateConstraints() { + NSLayoutConstraint.deactivate(contentViewConstraints) + contentViewConstraints = view.pinEdges(.horizontal, to: isCompact ? contentView : contentView.readableContentGuide) + super.updateConstraints() + } +} + +private final class ReaderCrossPostView: UIView { private let avatarView = ReaderAvatarView() private let iconView = ReaderAvatarView() private let headerLabel = UILabel() @@ -27,8 +68,8 @@ final class ReaderCrossPostCell: ReaderStreamBaseCell { .foregroundColor: UIColor.secondaryLabel ] - override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - super.init(style: style, reuseIdentifier: reuseIdentifier) + override init(frame: CGRect) { + super.init(frame: frame) setupStyle() setupLayout() @@ -38,9 +79,7 @@ final class ReaderCrossPostCell: ReaderStreamBaseCell { fatalError("Not implemented") } - override func prepareForReuse() { - super.prepareForReuse() - + func prepareForReuse() { avatarView.prepareForReuse() } diff --git a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift index 8cd3ddb6bc4d..0a6dfb11146d 100644 --- a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift @@ -5,7 +5,6 @@ import WordPressShared final class ReaderPostCell: ReaderStreamBaseCell { private let view = ReaderPostCellView() - private var contentViewConstraints: [NSLayoutConstraint] = [] static let avatarSize: CGFloat = SiteIconViewModel.Size.small.width