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

Add a way to customize sensitivity of swipe-to-dismiss action on modal sheet #162

Closed
fujidaiti opened this issue Jun 5, 2024 Discussed in #158 · 2 comments · Fixed by #222
Closed

Add a way to customize sensitivity of swipe-to-dismiss action on modal sheet #162

fujidaiti opened this issue Jun 5, 2024 Discussed in #158 · 2 comments · Fixed by #222
Assignees
Labels
feature request New feature or request P2
Milestone

Comments

@fujidaiti
Copy link
Owner

Discussed in #158

Originally posted by mark8044 June 5, 2024
Right now, compared to most other Sheet packages (including Wolt) this packages pull down sensitivity seems too sensitive for my taste. Meaning its too easy to pull it down to dismiss. It becomes a problem when using a scrollableSheet. Is there an easy way to modify this sensitivity?

Thank you much

@fujidaiti fujidaiti self-assigned this Jun 5, 2024
@fujidaiti fujidaiti added feature request New feature or request P2 labels Jun 5, 2024
@fujidaiti fujidaiti added this to the v1 milestone Jun 5, 2024
@fujidaiti fujidaiti changed the title Add a way to customize sensitivity of swipe-to-dismiss action on the modal sheet Add a way to customize sensitivity of swipe-to-dismiss action on modal sheet Jun 5, 2024
@ulusoyca
Copy link

Hi @fujidaiti This is added to the latest version of WoltModalSheet. You can check the implementation and maybe create a PR to smooth sheet package for the same functionality?

@fujidaiti
Copy link
Owner Author

fujidaiti commented Jul 11, 2024

Reading the code you mentioned, I can say that we could implement the same feature as wolt_modal_sheet. But I'm currently thinking of a different API, which could look like the following:

  ModalSheetRoute(
    // New API (optional). Specifying null is equivalent to `swipeDismissible: false`.
    swipeDismissibility: SwipeDismissibility(
        // The minimum required velocity of a fling gesture to dismiss the modal.
        flingVelocityThreshold: 500, // pixels/sec
        // If the extent (the visible height of the sheet) is smaller than this threshold
        // when a drag ends without flinging, the modal will be dismissed.
        extentThreshold: const Extent.pixels(100),
    ),
    // swipeDismissible: true,  <- Remove the current API to avoid confusion in usage.
    builder: (context) => ...,
 );

This enables precise control over the dismissing behavior of the modal. The current implementation already has similar thresholds, so I think implementing the above API wouldn't be difficult.

const _minFlingVelocityToDismiss = 1.0;
const _minDragDistanceToDismiss = 100.0; // Logical pixels.

For reference, here's the current logic that determines if the modal should be dismissed or not.

final bool invokePop;
if (MediaQuery.viewInsetsOf(_context).bottom > 0) {
// The on-screen keyboard is open.
invokePop = false;
} else if (velocity < 0) {
// Flings down.
invokePop = velocity.abs() > _minFlingVelocityToDismiss;
} else if (velocity.isApprox(0)) {
assert(draggedDistance >= 0);
// Dragged down enough to dismiss.
invokePop = draggedDistance > _minDragDistanceToDismiss;
} else {
// Flings up.
invokePop = false;
}

This is just an idea, so suggestions for the proposed API are of course welcome :)

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

Successfully merging a pull request may close this issue.

2 participants