Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the removal interaction at any positions upon the conditions #335

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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