Skip to content

Commit a6538b7

Browse files
authored
Add optional removalInteractionVelocityThreshold value to Behavior (#425)
Added an optional variable `removalInteractionVelocityThreshold` to `Behavior`, which let’s the user configure the velocity threshold for the default `floatingPanel:shouldRemoveAt:with` implementation.
1 parent 40194d9 commit a6538b7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Sources/Behavior.swift

+12
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public protocol FloatingPanelBehavior {
4343
/// This method allows a panel to activate the rubber band effect to a given edge of the surface view. By default, the effect is disabled.
4444
@objc optional
4545
func allowsRubberBanding(for edge: UIRectEdge) -> Bool
46+
47+
/// Returns the velocity threshold for the default interactive removal gesture.
48+
///
49+
/// In case `floatingPanel:shouldRemoveAt:with` is implemented, this value will not be used. The default value of `FloatingPanelDefaultBehavior` is 5.5
50+
@objc optional
51+
var removalInteractionVelocityThreshold: CGFloat { get }
4652
}
4753

4854
/// The default behavior object for a panel
@@ -70,6 +76,8 @@ open class FloatingPanelDefaultBehavior: FloatingPanelBehavior {
7076
open func allowsRubberBanding(for edge: UIRectEdge) -> Bool {
7177
return false
7278
}
79+
80+
open var removalInteractionVelocityThreshold: CGFloat = 5.5
7381
}
7482

7583
class BehaviorAdapter {
@@ -92,6 +100,10 @@ class BehaviorAdapter {
92100
var momentumProjectionRate: CGFloat {
93101
behavior.momentumProjectionRate ?? FloatingPanelDefaultBehavior().momentumProjectionRate
94102
}
103+
104+
var removalInteractionVelocityThreshold: CGFloat {
105+
behavior.removalInteractionVelocityThreshold ?? FloatingPanelDefaultBehavior().removalInteractionVelocityThreshold
106+
}
95107

96108
func redirectionalProgress(from: FloatingPanelState, to: FloatingPanelState) -> CGFloat {
97109
behavior.redirectionalProgress?(vc, from: from, to: to) ?? FloatingPanelDefaultBehavior().redirectionalProgress(vc,from: from, to: to)

Sources/Core.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ class Core: NSObject, UIGestureRecognizerDelegate {
713713
if let result = vc.delegate?.floatingPanel?(vc, shouldRemoveAt: vc.surfaceLocation, with: velocityVector) {
714714
return result
715715
}
716-
let threshold = CGFloat(5.5)
716+
let threshold = behaviorAdapter.removalInteractionVelocityThreshold
717717
switch layoutAdapter.position {
718718
case .top:
719719
return (velocityVector.dy <= -threshold)

0 commit comments

Comments
 (0)