From 1704c531de0c53fa748a5d8b4b7db54826dba86e Mon Sep 17 00:00:00 2001 From: Gil Eluard Date: Mon, 5 Sep 2022 23:32:11 +0200 Subject: [PATCH 1/2] Fixed last scrolling glitches in All Chats screen --- .../AllChats/AllChatsViewController.swift | 32 ++++++++++++++----- changelog.d/6680.bugfix | 1 + 2 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 changelog.d/6680.bugfix diff --git a/Riot/Modules/Home/AllChats/AllChatsViewController.swift b/Riot/Modules/Home/AllChats/AllChatsViewController.swift index d1df10be0..4a610a780 100644 --- a/Riot/Modules/Home/AllChats/AllChatsViewController.swift +++ b/Riot/Modules/Home/AllChats/AllChatsViewController.swift @@ -113,6 +113,7 @@ class AllChatsViewController: HomeViewController { searchController.obscuresBackgroundDuringPresentation = false searchController.searchResultsUpdater = self + searchController.delegate = self NotificationCenter.default.addObserver(self, selector: #selector(self.setupEditOptions), name: AllChatsLayoutSettingsManager.didUpdateSettings, object: nil) } @@ -197,7 +198,7 @@ class AllChatsViewController: HomeViewController { self.dataSource.currentSpace = space updateUI() - self.recentsTableView.setContentOffset(.zero, animated: true) + self.recentsTableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true) } override var recentsDataSourceMode: RecentsDataSourceMode { @@ -327,16 +328,22 @@ class AllChatsViewController: HomeViewController { // MARK: - Toolbar animation - private var lastScrollPosition: Double = 0 + private var initialScrollPosition: Double = 0 + + private func scrollPosition(of scrollView: UIScrollView) -> Double { + return scrollView.contentOffset.y + scrollView.adjustedContentInset.top + scrollView.adjustedContentInset.bottom + } override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { - lastScrollPosition = self.recentsTableView.contentOffset.y + initialScrollPosition = scrollPosition(of: scrollView) } override func scrollViewDidScroll(_ scrollView: UIScrollView) { super.scrollViewDidScroll(scrollView) + + let scrollPosition = scrollPosition(of: scrollView) - if self.recentsTableView.contentOffset.y == 0 { + if !self.recentsTableView.isDragging && scrollPosition == 0 && self.navigationController?.isToolbarHidden == true { self.navigationController?.setToolbarHidden(false, animated: true) } @@ -344,13 +351,14 @@ class AllChatsViewController: HomeViewController { return } - let scrollPosition = max(self.recentsTableView.contentOffset.y, 0) - guard scrollPosition < self.recentsTableView.contentSize.height - self.recentsTableView.bounds.height else { + guard scrollPosition > 0 && scrollPosition < self.recentsTableView.contentSize.height - self.recentsTableView.bounds.height else { return } - self.navigationController?.setToolbarHidden(scrollPosition - lastScrollPosition > 0, animated: true) - lastScrollPosition = scrollPosition + let isToolBarHidden: Bool = scrollPosition - initialScrollPosition > 0 + if isToolBarHidden != self.navigationController?.isToolbarHidden { + self.navigationController?.setToolbarHidden(isToolBarHidden, animated: true) + } } // MARK: - Empty view management @@ -648,6 +656,14 @@ extension AllChatsViewController: UISearchResultsUpdating { } +// MARK: - UISearchResultsUpdating +extension AllChatsViewController: UISearchControllerDelegate { + func willPresentSearchController(_ searchController: UISearchController) { + // Fix for https://github.com/vector-im/element-ios/issues/6680 + self.recentsTableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true) + } +} + // MARK: - UIAdaptivePresentationControllerDelegate extension AllChatsViewController: UIAdaptivePresentationControllerDelegate { diff --git a/changelog.d/6680.bugfix b/changelog.d/6680.bugfix new file mode 100644 index 000000000..78008d9a0 --- /dev/null +++ b/changelog.d/6680.bugfix @@ -0,0 +1 @@ +Fixed last scrolling glitches in All Chats screen From e3cc1f70e15a0b4e813841e69728c18e69bc5076 Mon Sep 17 00:00:00 2001 From: Gil Eluard Date: Mon, 5 Sep 2022 23:37:19 +0200 Subject: [PATCH 2/2] Fixed last scrolling glitches in All Chats screen - Changed comment --- Riot/Modules/Home/AllChats/AllChatsViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Riot/Modules/Home/AllChats/AllChatsViewController.swift b/Riot/Modules/Home/AllChats/AllChatsViewController.swift index 4a610a780..31efda335 100644 --- a/Riot/Modules/Home/AllChats/AllChatsViewController.swift +++ b/Riot/Modules/Home/AllChats/AllChatsViewController.swift @@ -656,7 +656,7 @@ extension AllChatsViewController: UISearchResultsUpdating { } -// MARK: - UISearchResultsUpdating +// MARK: - UISearchControllerDelegate extension AllChatsViewController: UISearchControllerDelegate { func willPresentSearchController(_ searchController: UISearchController) { // Fix for https://github.com/vector-im/element-ios/issues/6680