Skip to content

Commit

Permalink
Fix stopping a panel b/w anchors after an interruption
Browse files Browse the repository at this point in the history
The panel(surface view) could stop b/w anchors if the pan gesture doesn't
pass through `.changed` state after an interruptible animator is interrupted.

The possible reason is the constraints have never changed since the last animation
is committed so that `surfaceView.superview!.layoutIfNeeded()` doesn't trigger
a layout update by the constraint-based layout system in
`FloatingPanelLayoutAdapter.activateLayout(of:)`.

Thus the inserted code changes a panel interactive constraint by the least
positive number. It allows the constraint-based layout system to update the
surface layout expectedly.
  • Loading branch information
scenee committed Aug 8, 2019
1 parent 1671a3d commit 3b6271c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Framework/Sources/FloatingPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate {

if let animator = self.animator {
guard surfaceView.presentationFrame.minY >= layoutAdapter.topMaxY else { return }
log.debug("panel animation interrupted!!!")
log.debug("panel animation(interruptible: \(animator.isInterruptible)) interrupted!!!")
if animator.isInterruptible {
animator.stopAnimation(false)
// A user can stop a panel at the nearest Y of a target position so this fine-tunes
Expand Down Expand Up @@ -377,6 +377,12 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate {
case .ended, .cancelled, .failed:
if interactionInProgress == false {
startInteraction(with: translation, at: location)
// Workaround: Prevent stopping the surface view b/w anchors if the pan gesture
// doesn't pass through .changed state after an interruptible animator is interrupted.
let dy = translation.y - .leastNonzeroMagnitude
layoutAdapter.updateInteractiveTopConstraint(diff: dy,
allowsTopBuffer: true,
with: behavior)
}
panningEnd(with: translation, velocity: velocity)
default:
Expand Down
1 change: 1 addition & 0 deletions Framework/Sources/FloatingPanelLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ class FloatingPanelLayoutAdapter {
func activateLayout(of state: FloatingPanelPosition) {
defer {
surfaceView.superview!.layoutIfNeeded()
log.debug("activateLayout -- surface.presentation = \(self.surfaceView.presentationFrame) surface.frame = \(self.surfaceView.frame)")
}

var state = state
Expand Down

0 comments on commit 3b6271c

Please sign in to comment.