Fix the wrong layout update on iOS10
On iOS 10, there is a case when a floating panel is updated by a different position(the previous position) from the target position in animating. This is because `FloatingPanelController` calls `update(safeAreaInsets:)` in `viewDidLayoutSubviews()` unexpectedly.
This commit is contained in:
@@ -45,6 +45,7 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate, UIScrollViewDelegate
|
||||
private var transOffsetY: CGFloat = 0
|
||||
|
||||
var interactionInProgress: Bool = false
|
||||
var isDecelerating: Bool = false
|
||||
|
||||
// Scroll handling
|
||||
private var stopScrollDeceleration: Bool = false
|
||||
@@ -520,6 +521,9 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate, UIScrollViewDelegate
|
||||
private func startAnimation(to targetPosition: FloatingPanelPosition, at distance: CGFloat, with velocity: CGPoint) {
|
||||
log.debug("startAnimation", targetPosition, distance, velocity)
|
||||
let targetY = layoutAdapter.positionY(for: targetPosition)
|
||||
|
||||
isDecelerating = true
|
||||
|
||||
let velocityVector = (distance != 0) ? CGVector(dx: 0, dy: max(min(velocity.y/distance, 30.0), -30.0)) : .zero
|
||||
let animator = behavior.interactionAnimator(self.viewcontroller, to: targetPosition, with: velocityVector)
|
||||
animator.addAnimations { [weak self] in
|
||||
@@ -534,6 +538,7 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate, UIScrollViewDelegate
|
||||
}
|
||||
animator.addCompletion { [weak self] pos in
|
||||
guard let `self` = self else { return }
|
||||
self.isDecelerating = false
|
||||
guard
|
||||
self.interactionInProgress == false,
|
||||
animator == self.animator,
|
||||
|
||||
@@ -236,8 +236,9 @@ public class FloatingPanelController: UIViewController, UIScrollViewDelegate, UI
|
||||
// Don't re-layout the surface on SafeArea.Bottom enabled/disabled in interaction progress
|
||||
guard
|
||||
floatingPanel.layoutAdapter.safeAreaInsets != safeAreaInsets,
|
||||
self.floatingPanel.interactionInProgress == false
|
||||
else { return }
|
||||
self.floatingPanel.interactionInProgress == false,
|
||||
self.floatingPanel.isDecelerating == false
|
||||
else { return }
|
||||
|
||||
log.debug("Update safeAreaInsets", safeAreaInsets)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user