Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor: Introduce showAddEmailSheet for consistent bottom sheet usage

AmanRajSinghMourya2d1e3e758c97
diff --git a/mobile/apps/locker/lib/ui/sharing/add_email_bottom_sheet.dart b/mobile/apps/locker/lib/ui/sharing/add_email_bottom_sheet.dart
index 63a8fc3bb7..68291f4755 100644
--- a/mobile/apps/locker/lib/ui/sharing/add_email_bottom_sheet.dart
+++ b/mobile/apps/locker/lib/ui/sharing/add_email_bottom_sheet.dart
@@ -3,8 +3,8 @@ import "package:ente_accounts/services/user_service.dart";
import "package:ente_sharing/models/user.dart";
import "package:ente_sharing/user_avator_widget.dart";
import "package:ente_sharing/verify_identity_dialog.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";
@@ -20,6 +20,23 @@ import "package:locker/ui/components/popup_menu_item_widget.dart";
import "package:locker/ui/viewer/date/date_time_picker.dart";
import "package:locker/utils/collection_actions.dart";
+Future<void> showAddEmailSheet(
+ BuildContext context, {
+ required Collection collection,
+ required VoidCallback onShareAdded,
+}) {
+ return showBaseBottomSheet<void>(
+ context,
+ title: context.l10n.addNewEmail,
+ headerSpacing: 20,
+ isKeyboardAware: true,
+ child: AddEmailBottomSheet(
+ collection: collection,
+ onShareAdded: onShareAdded,
+ ),
+ );
+}
+
class AddEmailBottomSheet extends StatefulWidget {
final Collection collection;
final VoidCallback onShareAdded;
@@ -68,63 +85,29 @@ class _AddEmailBottomSheetState extends State<AddEmailBottomSheet> {
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
- final bottomInset = MediaQuery.of(context).viewInsets.bottom;
- return Container(
- decoration: BoxDecoration(
- color: colorScheme.backgroundElevated2,
- borderRadius: const BorderRadius.only(
- topLeft: Radius.circular(24),
- topRight: Radius.circular(24),
- ),
- ),
- child: Padding(
- padding: EdgeInsets.only(bottom: bottomInset),
- child: SafeArea(
- top: false,
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildHeader(colorScheme, textTheme),
- const SizedBox(height: 20),
- _buildEmailInputField(colorScheme, textTheme),
- if (_suggestedUsers.isNotEmpty) ...[
- const SizedBox(height: 20),
- _buildExistingContactsSection(colorScheme, textTheme),
- ],
- // _buildShareLaterCheckbox(colorScheme, textTheme),
- if (_shareLater) ...[
- const SizedBox(height: 12),
- _buildScheduleDateTimeRow(colorScheme, textTheme),
- ],
- const SizedBox(height: 20),
- _buildShareButton(),
- ],
- ),
- ),
- ),
- ),
+ return SingleChildScrollView(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _buildEmailInputField(colorScheme, textTheme),
+ if (_suggestedUsers.isNotEmpty) ...[
+ const SizedBox(height: 20),
+ _buildExistingContactsSection(colorScheme, textTheme),
+ ],
+ // _buildShareLaterCheckbox(colorScheme, textTheme),
+ if (_shareLater) ...[
+ const SizedBox(height: 12),
+ _buildScheduleDateTimeRow(colorScheme, textTheme),
+ ],
+ const SizedBox(height: 20),
+ _buildShareButton(),
+ ],
),
);
}
- Widget _buildHeader(colorScheme, textTheme) {
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- context.l10n.addNewEmail,
- style: textTheme.largeBold,
- ),
- const CloseIconButton(),
- ],
- );
- }
-
Widget _buildEmailInputField(colorScheme, textTheme) {
return Container(
decoration: BoxDecoration(
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 91f4728937..81887f360c 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
@@ -83,18 +83,14 @@ class _ShareCollectionBottomSheetState
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(() {});
- }
- },
- ),
+ await showAddEmailSheet(
+ context,
+ collection: widget.collection,
+ onShareAdded: () {
+ if (mounted) {
+ setState(() {});
+ }
+ },
);
},
),
diff --git a/mobile/packages/ui/lib/components/base_bottom_sheet.dart b/mobile/packages/ui/lib/components/base_bottom_sheet.dart
index 4170eb50cc..92f810870a 100644
--- a/mobile/packages/ui/lib/components/base_bottom_sheet.dart
+++ b/mobile/packages/ui/lib/components/base_bottom_sheet.dart
@@ -14,6 +14,7 @@ Future<T?> showBaseBottomSheet<T>(
EdgeInsets padding = const EdgeInsets.all(16),
bool isDismissible = true,
bool enableDrag = true,
+ bool isKeyboardAware = false,
}) {
return showModalBottomSheet<T>(
context: context,
@@ -29,6 +30,7 @@ Future<T?> showBaseBottomSheet<T>(
backgroundColor: backgroundColor,
crossAxisAlignment: crossAxisAlignment,
padding: padding,
+ isKeyboardAware: isKeyboardAware,
child: child,
),
);
@@ -43,6 +45,7 @@ class BaseBottomSheet extends StatelessWidget {
final EdgeInsets padding;
final Color? backgroundColor;
final double headerSpacing;
+ final bool isKeyboardAware;
const BaseBottomSheet({
required this.child,
@@ -53,6 +56,7 @@ class BaseBottomSheet extends StatelessWidget {
this.padding = const EdgeInsets.all(16),
this.backgroundColor,
this.headerSpacing = 0,
+ this.isKeyboardAware = false,
super.key,
});
@@ -60,6 +64,8 @@ class BaseBottomSheet extends StatelessWidget {
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
+ final bottomInset =
+ isKeyboardAware ? MediaQuery.of(context).viewInsets.bottom : 0.0;
return Container(
decoration: BoxDecoration(
@@ -69,27 +75,30 @@ class BaseBottomSheet extends StatelessWidget {
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,
- ],
+ child: Padding(
+ padding: EdgeInsets.only(bottom: bottomInset),
+ 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,
+ ],
+ ),
),
),
),