Skip to content

Commit 6821b26

Browse files
authored
Fix an inappropriate condition to determine scrolling content or not (#633)
Removed the `pre > .zero` condition from `FloatingPanelLayoutAnchor` as it was not appropriate for zero or negative `absoluteInset` values. Added documentation for `shouldScrollingContentInMoving(from:to:)` to prevent similar mistakes in the future.
1 parent 5bdbe0f commit 6821b26

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

Sources/Core.swift

+24-14
Original file line numberDiff line numberDiff line change
@@ -656,14 +656,19 @@ class Core: NSObject, UIGestureRecognizerDelegate {
656656
}
657657

658658
private func panningChange(with translation: CGPoint) {
659-
os_log(msg, log: devLog, type: .debug, "panningChange -- translation = \(value(of: translation))")
660659
let pre = value(of: layoutAdapter.surfaceLocation)
661660
let diff = value(of: translation - initialTranslation)
662661
let next = pre + diff
663662

664-
layoutAdapter.updateInteractiveEdgeConstraint(diff: diff,
665-
scrollingContent: shouldScrollingContentInMoving(from: pre, to: next),
666-
allowsRubberBanding: behaviorAdapter.allowsRubberBanding(for:))
663+
os_log(msg, log: devLog, type: .debug, """
664+
panningChange -- translation = \(value(of: translation)), diff = \(diff), pre = \(pre), next = \(next)
665+
""")
666+
667+
layoutAdapter.updateInteractiveEdgeConstraint(
668+
diff: diff,
669+
scrollingContent: shouldScrollingContentInMoving(from: pre, to: next),
670+
allowsRubberBanding: behaviorAdapter.allowsRubberBanding(for:)
671+
)
667672

668673
let cur = value(of: layoutAdapter.surfaceLocation)
669674

@@ -676,31 +681,36 @@ class Core: NSObject, UIGestureRecognizerDelegate {
676681
}
677682
}
678683

679-
private func shouldScrollingContentInMoving(from pre: CGFloat, to next: CGFloat) -> Bool {
684+
/// Determines if the content should scroll while the surface is moving from `cur` to `target`.
685+
///
686+
/// - Note: `cur` argument starts from an anchor location of surface view in a state. For example,
687+
/// it starts from zero if the state is full whose FloatingPanelLayoutAnchor.absoluteInset is zero
688+
/// and there is no additional safe area insets like a navigation bar. Therefore, `cur` argument
689+
/// can be minus if the absoluteInset is minus with such a condition.
690+
private func shouldScrollingContentInMoving(from cur: CGFloat, to target: CGFloat) -> Bool {
680691
// Don't allow scrolling if the initial panning location is in the grabber area.
681692
if surfaceView.grabberAreaContains(initialLocation) {
682693
return false
683694
}
684-
if let scrollView = scrollView, scrollView.panGestureRecognizer.state == .changed {
695+
if let sv = scrollView, sv.panGestureRecognizer.state == .changed {
696+
let (contentSize, bounds, alwaysBounceHorizontal, alwaysBounceVertical)
697+
= (sv.contentSize, sv.bounds, sv.alwaysBounceHorizontal, sv.alwaysBounceVertical)
698+
685699
switch layoutAdapter.position {
686700
case .top:
687-
if pre > .zero, pre < next,
688-
scrollView.contentSize.height > scrollView.bounds.height || scrollView.alwaysBounceVertical {
701+
if cur < target, contentSize.height > bounds.height || alwaysBounceVertical {
689702
return true
690703
}
691704
case .left:
692-
if pre > .zero, pre < next,
693-
scrollView.contentSize.width > scrollView.bounds.width || scrollView.alwaysBounceHorizontal {
705+
if cur < target, contentSize.width > bounds.width || alwaysBounceHorizontal {
694706
return true
695707
}
696708
case .bottom:
697-
if pre > .zero, pre > next,
698-
scrollView.contentSize.height > scrollView.bounds.height || scrollView.alwaysBounceVertical {
709+
if cur > target, contentSize.height > bounds.height || alwaysBounceVertical {
699710
return true
700711
}
701712
case .right:
702-
if pre > .zero, pre > next,
703-
scrollView.contentSize.width > scrollView.bounds.width || scrollView.alwaysBounceHorizontal {
713+
if cur > target, contentSize.width > bounds.width || alwaysBounceHorizontal {
704714
return true
705715
}
706716
}

0 commit comments

Comments
 (0)