fujidaiti / smooth_sheets

Sheet widgets with smooth motion and great flexibility.
https://pub.dev/packages/smooth_sheets
MIT License
195 stars 19 forks source link

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

Closed fujidaiti closed 1 week ago

fujidaiti commented 3 months ago

Discussed in https://github.com/fujidaiti/smooth_sheets/discussions/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
ulusoyca commented 2 months ago

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 commented 1 month ago

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.

https://github.com/fujidaiti/smooth_sheets/blob/a5d9be1afeb15d01e8257a6cac76bd28a2d1826b/package/lib/src/modal/modal_sheet.dart#L10-L11

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

https://github.com/fujidaiti/smooth_sheets/blob/a5d9be1afeb15d01e8257a6cac76bd28a2d1826b/package/lib/src/modal/modal_sheet.dart#L319-L333

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