Skip to content

Commit

Permalink
Extend the solution of #587 issue for another positions.
Browse files Browse the repository at this point in the history
  • Loading branch information
scenee committed Apr 22, 2023
1 parent 74ce9ed commit ed1e6e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
35 changes: 22 additions & 13 deletions Sources/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class Core: NSObject, UIGestureRecognizerDelegate {
location = \(value(of: location)), velocity = \(velocity)
""")

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

if insideMostExpandedAnchor {
// Scroll offset pinning
Expand Down Expand Up @@ -596,7 +596,7 @@ class Core: NSObject, UIGestureRecognizerDelegate {
return false
}

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

var offset: CGPoint = .zero
var offset = 0.0

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

// Fit the surface bounds to a scroll offset content by startInteraction(at:offset:)
let offsetDiff = scrollView.contentOffset - pinningOffset
let offsetDiff = offsetFromPinning(scrollView: scrollView)
switch layoutAdapter.position {
case .top, .left:
if value(of: offsetDiff) > 0 {
if offsetDiff > 0 {
offset = -offsetDiff
}
case .bottom, .right:
if value(of: offsetDiff) < 0 {
if offsetDiff < 0 {
offset = -offsetDiff
}
}
Expand Down Expand Up @@ -1075,16 +1075,25 @@ class Core: NSObject, UIGestureRecognizerDelegate {
}
}

private func allowScrollPanGesture(for scrollView: UIScrollView) -> Bool {
guard state == layoutAdapter.mostExpandedState else { return false }
var offsetY: CGFloat = 0
private func offsetFromPinning(scrollView: UIScrollView) -> CGFloat {
return value(of: scrollView.contentOffset - contentOffsetForPinning(of: scrollView))
}

private func distanceFromPinning(scrollView: UIScrollView) -> CGFloat {
var offset = offsetFromPinning(scrollView: scrollView)
switch layoutAdapter.position {
case .top, .left:
offsetY = value(of: scrollView.fp_contentOffsetMax - scrollView.contentOffset)
offset = -offset
case .bottom, .right:
offsetY = value(of: scrollView.contentOffset - contentOffsetForPinning(of: scrollView))
break;
}
return offsetY <= -30.0 || offsetY > 0
return offset
}

private func allowScrollPanGesture(for scrollView: UIScrollView) -> Bool {
guard state == layoutAdapter.mostExpandedState else { return false }
var offset = distanceFromPinning(scrollView: scrollView)
return offset <= -30.0 || offset > 0
}

// MARK: - UIPanGestureRecognizer Intermediation
Expand Down
4 changes: 2 additions & 2 deletions Sources/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class LayoutAdapter {
}
}

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

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

initialConst = edgePosition(surfaceView.frame) + offset.y
initialConst = edgePosition(surfaceView.frame) + offset

let constraint: NSLayoutConstraint
switch position {
Expand Down

0 comments on commit ed1e6e5

Please sign in to comment.