From e010fe913043ee82984f764a9a44bad779ceb728 Mon Sep 17 00:00:00 2001 From: kean Date: Tue, 10 Dec 2024 10:32:05 -0500 Subject: [PATCH] Fix layout of cross-post cells --- .../Reader/Cards/ReaderCrossPostCell.swift | 51 ++++++++++++++++--- .../Reader/Cards/ReaderPostCell.swift | 7 --- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderCrossPostCell.swift b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderCrossPostCell.swift index 7dd1a5314e68..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,22 +68,18 @@ 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() - - selectedBackgroundView = ReaderPostCell.makeSelectedBackgroundView() } required init?(coder: NSCoder) { 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 d16f15279b1a..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 @@ -23,12 +22,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") }