akshathjain / sliding_up_panel

A draggable Flutter widget that makes implementing a SlidingUpPanel much easier!
https://pub.dartlang.org/packages/sliding_up_panel
Other
1.38k stars 381 forks source link

Change backdrop closing to use onTapDown rather than onTap #121

Closed frmatthew closed 4 years ago

frmatthew commented 4 years ago

Right now, the GestureDetector for the backdrop uses onTap for detecting when the panel should be closed. Unfortunately this means that downward swipes in the backdrop--a natural user gesture--don't behave as expected, leaving the panel open still.

By using onTapDown, any gesture, including a swipe and a tap, will effectively close the panel.

Thanks!

akshathjain commented 4 years ago

Related to #24 and #70.

frmatthew commented 4 years ago

Thanks, just read through the threads for #24 and #70. Any chance either this PR or some other mechanism for capturing onTapDown will be implemented?

akshathjain commented 4 years ago

I put those two refs just to link everything together, I’m actually going to merge this later today because it’s the 3rd request I’ve gotten for it :)

frmatthew commented 4 years ago

Fantastic. Thanks for the helpful widget!

akshathjain commented 4 years ago

@frmatthew I found that using onTapDown was a little too sensitive — the panel would automatically close when the finger first touches the screen. onTap only causes a close when the user's finger leaves the screen. Maintaining similarity to the Drawer behavior, I've modified the code a little to look like this:

onVerticalDragEnd: widget.backdropTapClosesPanel ? (DragEndDetails dets){
  // only trigger a close if the drag is towards panel close position
  if((widget.slideDirection == SlideDirection.UP ? 1 : -1) * dets.velocity.pixelsPerSecond.dy > 0)
    _close();
} : null,
onTap: widget.backdropTapClosesPanel ? () => _close() : null,

This allows the user dragging down towards the closed position of the panel to close the panel, as well as taps on the backdrop. This also more closely imitates the Drawer, which only closes itself once the user's finger leaves the screen.

frmatthew commented 4 years ago

Nice, thanks.