Skip to content

Commit

Permalink
Use raw velocity rather than ratio for threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
fujidaiti committed Aug 23, 2024
1 parent 896d56a commit a9a1c80
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
7 changes: 5 additions & 2 deletions cookbook/lib/tutorial/cupertino_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ void _showModalSheet(BuildContext context, {required bool isFullScreen}) {
// For declarative navigation (Navigator 2.0), use `CupertinoModalSheetPage` instead.
final modalRoute = CupertinoModalSheetRoute(
swipeDismissible: true, // Enable the swipe-to-dismiss behavior.
swipeDismissSensitivity:
SwipeDismissSensitivity(minFlingVelocity: 3.0, minDragDistance: 400.0),
// Use `SwipeDismissSensitivity` to tweak the sensitivity of the swipe-to-dismiss gesture.
swipeDismissSensitivity: const SwipeDismissSensitivity(
minFlingVelocity: 1500,
minDragDistance: 300,
),
builder: (context) => switch (isFullScreen) {
true => const _FullScreenSheet(),
false => const _HalfScreenSheet(),
Expand Down
8 changes: 7 additions & 1 deletion cookbook/lib/tutorial/declarative_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ final _router = GoRouter(
key: state.pageKey,
// Enable the swipe-to-dismiss behavior.
swipeDismissible: true,
// Use `SwipeDismissSensitivity` to tweak the sensitivity of
// the swipe-to-dismiss gesture.
swipeDismissSensitivity: const SwipeDismissSensitivity(
minFlingVelocity: 1500,
minDragDistance: 300,
),
child: const _ExampleSheet(),
);
},
Expand Down Expand Up @@ -85,7 +91,7 @@ class _ExampleSheet extends StatelessWidget {
borderRadius: BorderRadius.circular(20),
),
child: const SizedBox(
height: 500,
height: double.infinity,
width: double.infinity,
),
),
Expand Down
6 changes: 2 additions & 4 deletions package/lib/src/modal/modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,9 @@ class _SwipeDismissibleController with SheetGestureTamperer {

final viewportHeight = _context.size!.height;
final draggedDistance = viewportHeight * (1 - transitionController.value);

final effectiveVelocity = switch (axisDirection) {
VerticalDirection.up => velocity.pixelsPerSecond.dy / viewportHeight,
VerticalDirection.down =>
-1 * velocity.pixelsPerSecond.dy / viewportHeight,
VerticalDirection.up => velocity.pixelsPerSecond.dy,
VerticalDirection.down => -1 * velocity.pixelsPerSecond.dy,
};

final bool invokePop;
Expand Down
4 changes: 2 additions & 2 deletions package/lib/src/modal/swipe_dismiss_sensitivity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/// a swipe to result in a dismissal.
class SwipeDismissSensitivity {
const SwipeDismissSensitivity({
this.minFlingVelocity = 1.0,
this.minDragDistance = 300.0,
this.minFlingVelocity = 1500,
this.minDragDistance = 300,
});

/// The minimum velocity that a fling gesture must reach to trigger
Expand Down

0 comments on commit a9a1c80

Please sign in to comment.