Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refactor: Replace showModalBottomSheet with showShareCollectionSheet for consistency

AmanRajSinghMouryabcc3d0bf7f89
diff --git a/mobile/apps/locker/lib/ui/pages/collection_page.dart b/mobile/apps/locker/lib/ui/pages/collection_page.dart
index ab124c1561..664ab0b345 100644
--- a/mobile/apps/locker/lib/ui/pages/collection_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/collection_page.dart
@@ -210,14 +210,7 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
);
}
- await showModalBottomSheet(
- context: context,
- backgroundColor: getEnteColorScheme(context).backgroundBase,
- isScrollControlled: true,
- builder: (context) => ShareCollectionBottomSheet(
- collection: _collection,
- ),
- );
+ await showShareCollectionSheet(context, collection: _collection);
// Refresh state after share sheet closes
if (mounted) {
setState(() {});
diff --git a/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart b/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
index 0def5ed879..91f4728937 100644
--- a/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
+++ b/mobile/apps/locker/lib/ui/sharing/share_collection_bottom_sheet.dart
@@ -1,8 +1,8 @@
import "package:ente_sharing/models/user.dart";
import "package:ente_sharing/user_avator_widget.dart";
import "package:ente_ui/components/alert_bottom_sheet.dart";
+import "package:ente_ui/components/base_bottom_sheet.dart";
import "package:ente_ui/components/captioned_text_widget_v2.dart";
-import "package:ente_ui/components/close_icon_button.dart";
import "package:ente_ui/components/divider_widget.dart";
import "package:ente_ui/components/menu_item_widget_v2.dart";
import "package:ente_ui/theme/ente_theme.dart";
@@ -17,6 +17,18 @@ import "package:locker/ui/components/popup_menu_item_widget.dart";
import "package:locker/ui/sharing/add_email_bottom_sheet.dart";
import "package:locker/utils/collection_actions.dart";
+Future<void> showShareCollectionSheet(
+ BuildContext context, {
+ required Collection collection,
+}) {
+ return showBaseBottomSheet<void>(
+ context,
+ title: context.l10n.sharedWith,
+ headerSpacing: 20,
+ child: ShareCollectionBottomSheet(collection: collection),
+ );
+}
+
class ShareCollectionBottomSheet extends StatefulWidget {
final Collection collection;
@@ -59,65 +71,35 @@ class _ShareCollectionBottomSheetState
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
- return Container(
- decoration: BoxDecoration(
- color: colorScheme.backgroundElevated2,
- borderRadius: const BorderRadius.only(
- topLeft: Radius.circular(24),
- topRight: Radius.circular(24),
- ),
- ),
- child: SafeArea(
- top: false,
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildHeader(colorScheme, textTheme),
- const SizedBox(height: 20),
- _buildShareesList(colorScheme, textTheme),
- if (_isOwner) ...[
- const SizedBox(height: 20),
- SizedBox(
- width: double.infinity,
- child: GradientButton(
- text: context.l10n.addEmail,
- onTap: () async {
- await showModalBottomSheet(
- context: context,
- backgroundColor: Colors.transparent,
- isScrollControlled: true,
- builder: (context) => AddEmailBottomSheet(
- collection: widget.collection,
- onShareAdded: () {
- if (mounted) {
- setState(() {});
- }
- },
- ),
- );
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _buildShareesList(colorScheme, textTheme),
+ if (_isOwner) ...[
+ const SizedBox(height: 20),
+ SizedBox(
+ width: double.infinity,
+ child: GradientButton(
+ text: context.l10n.addEmail,
+ onTap: () async {
+ await showModalBottomSheet(
+ context: context,
+ backgroundColor: Colors.transparent,
+ isScrollControlled: true,
+ builder: (context) => AddEmailBottomSheet(
+ collection: widget.collection,
+ onShareAdded: () {
+ if (mounted) {
+ setState(() {});
+ }
},
),
- ),
- ],
- ],
+ );
+ },
+ ),
),
- ),
- ),
- );
- }
-
- Widget _buildHeader(colorScheme, textTheme) {
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- context.l10n.sharedWith,
- style: textTheme.largeBold,
- ),
- const CloseIconButton(),
+ ],
],
);
}
diff --git a/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart
index f948c87aaf..83d44881eb 100644
--- a/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart
+++ b/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart
@@ -385,14 +385,7 @@ class _CollectionSelectionOverlayBarState
);
}
- await showModalBottomSheet(
- context: context,
- backgroundColor: getEnteColorScheme(context).backgroundBase,
- isScrollControlled: true,
- builder: (context) => ShareCollectionBottomSheet(
- collection: collection,
- ),
- );
+ await showShareCollectionSheet(context, collection: collection);
} catch (e, s) {
_logger.severe(e, s);
await showGenericErrorDialog(context: context, error: e);
diff --git a/mobile/packages/ui/lib/components/base_bottom_sheet.dart b/mobile/packages/ui/lib/components/base_bottom_sheet.dart
new file mode 100644
index 0000000000..4170eb50cc
--- /dev/null
+++ b/mobile/packages/ui/lib/components/base_bottom_sheet.dart
@@ -0,0 +1,98 @@
+import "package:ente_ui/components/close_icon_button.dart";
+import "package:ente_ui/theme/ente_theme.dart";
+import "package:flutter/material.dart";
+
+Future<T?> showBaseBottomSheet<T>(
+ BuildContext context, {
+ required String title,
+ required Widget child,
+ bool showCloseButton = true,
+ VoidCallback? onClose,
+ double headerSpacing = 0,
+ Color? backgroundColor,
+ CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.start,
+ EdgeInsets padding = const EdgeInsets.all(16),
+ bool isDismissible = true,
+ bool enableDrag = true,
+}) {
+ return showModalBottomSheet<T>(
+ context: context,
+ isScrollControlled: true,
+ backgroundColor: Colors.transparent,
+ isDismissible: isDismissible,
+ enableDrag: enableDrag,
+ builder: (context) => BaseBottomSheet(
+ title: title,
+ showCloseButton: showCloseButton,
+ onClose: onClose,
+ headerSpacing: headerSpacing,
+ backgroundColor: backgroundColor,
+ crossAxisAlignment: crossAxisAlignment,
+ padding: padding,
+ child: child,
+ ),
+ );
+}
+
+class BaseBottomSheet extends StatelessWidget {
+ final Widget child;
+ final String title;
+ final bool showCloseButton;
+ final VoidCallback? onClose;
+ final CrossAxisAlignment crossAxisAlignment;
+ final EdgeInsets padding;
+ final Color? backgroundColor;
+ final double headerSpacing;
+
+ const BaseBottomSheet({
+ required this.child,
+ required this.title,
+ this.showCloseButton = true,
+ this.onClose,
+ this.crossAxisAlignment = CrossAxisAlignment.start,
+ this.padding = const EdgeInsets.all(16),
+ this.backgroundColor,
+ this.headerSpacing = 0,
+ super.key,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return Container(
+ decoration: BoxDecoration(
+ color: backgroundColor ?? colorScheme.backgroundElevated2,
+ borderRadius: const BorderRadius.only(
+ topLeft: Radius.circular(24),
+ topRight: Radius.circular(24),
+ ),
+ ),
+ child: SafeArea(
+ top: false,
+ child: Padding(
+ padding: padding,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: crossAxisAlignment,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(title, style: textTheme.largeBold),
+ if (showCloseButton)
+ CloseIconButton(onTap: onClose)
+ else
+ const SizedBox.shrink(),
+ ],
+ ),
+ if (headerSpacing > 0) SizedBox(height: headerSpacing),
+ child,
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}