Skip to content

Commit

Permalink
Update the timeline to correctly fix it to the bottom in UI tests. (#553
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pixlwave authored Feb 8, 2023
1 parent 22a9948 commit f7fbdcc
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ class TimelineTableViewController: UIViewController {
hasAppearedOnce = true
}

override func didMove(toParent parent: UIViewController?) {
super.didMove(toParent: parent)

// Ensure the padding is correct before display.
updateTopPadding()
}

override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()

Expand Down Expand Up @@ -286,11 +293,14 @@ class TimelineTableViewController: UIViewController {
/// Updates the additional padding added to the top of the table (via a header)
/// in order to fill the timeline from the bottom of the view upwards.
private func updateTopPadding() {
let contentHeight = tableView.contentSize.height - (tableView.tableHeaderView?.frame.height ?? 0)
let height = tableView.visibleSize.height - contentHeight
let headerHeight = tableView.tableHeaderView?.frame.height ?? 0
let contentHeight = tableView.contentSize.height - headerHeight
let newHeight = max(0, tableView.visibleSize.height - contentHeight)

guard newHeight != headerHeight else { return }

if height > 0 {
let frame = CGRect(origin: .zero, size: CGSize(width: tableView.contentSize.width, height: height))
if newHeight > 0 {
let frame = CGRect(origin: .zero, size: CGSize(width: tableView.contentSize.width, height: newHeight))
tableView.tableHeaderView = UIView(frame: frame) // Updating an existing view's height doesn't move the cells.
} else {
tableView.tableHeaderView = nil
Expand Down

0 comments on commit f7fbdcc

Please sign in to comment.