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

Fix: Prevent dismiss on barrier tap for alert dialog #245

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/modal_type/wolt_alert_dialog_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:wolt_modal_sheet/src/utils/wolt_breakpoints.dart';
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';

class WoltAlertDialogType extends WoltDialogType {
const WoltAlertDialogType();
const WoltAlertDialogType() : super(barrierDismissible: false);

@override
BoxConstraints layoutModal(Size availableSize) {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/modal_type/wolt_bottom_sheet_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class WoltBottomSheetType extends WoltModalType {
Duration transitionDuration = _defaultEnterDuration,
Duration reverseTransitionDuration = _defaultExitDuration,
minFlingVelocity = 700.0,
bool? barrierDismissible,
}) : super(
shapeBorder: shapeBorder,
forceMaxHeight: forceMaxHeight,
Expand All @@ -27,6 +28,7 @@ class WoltBottomSheetType extends WoltModalType {
dismissDirection: dismissDirection,
minFlingVelocity: minFlingVelocity,
showDragHandle: showDragHandle,
barrierDismissible: barrierDismissible,
);

static const Duration _defaultEnterDuration = Duration(milliseconds: 350);
Expand Down Expand Up @@ -176,6 +178,7 @@ class WoltBottomSheetType extends WoltModalType {
Duration? reverseTransitionDuration,
WoltModalDismissDirection? dismissDirection,
double? minFlingVelocity,
bool? barrierDismissible,
}) {
return WoltBottomSheetType(
shapeBorder: shapeBorder ?? this.shapeBorder,
Expand All @@ -186,6 +189,7 @@ class WoltBottomSheetType extends WoltModalType {
reverseTransitionDuration ?? this.reverseTransitionDuration,
dismissDirection: dismissDirection ?? this.dismissDirection,
minFlingVelocity: minFlingVelocity ?? this.minFlingVelocity,
barrierDismissible: barrierDismissible ?? this.barrierDismissible,
);
}
}
4 changes: 4 additions & 0 deletions lib/src/modal_type/wolt_dialog_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class WoltDialogType extends WoltModalType {
bool forceMaxHeight = false,
Duration transitionDuration = _defaultEnterDuration,
Duration reverseTransitionDuration = _defaultExitDuration,
bool? barrierDismissible,
}) : super(
shapeBorder: shapeBorder,
forceMaxHeight: forceMaxHeight,
transitionDuration: transitionDuration,
reverseTransitionDuration: reverseTransitionDuration,
showDragHandle: false,
barrierDismissible: barrierDismissible,
);

static const Duration _defaultEnterDuration = Duration(milliseconds: 300);
Expand Down Expand Up @@ -145,13 +147,15 @@ class WoltDialogType extends WoltModalType {
bool? forceMaxHeight,
Duration? transitionDuration,
Duration? reverseTransitionDuration,
bool? barrierDismissible,
}) {
return WoltDialogType(
shapeBorder: shapeBorder ?? this.shapeBorder,
forceMaxHeight: forceMaxHeight ?? this.forceMaxHeight,
transitionDuration: transitionDuration ?? this.transitionDuration,
reverseTransitionDuration:
reverseTransitionDuration ?? this.reverseTransitionDuration,
barrierDismissible: barrierDismissible ?? this.barrierDismissible,
);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/src/modal_type/wolt_modal_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ abstract class WoltModalType {
this.reverseTransitionDuration = const Duration(milliseconds: 300),
this.minFlingVelocity = 700.0,
this.closeProgressThreshold = 0.5,
this.barrierDismissible,
});

/// Creates the default bottom sheet modal.
Expand Down Expand Up @@ -83,6 +84,9 @@ abstract class WoltModalType {
/// - A lower value (closer to 0.0) means the modal will be harder to dismiss
final double closeProgressThreshold;

// Whether the modal can be dismissed by tapping the barrier.
final bool? barrierDismissible;

/// Defines the constraints for the modal based on the available screen size.
///
/// Implement this method to specify the modal's sizing within the route screen.
Expand Down
4 changes: 4 additions & 0 deletions lib/src/modal_type/wolt_side_sheet_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class WoltSideSheetType extends WoltModalType {
WoltModalDismissDirection? dismissDirection =
WoltModalDismissDirection.endToStart,
double minFlingVelocity = 365.0,
bool? barrierDismissible,
}) : super(
shapeBorder: shapeBorder,
showDragHandle: false,
Expand All @@ -23,6 +24,7 @@ class WoltSideSheetType extends WoltModalType {
reverseTransitionDuration: reverseTransitionDuration,
dismissDirection: dismissDirection,
minFlingVelocity: minFlingVelocity,
barrierDismissible: barrierDismissible,
);

static const Duration _defaultEnterDuration = Duration(milliseconds: 300);
Expand Down Expand Up @@ -187,6 +189,7 @@ class WoltSideSheetType extends WoltModalType {
Duration? reverseTransitionDuration,
WoltModalDismissDirection? dismissDirection,
double? minFlingVelocity,
bool? barrierDismissible,
}) {
return WoltSideSheetType(
shapeBorder: shapeBorder ?? this.shapeBorder,
Expand All @@ -196,6 +199,7 @@ class WoltSideSheetType extends WoltModalType {
reverseTransitionDuration ?? this.reverseTransitionDuration,
dismissDirection: dismissDirection ?? this.dismissDirection,
minFlingVelocity: minFlingVelocity ?? this.minFlingVelocity,
barrierDismissible: barrierDismissible ?? this.barrierDismissible,
);
}
}
9 changes: 6 additions & 3 deletions lib/src/wolt_modal_sheet_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class WoltModalSheetRoute<T> extends PageRoute<T> {
_showDragHandle = showDragHandle,
_useSafeArea = useSafeArea ?? true,
_transitionAnimationController = transitionAnimationController,
_barrierDismissible = barrierDismissible ?? true,
_barrierDismissible = barrierDismissible,
_modalTypeBuilder = modalTypeBuilder,
super(settings: routeSettings);

Expand All @@ -34,7 +34,7 @@ class WoltModalSheetRoute<T> extends PageRoute<T> {

final WoltModalTypeBuilder? _modalTypeBuilder;

late final bool _barrierDismissible;
final bool? _barrierDismissible;

final VoidCallback? onModalDismissedWithBarrierTap;

Expand All @@ -58,7 +58,10 @@ class WoltModalSheetRoute<T> extends PageRoute<T> {
final AnimationController? _transitionAnimationController;

@override
bool get barrierDismissible => _barrierDismissible;
bool get barrierDismissible =>
_barrierDismissible ??
_determineCurrentModalType(navigator!.context).barrierDismissible ??
true;

/// The value of false was chosen to indicate that the modal route does not fully obscure the
/// underlying content. This allows for a translucent effect, where the content beneath the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TopNotificationSheetType extends WoltModalType {
dismissDirection: WoltModalDismissDirection.up,
showDragHandle: false,
closeProgressThreshold: 0.8,
barrierDismissible: false,
);

@override
Expand Down
2 changes: 0 additions & 2 deletions playground/lib/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ class _HomeScreenState extends State<HomeScreen> {
child: WoltElevatedButton(
onPressed: () {
WoltModalSheet.show(
barrierDismissible: false,
context: context,
modalTypeBuilder: (_) =>
const TopNotificationSheetType(),
Expand All @@ -220,7 +219,6 @@ class _HomeScreenState extends State<HomeScreen> {
floatingActionButton: FloatingActionButton(
onPressed: () {
WoltModalSheet.show(
barrierDismissible: false,
context: context,
modalTypeBuilder: (_) => const FloatingBottomSheetType(),
pageListBuilder: (_) => [NewOrderNotificationPage()],
Expand Down
Loading