From e862588b828b8ea08b67bf20eb90f3d43c2c77e4 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 11 May 2022 09:55:28 -0300 Subject: [PATCH] Update translation driver --- .../Internal/Extensions/UIScrollViiew+Utils.swift | 8 +++++++- .../Internal/ScrollViewOverlayTranslationDriver.swift | 9 ++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Source/Classes/Internal/Extensions/UIScrollViiew+Utils.swift b/Source/Classes/Internal/Extensions/UIScrollViiew+Utils.swift index f605315..f62991f 100644 --- a/Source/Classes/Internal/Extensions/UIScrollViiew+Utils.swift +++ b/Source/Classes/Internal/Extensions/UIScrollViiew+Utils.swift @@ -13,12 +13,18 @@ extension UIScrollView { return panGestureRecognizer.yDirection == .up } + var scrollsDown: Bool { + return panGestureRecognizer.yDirection == .down + } + var isContentOriginInBounds: Bool { topOffsetInContent <= 0.0 } var isContentReachedBottom: Bool { - return topOffsetInContent >= (contentSize.height - frame.size.height) + let distanceFromBottom = contentSize.height - topOffsetInContent +// print("distance \(distanceFromBottom) content \(contentSize.height) height \(frame.height)") + return distanceFromBottom < frame.height } var topOffsetInContent: CGFloat { diff --git a/Source/Classes/Internal/ScrollViewOverlayTranslationDriver.swift b/Source/Classes/Internal/ScrollViewOverlayTranslationDriver.swift index 684f289..fb15f1e 100644 --- a/Source/Classes/Internal/ScrollViewOverlayTranslationDriver.swift +++ b/Source/Classes/Internal/ScrollViewOverlayTranslationDriver.swift @@ -75,9 +75,7 @@ class ScrollViewOverlayTranslationDriver: OverlayTranslationDriver, OverlayScrol case .bottom where targetContentOffset.pointee.y > -scrollView.oc_adjustedContentInset.top: // (gz) 2018-11-26 The user raises its finger in the bottom position // and the content offset will exceed the top content inset. - // (Thomas) commented line above to allow scroll up when in the middle of content -// targetContentOffset.pointee.y = -scrollView.oc_adjustedContentInset.top - break + targetContentOffset.pointee.y = -scrollView.oc_adjustedContentInset.top case .inFlight where !controller.overlayHasReachedANotch(): targetContentOffset.pointee.y = lastContentOffsetWhileScrolling.y case .top, .bottom, .inFlight, .stationary: @@ -102,11 +100,12 @@ class ScrollViewOverlayTranslationDriver: OverlayTranslationDriver, OverlayScrol let movesUp = velocity < 0 switch controller.translationPosition { case .bottom: - return scrollView.isContentReachedBottom && scrollView.scrollsUp + return !scrollView.isContentOriginInBounds && scrollView.scrollsUp case .top: return scrollView.isContentOriginInBounds && !movesUp case .inFlight: - return scrollView.isContentOriginInBounds || scrollView.scrollsUp + return (scrollView.isContentReachedBottom && scrollView.scrollsUp) || + (scrollView.isContentOriginInBounds && scrollView.scrollsDown) case .stationary: return false }