From 07f90e3df3dc22bf56385ed6c59f42e2947ed44a Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Fri, 21 Mar 2025 12:56:54 +0400 Subject: [PATCH] [ios] fix internal scroll scrolling to the top When the user starts scrolling to the top from the halfscreen position the internal scroll continues scrolling the table even if the content offset is zero. This commit fixes it. Signed-off-by: Kiryl Kaveryn --- .../SearchOnMap/SearchOnMapViewController.swift | 15 +++++++++++++-- .../SearchCategoriesViewController.swift | 4 ++++ .../UI/Search/Tabs/SearchTabViewController.swift | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift index 3af4dba94f..604be50881 100644 --- a/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift +++ b/iphone/Maps/UI/Search/SearchOnMap/SearchOnMapViewController.swift @@ -7,6 +7,7 @@ protocol SearchOnMapView: AnyObject { @objc protocol SearchOnMapScrollViewDelegate: AnyObject { func scrollViewDidScroll(_ scrollView: UIScrollView) + func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) } @objc @@ -463,8 +464,11 @@ extension SearchOnMapViewController: UIGestureRecognizerDelegate { } func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { - // threshold is used to soften transition from the internal scroll zero content offset - internalScrollViewContentOffset < Constants.panGestureThreshold + if gestureRecognizer is UIPanGestureRecognizer && otherGestureRecognizer is UIPanGestureRecognizer { + // threshold is used to soften transition from the internal scroll zero content offset + return internalScrollViewContentOffset < Constants.panGestureThreshold + } + return false } } @@ -480,4 +484,11 @@ extension SearchOnMapViewController: SearchOnMapScrollViewDelegate { } internalScrollViewContentOffset = scrollView.contentOffset.y } + + func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { + // lock internal scroll view when the user fast scrolls screen to the top + if internalScrollViewContentOffset == 0 { + targetContentOffset.pointee = .zero + } + } } diff --git a/iphone/Maps/UI/Search/Tabs/CategoriesTab/SearchCategoriesViewController.swift b/iphone/Maps/UI/Search/Tabs/CategoriesTab/SearchCategoriesViewController.swift index 4ce8ae6453..ce5abe53e9 100644 --- a/iphone/Maps/UI/Search/Tabs/CategoriesTab/SearchCategoriesViewController.swift +++ b/iphone/Maps/UI/Search/Tabs/CategoriesTab/SearchCategoriesViewController.swift @@ -45,6 +45,10 @@ final class SearchCategoriesViewController: MWMTableViewController { delegate?.scrollViewDidScroll(scrollView) } + override func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { + delegate?.scrollViewWillEndDragging(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset) + } + func category(at indexPath: IndexPath) -> String { let index = indexPath.row return categories[index] diff --git a/iphone/Maps/UI/Search/Tabs/SearchTabViewController.swift b/iphone/Maps/UI/Search/Tabs/SearchTabViewController.swift index b770bf063d..2dfe98f800 100644 --- a/iphone/Maps/UI/Search/Tabs/SearchTabViewController.swift +++ b/iphone/Maps/UI/Search/Tabs/SearchTabViewController.swift @@ -63,6 +63,10 @@ extension SearchTabViewController: SearchOnMapScrollViewDelegate { func scrollViewDidScroll(_ scrollView: UIScrollView) { delegate?.scrollViewDidScroll(scrollView) } + + func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { + delegate?.scrollViewWillEndDragging(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset) + } } extension SearchTabViewController: SearchCategoriesViewControllerDelegate {