diff --git a/lib/src/wolt_modal_sheet.dart b/lib/src/wolt_modal_sheet.dart index 1087b6cb..c26eb1ac 100644 --- a/lib/src/wolt_modal_sheet.dart +++ b/lib/src/wolt_modal_sheet.dart @@ -23,6 +23,7 @@ class WoltModalSheet extends StatefulWidget { required this.pageListBuilderNotifier, required this.pageIndexNotifier, required this.onModalDismissedWithBarrierTap, + required this.onModalDismissedWithDrag, required this.decorator, required this.modalTypeBuilder, required this.animationController, @@ -39,6 +40,7 @@ class WoltModalSheet extends StatefulWidget { final ValueNotifier pageListBuilderNotifier; final ValueNotifier pageIndexNotifier; final VoidCallback? onModalDismissedWithBarrierTap; + final VoidCallback? onModalDismissedWithDrag; final Widget Function(Widget)? decorator; final WoltModalType Function(BuildContext context) modalTypeBuilder; final AnimationController? animationController; @@ -68,6 +70,7 @@ class WoltModalSheet extends StatefulWidget { RouteSettings? routeSettings, Duration? transitionDuration, VoidCallback? onModalDismissedWithBarrierTap, + VoidCallback? onModalDismissedWithDrag, AnimationController? transitionAnimationController, AnimatedWidget? bottomSheetTransitionAnimation, AnimatedWidget? dialogTransitionAnimation, @@ -112,6 +115,7 @@ class WoltModalSheet extends StatefulWidget { RouteSettings? routeSettings, Duration? transitionDuration, VoidCallback? onModalDismissedWithBarrierTap, + VoidCallback? onModalDismissedWithDrag, AnimationController? transitionAnimationController, AnimatedWidget? bottomSheetTransitionAnimation, AnimatedWidget? dialogTransitionAnimation, @@ -133,6 +137,7 @@ class WoltModalSheet extends StatefulWidget { barrierDismissible: barrierDismissible, enableDragForBottomSheet: enableDragForBottomSheet, onModalDismissedWithBarrierTap: onModalDismissedWithBarrierTap, + onModalDismissedWithDrag: onModalDismissedWithDrag, transitionAnimationController: transitionAnimationController, useSafeArea: useSafeArea, bottomSheetTransitionAnimation: bottomSheetTransitionAnimation, @@ -220,10 +225,7 @@ class _WoltModalSheetState extends State { id: barrierLayoutId, child: GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - widget.onModalDismissedWithBarrierTap?.call(); - Navigator.of(context).pop(); - }, + onTap: widget.onModalDismissedWithBarrierTap ?? Navigator.of(context).pop, child: const SizedBox.expand(), ), ), @@ -331,7 +333,12 @@ class _WoltModalSheetState extends State { ); if (isClosing && widget.route.isCurrent) { - Navigator.pop(context); + final onModalDismissedWithDrag = widget.onModalDismissedWithDrag; + if (onModalDismissedWithDrag != null) { + onModalDismissedWithDrag(); + } else { + Navigator.pop(context); + } } } } diff --git a/lib/src/wolt_modal_sheet_route.dart b/lib/src/wolt_modal_sheet_route.dart index 9ee4cade..bdcd157c 100644 --- a/lib/src/wolt_modal_sheet_route.dart +++ b/lib/src/wolt_modal_sheet_route.dart @@ -8,6 +8,7 @@ class WoltModalSheetRoute extends PageRoute { this.pageIndexNotifier, this.decorator, this.onModalDismissedWithBarrierTap, + this.onModalDismissedWithDrag, bool? enableDragForBottomSheet, bool? useSafeArea, bool? barrierDismissible, @@ -47,6 +48,8 @@ class WoltModalSheetRoute extends PageRoute { final VoidCallback? onModalDismissedWithBarrierTap; + final VoidCallback? onModalDismissedWithDrag; + final bool _enableDragForBottomSheet; final bool _useSafeArea; @@ -100,6 +103,7 @@ class WoltModalSheetRoute extends PageRoute { pageListBuilderNotifier: pageListBuilderNotifier, modalTypeBuilder: modalTypeBuilder, onModalDismissedWithBarrierTap: onModalDismissedWithBarrierTap, + onModalDismissedWithDrag: onModalDismissedWithDrag, animationController: animationController, enableDragForBottomSheet: _enableDragForBottomSheet, useSafeArea: _useSafeArea, diff --git a/playground/lib/home/home_screen.dart b/playground/lib/home/home_screen.dart index b60b0f44..89cbee16 100644 --- a/playground/lib/home/home_screen.dart +++ b/playground/lib/home/home_screen.dart @@ -82,7 +82,16 @@ class _HomeScreenState extends State { context: context, pageListBuilderNotifier: pageListBuilderNotifier, modalTypeBuilder: _modalTypeBuilder, - onModalDismissedWithBarrierTap: () => pageIndexNotifier.value = 0, + onModalDismissedWithDrag: () { + debugPrint('Bottom sheet is dismissed with drag.'); + Navigator.of(context).pop(); + pageIndexNotifier.value = 0; + }, + onModalDismissedWithBarrierTap: () { + debugPrint('Modal is dismissed with barrier tap.'); + Navigator.of(context).pop(); + pageIndexNotifier.value = 0; + }, maxDialogWidth: 560, minDialogWidth: 400, minPageHeight: 0.4, diff --git a/playground_navigator2/lib/router/playground_router_delegate.dart b/playground_navigator2/lib/router/playground_router_delegate.dart index 09ddbe5c..21ff5b5c 100644 --- a/playground_navigator2/lib/router/playground_router_delegate.dart +++ b/playground_navigator2/lib/router/playground_router_delegate.dart @@ -66,9 +66,6 @@ class PlaygroundRouterDelegate extends RouterDelegate { @@ -21,6 +23,12 @@ class SheetPage extends Page { pageIndexNotifier: pageIndexNotifier, modalTypeBuilder: modalTypeBuilder, pageListBuilderNotifier: pageListBuilderNotifier, + onModalDismissedWithDrag: () { + context.read().closeSheet(); + }, + onModalDismissedWithBarrierTap: () { + context.read().closeSheet(); + }, routeSettings: this, ); }