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

Added optional removalInteractionVelocityThreshold value to Behavior #425

Merged
merged 2 commits into from
Jan 4, 2021

Conversation

Argent
Copy link
Contributor

@Argent Argent commented Jan 2, 2021

Currently, in order to change the velocity threshold for the interactive removal gesture, we need to duplicate the default code of floatingPanel:shouldRemoveAt:with like this:

func defaultFloatingPanel(_ fpc: FloatingPanelController, shouldRemoveAt location: CGPoint, with velocity: CGVector) -> Bool {
        let threshold = CGFloat(1.5) // Changed from 5.5 -> 1.5

        switch fpc.layout.position {
        case .top:
            return (velocity.dy <= -threshold)
        case .left:
            return (velocity.dx <= -threshold)
        case .bottom:
            return (velocity.dy >= threshold)
        case .right:
            return (velocity.dx >= threshold)
        }
 }

I added an optional variable removalInteractionVelocityThreshold to Behavior, which let’s the user configure the velocity threshold for the default floatingPanel:shouldRemoveAt:with implementation.

Now the only thing needed to change the threshold is this:

let behavior = FloatingPanelDefaultBehavior()
behavior.removalInteractionVelocityThreshold = 1.5
fpc.behavior = behavior

Added an optional variable `removalInteractionVelocityThreshold` to `Behavior`, which let’s the user configure the velocity threshold for the default `floatingPanel:shouldRemoveAt:with` implementation
@scenee
Copy link
Owner

scenee commented Jan 4, 2021

Thank you for your proposal 👍 I agree with the new optional variable of Behavior.

I have one request. This implementation is ok, but it's better to use Core.behaviorAdapter to proxy the default value(5.5) of FloatingPanelDefaultBehavior because it's able to remove a duplicate of the default value.

https://github.com/SCENEE/FloatingPanel/blob/fb373cc60f717f8772e2fc63644eb5b3a086772c/Sources/Core.swift#L716

@Argent
Copy link
Contributor Author

Argent commented Jan 4, 2021

@scenee good point, thanks for bringing it to my attention.
I adjusted the PR and added removalInteractionVelocityThreshold to BehaviorAdapter

@scenee scenee merged commit a6538b7 into scenee:master Jan 4, 2021
@scenee
Copy link
Owner

scenee commented Jan 4, 2021

Thank you for your quick response! I've merged your PR to master 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants