Fix removal interaction

This commit is contained in:
Shin Yamamoto
2018-11-07 13:11:38 +09:00
parent 16e8808ce5
commit bd128bf8b0
2 changed files with 17 additions and 7 deletions
+4 -3
View File
@@ -338,11 +338,12 @@ class FloatingPanel: NSObject, UIGestureRecognizerDelegate, UIScrollViewDelegate
let posY = layoutAdapter.positionY(for: state)
let currentY = getCurrentY(from: initialFrame, with: translation)
let safeAreaBottomY = layoutAdapter.safeAreaBottomY
let vth = behavior.removalVelocityThreshold
let vth = behavior.removalVelocity
let pth = max(min(behavior.removalProgress, 1.0), 0.0)
let velocityVector = (distance != 0) ? CGVector(dx: 0, dy: max(min(velocity.y/distance, vth), 0.0)) : .zero
guard (currentY - posY) != 0 else { return false }
guard (safeAreaBottomY - posY) / (currentY - posY) >= 0.5 || velocityVector.dy == vth else { return false }
guard (safeAreaBottomY - posY) != 0 else { return false }
guard (currentY - posY) / (safeAreaBottomY - posY) >= pth || velocityVector.dy == vth else { return false }
viewcontroller.delegate?.floatingPanelDidEndDraggingToRemove(viewcontroller, withVelocity: velocity)
let animator = self.behavior.removalInteractionAnimator(self.viewcontroller, with: velocityVector)
+13 -4
View File
@@ -29,12 +29,17 @@ public protocol FloatingPanelBehavior {
/// Returns a y-axis velocity to invoke a removal interaction at the bottom position.
///
/// This method is called when FloatingPanelController.isRemovalInteractionEnabled is true.
var removalVelocityThreshold: CGFloat { get }
/// Default is 10.0. This method is called when FloatingPanelController.isRemovalInteractionEnabled is true.
var removalVelocity: CGFloat { get }
/// Returns the threshold of the transition to invoke a removal interaction at the bottom position.
///
/// The progress is represented by a floating-point value between 0.0 and 1.0, inclusive, where 1.0 indicates the floating panel is impossible to invoke the removal interaction. The default value is 0.5. Values less than 0.0 and greater than 1.0 are pinned to those limits. This method is called when FloatingPanelController.isRemovalInteractionEnabled is true.
var removalProgress: CGFloat { get }
/// Returns a UIViewPropertyAnimator object to remove a floating panel with a velocity interactively at the bottom position.
///
/// This method is called when FloatingPanelController.isRemovalInteractionEnabled is true.
/// Default is a spring animator with 1.0 damping ratio. This method is called when FloatingPanelController.isRemovalInteractionEnabled is true.
func removalInteractionAnimator(_ fpc: FloatingPanelController, with velocity: CGVector) -> UIViewPropertyAnimator
}
@@ -51,10 +56,14 @@ public extension FloatingPanelBehavior {
return UIViewPropertyAnimator(duration: 0.25, curve: .easeInOut)
}
var removalVelocityThreshold: CGFloat {
var removalVelocity: CGFloat {
return 10.0
}
var removalProgress: CGFloat {
return 0.5
}
func removalInteractionAnimator(_ fpc: FloatingPanelController, with velocity: CGVector) -> UIViewPropertyAnimator {
log.debug("velocity", velocity)
let timing = UISpringTimingParameters(dampingRatio: 1.0,