Skip to content

Commit

Permalink
Update translation driver
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdelgado committed May 11, 2022
1 parent ee71c0e commit e862588
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 7 additions & 1 deletion Source/Classes/Internal/Extensions/UIScrollViiew+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
}
Expand Down

0 comments on commit e862588

Please sign in to comment.