Skip to content

Commit

Permalink
Fix layout of cross-post cells
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Dec 10, 2024
1 parent c35ff67 commit e010fe9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
Expand Down

0 comments on commit e010fe9

Please sign in to comment.