Skip to content

Commit 6532311

Browse files
committed
Extend the solution of issue #587 for another positions.
1 parent 74ce9ed commit 6532311

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

Sources/Core.swift

+22-13
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class Core: NSObject, UIGestureRecognizerDelegate {
395395
location = \(value(of: location)), velocity = \(velocity)
396396
""")
397397

398-
let offsetDiff = value(of: scrollView.contentOffset - contentOffsetForPinning(of: scrollView))
398+
let offsetDiff = offsetFromPinning(scrollView: scrollView)
399399

400400
if insideMostExpandedAnchor {
401401
// Scroll offset pinning
@@ -596,7 +596,7 @@ class Core: NSObject, UIGestureRecognizerDelegate {
596596
return false
597597
}
598598

599-
let offset = value(of: scrollView.contentOffset - contentOffsetForPinning(of: scrollView))
599+
let offset = offsetFromPinning(scrollView: scrollView)
600600
// The zero offset must be excluded because the offset is usually zero
601601
// after a panel moves from half/tip to full.
602602
switch layoutAdapter.position {
@@ -791,13 +791,13 @@ class Core: NSObject, UIGestureRecognizerDelegate {
791791
log.debug("startInteraction -- translation = \(value(of: translation)), location = \(value(of: location))")
792792
guard interactionInProgress == false else { return }
793793

794-
var offset: CGPoint = .zero
794+
var offset = 0.0
795795

796796
initialSurfaceLocation = layoutAdapter.surfaceLocation
797797
if state == layoutAdapter.mostExpandedState, let scrollView = scrollView {
798798
if surfaceView.grabberAreaContains(location) {
799799
initialScrollOffset = scrollView.contentOffset
800-
} else if value(of: scrollView.contentOffset) >= 0 {
800+
} else if distanceFromPinning(scrollView: scrollView) >= 0 {
801801
// The condition must be out of the range defined by `allowScrollPanGesture(for:)`, [-30, 0).
802802
// It can be true when a panel moves by dragging it with an overlay view,
803803
// for example, a user drags a panel at the bottom of the search bar in Maps example.
@@ -812,14 +812,14 @@ class Core: NSObject, UIGestureRecognizerDelegate {
812812
initialScrollOffset = pinningOffset
813813

814814
// Fit the surface bounds to a scroll offset content by startInteraction(at:offset:)
815-
let offsetDiff = scrollView.contentOffset - pinningOffset
815+
let offsetDiff = offsetFromPinning(scrollView: scrollView)
816816
switch layoutAdapter.position {
817817
case .top, .left:
818-
if value(of: offsetDiff) > 0 {
818+
if offsetDiff > 0 {
819819
offset = -offsetDiff
820820
}
821821
case .bottom, .right:
822-
if value(of: offsetDiff) < 0 {
822+
if offsetDiff < 0 {
823823
offset = -offsetDiff
824824
}
825825
}
@@ -1075,16 +1075,25 @@ class Core: NSObject, UIGestureRecognizerDelegate {
10751075
}
10761076
}
10771077

1078-
private func allowScrollPanGesture(for scrollView: UIScrollView) -> Bool {
1079-
guard state == layoutAdapter.mostExpandedState else { return false }
1080-
var offsetY: CGFloat = 0
1078+
private func offsetFromPinning(scrollView: UIScrollView) -> CGFloat {
1079+
return value(of: scrollView.contentOffset - contentOffsetForPinning(of: scrollView))
1080+
}
1081+
1082+
private func distanceFromPinning(scrollView: UIScrollView) -> CGFloat {
1083+
var offset = offsetFromPinning(scrollView: scrollView)
10811084
switch layoutAdapter.position {
10821085
case .top, .left:
1083-
offsetY = value(of: scrollView.fp_contentOffsetMax - scrollView.contentOffset)
1086+
offset = -offset
10841087
case .bottom, .right:
1085-
offsetY = value(of: scrollView.contentOffset - contentOffsetForPinning(of: scrollView))
1088+
break;
10861089
}
1087-
return offsetY <= -30.0 || offsetY > 0
1090+
return offset
1091+
}
1092+
1093+
private func allowScrollPanGesture(for scrollView: UIScrollView) -> Bool {
1094+
guard state == layoutAdapter.mostExpandedState else { return false }
1095+
var offset = distanceFromPinning(scrollView: scrollView)
1096+
return offset <= -30.0 || offset > 0
10881097
}
10891098

10901099
// MARK: - UIPanGestureRecognizer Intermediation

Sources/Layout.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ class LayoutAdapter {
480480
}
481481
}
482482

483-
func startInteraction(at state: FloatingPanelState, offset: CGPoint = .zero) {
483+
func startInteraction(at state: FloatingPanelState, offset: CGFloat = 0) {
484484
if let constraint = interactionConstraint {
485485
initialConst = constraint.constant
486486
return
@@ -490,7 +490,7 @@ class LayoutAdapter {
490490

491491
NSLayoutConstraint.deactivate(stateConstraints.flatMap { $1 } + offConstraints)
492492

493-
initialConst = edgePosition(surfaceView.frame) + offset.y
493+
initialConst = edgePosition(surfaceView.frame) + offset
494494

495495
let constraint: NSLayoutConstraint
496496
switch position {

0 commit comments

Comments
 (0)