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

Add option to dynamically enable bottom sheet drag for a single page #45

Merged
merged 3 commits into from
Sep 2, 2023
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
8 changes: 4 additions & 4 deletions lib/src/content/wolt_modal_sheet_animated_switcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class WoltModalSheetAnimatedSwitcher extends StatefulWidget {
final int pageIndex;
final WoltModalType woltModalType;
final double sheetWidth;
final bool showDragHandleForBottomSheet;
final bool showDragHandle;

const WoltModalSheetAnimatedSwitcher({
required this.pages,
required this.pageIndex,
required this.woltModalType,
required this.sheetWidth,
required this.showDragHandleForBottomSheet,
required this.showDragHandle,
Key? key,
}) : assert(pageIndex >= 0 && pageIndex < pages.length),
super(key: key);
Expand Down Expand Up @@ -127,15 +127,15 @@ class _WoltModalSheetAnimatedSwitcherState extends State<WoltModalSheetAnimatedS
page: _page,
woltModalType: widget.woltModalType,
topBarTranslationY: _topBarTranslationY,
showDragHandleForBottomSheet: widget.showDragHandleForBottomSheet,
showDragHandle: widget.showDragHandle,
),
if (currentWidgets != null)
WoltModalSheetLayout(
paginatingWidgetsGroup: currentWidgets,
page: _page,
woltModalType: widget.woltModalType,
topBarTranslationY: _topBarTranslationY,
showDragHandleForBottomSheet: widget.showDragHandleForBottomSheet,
showDragHandle: widget.showDragHandle,
),
if (currentWidgets != null &&
animationController != null &&
Expand Down
6 changes: 3 additions & 3 deletions lib/src/content/wolt_modal_sheet_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class WoltModalSheetLayout extends StatelessWidget {
required this.paginatingWidgetsGroup,
required this.woltModalType,
required this.topBarTranslationY,
required this.showDragHandleForBottomSheet,
required this.showDragHandle,
Key? key,
}) : super(key: key);

final WoltModalSheetPage page;
final PaginatingWidgetsGroup paginatingWidgetsGroup;
final WoltModalType woltModalType;
final double topBarTranslationY;
final bool showDragHandleForBottomSheet;
final bool showDragHandle;

@override
Widget build(BuildContext context) {
Expand All @@ -44,7 +44,7 @@ class WoltModalSheetLayout extends StatelessWidget {
height: topBarHeight,
child: paginatingWidgetsGroup.topBarAnimatedBuilder,
),
if (showDragHandleForBottomSheet)
if (showDragHandle)
const Positioned(
left: 0,
right: 0,
Expand Down
51 changes: 51 additions & 0 deletions lib/src/modal_page/wolt_modal_sheet_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class WoltModalSheetPage {
/// `true`.
final bool? hasSabGradient;

/// Controls the draggability of the bottom sheet. This setting overrides the value provided
/// via [WoltModalSheet.show] specifically for this page when the modal is displayed as a bottom sheet.
final bool? enableDrag;

/// The color of the gentle gradient overlay that is rendered above the [stickyActionBar]. The
/// purpose of this gradient is to visually suggest to the user that additional content might
/// be present below the action bar.
Expand Down Expand Up @@ -146,6 +150,7 @@ class WoltModalSheetPage {
this.heroImageHeight,
this.backgroundColor,
this.hasSabGradient,
this.enableDrag,
this.sabGradientColor,
this.forceMaxHeight = false,
this.scrollController,
Expand All @@ -167,6 +172,7 @@ class WoltModalSheetPage {
Color? backgroundColor,
bool? hasSabGradient,
Color? sabGradientColor,
bool? enableDrag,
bool forceMaxHeight = false,
bool? isTopBarLayerAlwaysVisible,
bool? hasTopBarLayer,
Expand All @@ -184,6 +190,7 @@ class WoltModalSheetPage {
heroImageHeight: heroImageHeight,
backgroundColor: backgroundColor,
hasSabGradient: hasSabGradient,
enableDrag: enableDrag,
sabGradientColor: sabGradientColor,
forceMaxHeight: forceMaxHeight,
isTopBarLayerAlwaysVisible: isTopBarLayerAlwaysVisible,
Expand All @@ -206,6 +213,7 @@ class WoltModalSheetPage {
Color? backgroundColor,
bool? hasSabGradient,
Color? sabGradientColor,
bool? enableDrag,
bool forceMaxHeight = false,
bool? isTopBarLayerAlwaysVisible,
bool? hasTopBarLayer,
Expand All @@ -224,6 +232,7 @@ class WoltModalSheetPage {
backgroundColor: backgroundColor,
hasSabGradient: hasSabGradient,
sabGradientColor: sabGradientColor,
enableDrag: enableDrag,
forceMaxHeight: forceMaxHeight,
isTopBarLayerAlwaysVisible: isTopBarLayerAlwaysVisible,
hasTopBarLayer: hasTopBarLayer,
Expand All @@ -233,4 +242,46 @@ class WoltModalSheetPage {
trailingNavBarWidget: trailingNavBarWidget,
);
}

WoltModalSheetPage copyWith({
Widget? pageTitle,
double? navBarHeight,
Widget? sliverList,
Widget? singleChildContent,
Widget? topBarTitle,
Widget? heroImage,
double? heroImageHeight,
Color? backgroundColor,
bool? hasSabGradient,
Color? sabGradientColor,
bool? enableDrag,
bool? forceMaxHeight,
bool? isTopBarLayerAlwaysVisible,
bool? hasTopBarLayer,
ScrollController? scrollController,
Widget? stickyActionBar,
Widget? leadingNavBarWidget,
Widget? trailingNavBarWidget,
}) {
return WoltModalSheetPage(
pageTitle: pageTitle ?? this.pageTitle,
navBarHeight: navBarHeight ?? this.navBarHeight,
sliverList: sliverList ?? this.sliverList,
singleChildContent: singleChildContent ?? this.singleChildContent,
topBarTitle: topBarTitle ?? this.topBarTitle,
heroImage: heroImage ?? this.heroImage,
heroImageHeight: heroImageHeight ?? this.heroImageHeight,
backgroundColor: backgroundColor ?? this.backgroundColor,
hasSabGradient: hasSabGradient ?? this.hasSabGradient,
sabGradientColor: sabGradientColor ?? this.sabGradientColor,
enableDrag: enableDrag ?? this.enableDrag,
forceMaxHeight: forceMaxHeight ?? this.forceMaxHeight,
isTopBarLayerAlwaysVisible: isTopBarLayerAlwaysVisible ?? this.isTopBarLayerAlwaysVisible,
hasTopBarLayer: hasTopBarLayer ?? this.hasTopBarLayer,
scrollController: scrollController ?? this.scrollController,
stickyActionBar: stickyActionBar ?? this.stickyActionBar,
leadingNavBarWidget: leadingNavBarWidget ?? this.leadingNavBarWidget,
trailingNavBarWidget: trailingNavBarWidget ?? this.trailingNavBarWidget,
);
}
}
4 changes: 2 additions & 2 deletions lib/src/theme/wolt_modal_sheet_default_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class WoltModalSheetDefaultThemeData extends WoltModalSheetThemeData {

/// Whether to show the drag handle.
@override
bool get showDragHandleForBottomSheet => enableDragForBottomSheet;
bool get showDragHandle => enableDrag;

/// Whether to enable the drag for bottom sheet.
@override
bool get enableDragForBottomSheet => true;
bool get enableDrag => true;

@override
Color get dragHandleColor => _colors.onSurfaceVariant.withOpacity(0.4);
Expand Down
14 changes: 7 additions & 7 deletions lib/src/theme/wolt_modal_sheet_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
this.modalBarrierColor,
this.bottomSheetShape,
this.dialogShape,
this.showDragHandleForBottomSheet,
this.showDragHandle,
this.dragHandleColor,
this.dragHandleSize,
this.enableDragForBottomSheet,
this.enableDrag,
this.topBarShadowColor,
this.topBarElevation,
this.heroImageHeight,
Expand Down Expand Up @@ -56,7 +56,7 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
final ShapeBorder? dialogShape;

/// Whether to show the drag handle.
final bool? showDragHandleForBottomSheet;
final bool? showDragHandle;

/// The color of the drag handle.
final Color? dragHandleColor;
Expand All @@ -65,7 +65,7 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
final Size? dragHandleSize;

/// Whether the bottom sheet can be dragged.
final bool? enableDragForBottomSheet;
final bool? enableDrag;

/// The elevation color of the top bar.
final Color? topBarShadowColor;
Expand Down Expand Up @@ -135,7 +135,7 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
Color? modalBarrierColor,
ShapeBorder? bottomSheetShape,
ShapeBorder? dialogShape,
bool? showDragHandleForBottomSheet,
bool? showDragHandle,
Color? dragHandleColor,
Size? dragHandleSize,
Color? topBarShadowColor,
Expand All @@ -160,7 +160,7 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
modalBarrierColor: modalBarrierColor ?? this.modalBarrierColor,
bottomSheetShape: bottomSheetShape ?? this.bottomSheetShape,
dialogShape: dialogShape ?? this.dialogShape,
showDragHandleForBottomSheet: showDragHandleForBottomSheet ?? this.showDragHandleForBottomSheet,
showDragHandle: showDragHandle ?? this.showDragHandle,
dragHandleColor: dragHandleColor ?? this.dragHandleColor,
dragHandleSize: dragHandleSize ?? this.dragHandleSize,
topBarShadowColor: topBarShadowColor ?? this.topBarShadowColor,
Expand Down Expand Up @@ -188,7 +188,7 @@ class WoltModalSheetThemeData extends ThemeExtension<WoltModalSheetThemeData> {
return WoltModalSheetThemeData(
backgroundColor: Color.lerp(backgroundColor, other.backgroundColor, t),
modalElevation: lerpDouble(modalElevation, other.modalElevation, t),
showDragHandleForBottomSheet: t < 0.5 ? showDragHandleForBottomSheet : other.showDragHandleForBottomSheet,
showDragHandle: t < 0.5 ? showDragHandle : other.showDragHandle,
modalBarrierColor: Color.lerp(modalBarrierColor, other.modalBarrierColor, t),
bottomSheetShape: ShapeBorder.lerp(bottomSheetShape, other.bottomSheetShape, t),
dialogShape: ShapeBorder.lerp(dialogShape, other.dialogShape, t),
Expand Down
39 changes: 20 additions & 19 deletions lib/src/wolt_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class WoltModalSheet<T> extends StatefulWidget {
required this.modalTypeBuilder,
required this.animationController,
required this.route,
required this.enableDragForBottomSheet,
required this.showDragHandleForBottomSheet,
required this.enableDrag,
required this.showDragHandle,
required this.useSafeArea,
this.minDialogWidth,
this.maxDialogWidth,
Expand All @@ -47,8 +47,8 @@ class WoltModalSheet<T> extends StatefulWidget {
final WoltModalTypeBuilder modalTypeBuilder;
final AnimationController? animationController;
final WoltModalSheetRoute<T> route;
final bool? enableDragForBottomSheet;
final bool? showDragHandleForBottomSheet;
final bool? enableDrag;
final bool? showDragHandle;
final bool useSafeArea;
final double? minDialogWidth;
final double? maxDialogWidth;
Expand All @@ -69,8 +69,8 @@ class WoltModalSheet<T> extends StatefulWidget {
bool useRootNavigator = false,
bool? useSafeArea,
bool? barrierDismissible,
bool? enableDragForBottomSheet,
bool? showDragHandleForBottomSheet,
bool? enableDrag,
bool? showDragHandle,
RouteSettings? routeSettings,
Duration? transitionDuration,
VoidCallback? onModalDismissedWithBarrierTap,
Expand All @@ -93,8 +93,8 @@ class WoltModalSheet<T> extends StatefulWidget {
useRootNavigator: useRootNavigator,
useSafeArea: useSafeArea,
barrierDismissible: barrierDismissible,
enableDragForBottomSheet: enableDragForBottomSheet,
showDragHandleForBottomSheet: showDragHandleForBottomSheet,
enableDrag: enableDrag,
showDragHandle: showDragHandle,
routeSettings: routeSettings,
transitionDuration: transitionDuration,
onModalDismissedWithBarrierTap: onModalDismissedWithBarrierTap,
Expand All @@ -119,8 +119,8 @@ class WoltModalSheet<T> extends StatefulWidget {
bool useRootNavigator = false,
bool? useSafeArea,
bool? barrierDismissible,
bool? enableDragForBottomSheet,
bool? showDragHandleForBottomSheet,
bool? enableDrag,
bool? showDragHandle,
RouteSettings? routeSettings,
Duration? transitionDuration,
VoidCallback? onModalDismissedWithBarrierTap,
Expand All @@ -145,8 +145,8 @@ class WoltModalSheet<T> extends StatefulWidget {
routeSettings: routeSettings,
transitionDuration: transitionDuration,
barrierDismissible: barrierDismissible,
enableDragForBottomSheet: enableDragForBottomSheet,
showDragHandleForBottomSheet: showDragHandleForBottomSheet,
enableDrag: enableDrag,
showDragHandle: showDragHandle,
onModalDismissedWithBarrierTap: onModalDismissedWithBarrierTap,
onModalDismissedWithDrag: onModalDismissedWithDrag,
transitionAnimationController: transitionAnimationController,
Expand Down Expand Up @@ -229,13 +229,14 @@ class _WoltModalSheetState extends State<WoltModalSheet> {
break;
}
final enableDrag = _modalType == WoltModalType.bottomSheet &&
(widget.enableDragForBottomSheet ??
themeData?.enableDragForBottomSheet ??
defaultThemeData.enableDragForBottomSheet);
final showDragHandle = widget.showDragHandleForBottomSheet ??
(page.enableDrag ??
widget.enableDrag ??
themeData?.enableDrag ??
defaultThemeData.enableDrag);
final showDragHandle = widget.showDragHandle ??
(enableDrag &&
(themeData?.showDragHandleForBottomSheet ??
defaultThemeData.showDragHandleForBottomSheet));
(themeData?.showDragHandle ??
defaultThemeData.showDragHandle));
final pageBackgroundColor = page.backgroundColor ??
themeData?.backgroundColor ??
defaultThemeData.backgroundColor;
Expand Down Expand Up @@ -298,7 +299,7 @@ class _WoltModalSheetState extends State<WoltModalSheet> {
pageIndex: pageIndex,
pages: pages,
sheetWidth: constraints.maxWidth,
showDragHandleForBottomSheet: showDragHandle,
showDragHandle: showDragHandle,
);
},
),
Expand Down
16 changes: 8 additions & 8 deletions lib/src/wolt_modal_sheet_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class WoltModalSheetRoute<T> extends PageRoute<T> {
this.onModalDismissedWithDrag,
this.modalBarrierColor,
WoltModalTypeBuilder? modalTypeBuilder,
bool? enableDragForBottomSheet,
bool? showDragHandleForBottomSheet,
bool? enableDrag,
bool? showDragHandle,
bool? useSafeArea,
bool? barrierDismissible,
AnimationController? transitionAnimationController,
Expand All @@ -31,8 +31,8 @@ class WoltModalSheetRoute<T> extends PageRoute<T> {
double? maxDialogWidth,
double? minPageHeight,
double? maxPageHeight,
}) : _enableDragForBottomSheet = enableDragForBottomSheet,
_showDragHandleForBottomSheet = showDragHandleForBottomSheet,
}) : _enableDrag = enableDrag,
_showDragHandle = showDragHandle,
_useSafeArea = useSafeArea ?? true,
_transitionAnimationController = transitionAnimationController,
_transitionDuration = transitionDuration ?? const Duration(milliseconds: 300),
Expand Down Expand Up @@ -62,9 +62,9 @@ class WoltModalSheetRoute<T> extends PageRoute<T> {

final VoidCallback? onModalDismissedWithDrag;

final bool? _enableDragForBottomSheet;
final bool? _enableDrag;

final bool? _showDragHandleForBottomSheet;
final bool? _showDragHandle;

final bool _useSafeArea;

Expand Down Expand Up @@ -125,8 +125,8 @@ class WoltModalSheetRoute<T> extends PageRoute<T> {
onModalDismissedWithBarrierTap: onModalDismissedWithBarrierTap,
onModalDismissedWithDrag: onModalDismissedWithDrag,
animationController: animationController,
enableDragForBottomSheet: _enableDragForBottomSheet,
showDragHandleForBottomSheet: _showDragHandleForBottomSheet,
enableDrag: _enableDrag,
showDragHandle: _showDragHandle,
useSafeArea: _useSafeArea,
minDialogWidth: _minDialogWidth,
maxDialogWidth: _maxDialogWidth,
Expand Down
Loading