From 73a5bca3868ebd1c21603f18eeb1ec0900bc448a Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Wed, 8 Feb 2023 17:58:12 +0000 Subject: [PATCH] Update the timeline to correctly fix it to the bottom in UI tests. (#553) --- .../View/TimelineTableViewController.swift | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ElementX/Sources/Screens/RoomScreen/View/TimelineTableViewController.swift b/ElementX/Sources/Screens/RoomScreen/View/TimelineTableViewController.swift index 594bb8878..9d1505607 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/TimelineTableViewController.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/TimelineTableViewController.swift @@ -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() @@ -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) - if height > 0 { - let frame = CGRect(origin: .zero, size: CGSize(width: tableView.contentSize.width, height: height)) + guard newHeight != headerHeight else { return } + + 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