Skip to content

Commit

Permalink
Enable the removal interaction at any positions upon the conditions (#…
Browse files Browse the repository at this point in the history
…335)

If a library consumer allows a panel projectable movement with the
FloatingPanelBehavior object, the panel is able to invoke the removal
interaction when the next moving position projected the momentum is
hidden.
  • Loading branch information
scenee authored Sep 3, 2020
1 parent da4e1d2 commit 007f9af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 12 additions & 1 deletion Examples/Samples/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1355,15 +1355,26 @@ final class MultiPanelController: FloatingPanelController, FloatingPanelControll

private final class FirstViewLayout: FloatingPanelLayout {
let initialPosition: FloatingPanelPosition = .full
let supportedPositions: Set<FloatingPanelPosition> = [.full]
let supportedPositions: Set<FloatingPanelPosition> = [.full, .half]
func insetFor(position: FloatingPanelPosition) -> CGFloat? {
switch position {
case .full: return 40.0
case .half: return 200.0
default: return nil
}
}
}

private final class FirstViewBehavior: FloatingPanelBehavior {
func shouldProjectMomentum(_ fpc: FloatingPanelController, for proposedTargetPosition: FloatingPanelPosition) -> Bool {
return true
}
}

func floatingPanel(_ vc: FloatingPanelController, behaviorFor newCollection: UITraitCollection) -> FloatingPanelBehavior? {
return FirstViewBehavior()
}

func floatingPanel(_ vc: FloatingPanelController, layoutFor newCollection: UITraitCollection) -> FloatingPanelLayout? {
return FirstViewLayout()
}
Expand Down
14 changes: 8 additions & 6 deletions Framework/Sources/FloatingPanelCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ class FloatingPanelCore: NSObject, UIGestureRecognizerDelegate {

endInteraction(for: targetPosition)

if isRemovalInteractionEnabled, isBottomState {
if isRemovalInteractionEnabled {
let velocityVector: CGVector
if distance == 0 {
velocityVector = .zero
Expand All @@ -627,12 +627,14 @@ class FloatingPanelCore: NSObject, UIGestureRecognizerDelegate {
}
// `velocityVector` will be replaced by just a velocity(not vector) when FloatingPanelRemovalInteraction will be added.
if shouldStartRemovalAnimation(with: velocityVector), let vc = viewcontroller {
vc.delegate?.floatingPanelDidEndDraggingToRemove(vc, withVelocity: velocity)
let animationVector = CGVector(dx: abs(velocityVector.dx), dy: abs(velocityVector.dy))
startRemovalAnimation(vc, with: animationVector) { [weak self] in
self?.finishRemovalAnimation()
if behavior.shouldProjectMomentum(vc, for: targetPosition) || isBottomState {
vc.delegate?.floatingPanelDidEndDraggingToRemove(vc, withVelocity: velocity)
let animationVector = CGVector(dx: abs(velocityVector.dx), dy: abs(velocityVector.dy))
startRemovalAnimation(vc, with: animationVector) { [weak self] in
self?.finishRemovalAnimation()
}
return
}
return
}
}

Expand Down

0 comments on commit 007f9af

Please sign in to comment.