From 412c5ee91d6956dfec32b35a3cba399f3171f914 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 7 Jul 2024 10:01:33 -0700 Subject: [PATCH] Fix multi column navigation not animating when scrolling back while replacing multiple columns --- .../Utilities/MultiColumnNavigationController.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Utilities/MultiColumnNavigationController.swift b/Tusker/Screens/Utilities/MultiColumnNavigationController.swift index b11bdd17e3..e43bd7f79d 100644 --- a/Tusker/Screens/Utilities/MultiColumnNavigationController.swift +++ b/Tusker/Screens/Utilities/MultiColumnNavigationController.swift @@ -17,7 +17,6 @@ protocol MultiColumnNavigationCustomTargetProviding { class MultiColumnNavigationController: UIViewController { - private var isManuallyUpdating = false private var _viewControllers: [UIViewController] = [] var viewControllers: [UIViewController] { get { @@ -25,8 +24,7 @@ class MultiColumnNavigationController: UIViewController { } set { _viewControllers = newValue - if isViewLoaded, - !isManuallyUpdating { + if isViewLoaded { updateViews() scrollToEnd(animated: false) } @@ -143,7 +141,14 @@ class MultiColumnNavigationController: UIViewController { } private func scrollColumnToEnd(columnIndex: Int, animated: Bool) { + // Laying out may change the content offset if we have fewer columns than before, + // but we want to keep the original offset so that we can animate smoothly to the final one. + let origContentOffset = scrollView.contentOffset scrollView.layoutIfNeeded() + if animated { + scrollView.contentOffset = origContentOffset + } + let column = stackView.arrangedSubviews[columnIndex] let columnFrame = column.convert(column.bounds, to: scrollView) let offset: CGFloat