fix: status poll height not stable issue

This commit is contained in:
CMK 2021-07-23 20:03:39 +08:00
parent 7e811a6e8d
commit afb79fb870
3 changed files with 18 additions and 10 deletions

View File

@ -1035,6 +1035,7 @@ extension StatusSection {
} }
snapshot.appendItems(pollItems, toSection: .main) snapshot.appendItems(pollItems, toSection: .main)
cell.statusView.pollTableViewDataSource?.apply(snapshot, animatingDifferences: false, completion: nil) cell.statusView.pollTableViewDataSource?.apply(snapshot, animatingDifferences: false, completion: nil)
cell.statusView.pollTableViewHeightLayoutConstraint.constant = PollOptionTableViewCell.height * CGFloat(poll.options.count)
} }
static func configureActionToolBar( static func configureActionToolBar(

View File

@ -287,6 +287,7 @@ extension StatusView {
headerContainerStackView.trailingAnchor.constraint(equalTo: headerContainerView.trailingAnchor), headerContainerStackView.trailingAnchor.constraint(equalTo: headerContainerView.trailingAnchor),
headerContainerView.bottomAnchor.constraint(equalTo: headerContainerStackView.bottomAnchor, constant: StatusView.containerStackViewSpacing).priority(.defaultHigh), headerContainerView.bottomAnchor.constraint(equalTo: headerContainerStackView.bottomAnchor, constant: StatusView.containerStackViewSpacing).priority(.defaultHigh),
]) ])
headerContainerStackView.setContentCompressionResistancePriority(.required - 5, for: .vertical)
containerStackView.addArrangedSubview(headerContainerView) containerStackView.addArrangedSubview(headerContainerView)
defer { defer {
containerStackView.bringSubviewToFront(headerContainerView) containerStackView.bringSubviewToFront(headerContainerView)
@ -418,17 +419,21 @@ extension StatusView {
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
pollTableViewHeightLayoutConstraint, pollTableViewHeightLayoutConstraint,
]) ])
statusPollTableViewHeightObservation = pollTableView.observe(\.contentSize, options: .new, changeHandler: { [weak self] tableView, _ in // statusPollTableViewHeightObservation = pollTableView.observe(\.contentSize, options: .new, changeHandler: { [weak self] tableView, _ in
guard let self = self else { return } // guard let self = self else { return }
guard self.pollTableView.contentSize.height != .zero else { // guard self.pollTableView.contentSize.height != .zero else {
self.pollTableViewHeightLayoutConstraint.constant = 44 // self.pollTableViewHeightLayoutConstraint.constant = 44
return // return
} // }
self.pollTableViewHeightLayoutConstraint.constant = self.pollTableView.contentSize.height // self.pollTableViewHeightLayoutConstraint.constant = self.pollTableView.contentSize.height
}) // })
pollStatusStackView.translatesAutoresizingMaskIntoConstraints = false
statusContainerStackView.addArrangedSubview(pollStatusStackView) statusContainerStackView.addArrangedSubview(pollStatusStackView)
NSLayoutConstraint.activate([
pollStatusStackView.heightAnchor.constraint(equalToConstant: 30).priority(.required - 10)
])
pollStatusStackView.axis = .horizontal pollStatusStackView.axis = .horizontal
pollStatusStackView.addArrangedSubview(pollVoteCountLabel) pollStatusStackView.addArrangedSubview(pollVoteCountLabel)
pollStatusStackView.addArrangedSubview(pollStatusDotLabel) pollStatusStackView.addArrangedSubview(pollStatusDotLabel)

View File

@ -10,6 +10,8 @@ import Combine
final class PollOptionTableViewCell: UITableViewCell { final class PollOptionTableViewCell: UITableViewCell {
static let height: CGFloat = PollOptionView.height
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
let pollOptionView = PollOptionView() let pollOptionView = PollOptionView()