π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][package] Add bottom sheet components (#10464)
aman-pilot8bf10bc95d8a
diff --git a/mobile/packages/ente_components/example/assets/2.0x/warning-grey.png b/mobile/packages/ente_components/example/assets/2.0x/warning-grey.pngnew file mode 100644index 0000000000..aac9fdf2acBinary files /dev/null and b/mobile/packages/ente_components/example/assets/2.0x/warning-grey.png differdiff --git a/mobile/packages/ente_components/example/assets/3.0x/warning-grey.png b/mobile/packages/ente_components/example/assets/3.0x/warning-grey.pngnew file mode 100644index 0000000000..e8b788289cBinary files /dev/null and b/mobile/packages/ente_components/example/assets/3.0x/warning-grey.png differdiff --git a/mobile/packages/ente_components/example/assets/warning-grey.png b/mobile/packages/ente_components/example/assets/warning-grey.pngnew file mode 100644index 0000000000..bf6720c453Binary files /dev/null and b/mobile/packages/ente_components/example/assets/warning-grey.png differdiff --git a/mobile/packages/ente_components/example/lib/main.dart b/mobile/packages/ente_components/example/lib/main.dartindex ff680187a2..903d3df03d 100644--- a/mobile/packages/ente_components/example/lib/main.dart+++ b/mobile/packages/ente_components/example/lib/main.dart@@ -124,69 +124,62 @@ class _CatalogHomeState extends State<CatalogHome> {return Scaffold(drawer: const CatalogSettingsDrawer(),- body: CustomScrollView(- slivers: [- HeaderAppBarComponent(- title: 'Components',- subtitle: 'Design system catalog',- backButton: Builder(- builder: (context) {- return IconButtonComponent(- tooltip: 'Settings',- variant: IconButtonComponentVariant.unfilled,- onTap: () => Scaffold.of(context).openDrawer(),- icon: const _CatalogHugeIcon(HugeIcons.strokeRoundedMenu01),- );- },- ),- actions: [- _CatalogThemeCycleButton(- themeMode: _themeMode,- onChanged: _setThemeMode,+ appBar: AppBar(+ centerTitle: true,+ elevation: 0,+ scrolledUnderElevation: 0,+ backgroundColor: colors.backgroundBase,+ foregroundColor: colors.textBase,+ surfaceTintColor: Colors.transparent,+ title: Text(+ 'Components',+ style: TextStyles.h1Bold.copyWith(color: colors.textBase),+ ),+ leading: Builder(+ builder: (context) {+ return Center(+ child: IconButtonComponent(+ tooltip: 'Settings',+ variant: IconButtonComponentVariant.unfilled,+ onTap: () => Scaffold.of(context).openDrawer(),+ icon: const _CatalogHugeIcon(HugeIcons.strokeRoundedMenu01),),- ],- ),- SliverPadding(- padding: const EdgeInsets.fromLTRB(- Spacing.lg,- Spacing.xs,- Spacing.lg,- Spacing.lg,- ),- sliver: SliverList.builder(- itemCount: sections.length * 2 - 1,- itemBuilder: (context, index) {- if (index.isOdd) {- return const SizedBox(height: Spacing.lg);- }- return _CatalogSectionTile(- section: sections[index ~/ 2],- themeMode: _themeMode,- onThemeModeChanged: widget.onThemeModeChanged,- );- },+ );+ },+ ),+ actions: [+ Padding(+ padding: const EdgeInsets.only(right: Spacing.lg),+ child: _CatalogThemeCycleButton(+ themeMode: _themeMode,+ onChanged: _setThemeMode,),),],),+ body: ListView.separated(+ padding: const EdgeInsets.fromLTRB(+ Spacing.lg,+ Spacing.lg,+ Spacing.lg,+ Spacing.lg,+ ),+ itemCount: sections.length,+ separatorBuilder: (_, _) => const SizedBox(height: Spacing.lg),+ itemBuilder: (context, index) {+ return _CatalogSectionTile(+ section: sections[index],+ themeMode: _themeMode,+ onThemeModeChanged: widget.onThemeModeChanged,+ );+ },+ ),backgroundColor: colors.backgroundBase,);}List<CatalogSection> _sections() {return [- CatalogSection(- title: 'Colours',- icon: HugeIcons.strokeRoundedColors,- components: const ['Color tokens'],- previewBuilder: (_) => _ColorPreview(),- ),- CatalogSection(- title: 'Text styles',- icon: HugeIcons.strokeRoundedTextFont,- components: const ['H1', 'H1-Bold', 'H2', 'Large', 'Body', 'Mini'],- previewBuilder: (_) => const _TextStylesPreview(),- ),CatalogSection(title: 'Menu Item',icon: HugeIcons.strokeRoundedUser,@@ -217,17 +210,17 @@ class _CatalogHomeState extends State<CatalogHome> {previewBuilder: (_) => const _ButtonMatrix(),),CatalogSection(- title: 'Filter chips',- icon: HugeIcons.strokeRoundedFilter,+ title: 'Bottom sheets',+ icon: HugeIcons.strokeRoundedLayoutTable01,components: const [- 'Selected',- 'Unselected',- 'Disabled',- 'Leading icon',- 'Trailing icon',- 'Face',+ 'Header',+ 'Default sheet',+ 'Choice sheet',+ 'Warning sheet',+ 'Error sheet',+ 'Custom content',],- previewBuilder: (_) => const _FilterChipPreview(),+ previewBuilder: (_) => const _BottomSheetPreview(),),CatalogSection(title: 'Text input',@@ -246,6 +239,25 @@ class _CatalogHomeState extends State<CatalogHome> {],previewBuilder: (_) => const _TextInputPreview(),),+ CatalogSection(+ title: 'Selection controls',+ icon: HugeIcons.strokeRoundedSlidersHorizontal,+ components: const ['Checkbox', 'Radio', 'Switch', 'Slider', 'Stepper'],+ previewBuilder: (_) => const _SelectionPreview(),+ ),+ CatalogSection(+ title: 'Filter chips',+ icon: HugeIcons.strokeRoundedFilter,+ components: const [+ 'Selected',+ 'Unselected',+ 'Disabled',+ 'Leading icon',+ 'Trailing icon',+ 'Face',+ ],+ previewBuilder: (_) => const _FilterChipPreview(),+ ),CatalogSection(title: 'Header app bar',icon: HugeIcons.strokeRoundedHeading,@@ -265,10 +277,10 @@ class _CatalogHomeState extends State<CatalogHome> {previewBuilder: (_) => const _AvatarPreview(),),CatalogSection(- title: 'Selection controls',- icon: HugeIcons.strokeRoundedSlidersHorizontal,- components: const ['Checkbox', 'Radio', 'Switch', 'Slider', 'Stepper'],- previewBuilder: (_) => const _SelectionPreview(),+ title: 'Text styles',+ icon: HugeIcons.strokeRoundedTextFont,+ components: const ['H1', 'H1-Bold', 'H2', 'Large', 'Body', 'Mini'],+ previewBuilder: (_) => const _TextStylesPreview(),),];}@@ -318,34 +330,23 @@ class CatalogSettingsDrawer extends StatelessWidget {width: _drawerWidth(context),shape: const RoundedRectangleBorder(),backgroundColor: colors.backgroundBase,- child: SafeArea(- bottom: false,- child: ListView(- padding: const EdgeInsets.all(Spacing.lg),- children: [- Row(- children: [- IconButtonComponent(- tooltip: 'Close settings',- variant: IconButtonComponentVariant.unfilled,- icon: const _CatalogHugeIcon(- HugeIcons.strokeRoundedArrowLeft02,- ),- onTap: () => Navigator.of(context).pop(),- ),- const SizedBox(width: Spacing.md),- Expanded(- child: Text(- 'Settings',- style: TextStyles.h1Bold.copyWith(color: colors.textBase),- ),- ),- ],+ child: CustomScrollView(+ slivers: [+ HeaderAppBarComponent(+ title: 'Settings',+ subtitle: '[email protected]',+ onBack: () => Navigator.of(context).pop(),+ ),+ const SliverPadding(+ padding: EdgeInsets.fromLTRB(+ Spacing.sm,+ Spacing.xs,+ Spacing.sm,+ Spacing.lg,),- const SizedBox(height: Spacing.xl),- const _SettingsMainContent(),- ],- ),+ sliver: SliverToBoxAdapter(child: _SettingsMainContent()),+ ),+ ],),);}@@ -589,16 +590,6 @@ class _SettingsMainContent extends StatelessWidget {return Column(crossAxisAlignment: CrossAxisAlignment.start,children: [- Padding(- padding: const EdgeInsets.symmetric(horizontal: Spacing.sm),- child: Text(- '[email protected]',- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: TextStyles.body.copyWith(color: colors.textLight),- ),- ),- const SizedBox(height: Spacing.md),const _SettingsNavigationItem(title: 'Account',icon: HugeIcons.strokeRoundedUser,@@ -1030,67 +1021,6 @@ class _SettingsAboutPage extends StatelessWidget {}}-class _ColorPreview extends StatelessWidget {- @override- Widget build(BuildContext context) {- return const _CatalogPreviewList(- children: [- _CatalogPreviewGroup(- title: 'Light palette',- child: _ColorColumn(colors: ColorTokens.light),- ),- _CatalogPreviewGroup(- title: 'Dark palette',- child: _ColorColumn(colors: ColorTokens.dark),- ),- ],- );- }-}--class _ColorColumn extends StatelessWidget {- const _ColorColumn({required this.colors});-- final ColorTokens colors;-- @override- Widget build(BuildContext context) {- return Wrap(- spacing: Spacing.sm,- runSpacing: Spacing.sm,- children: [- _Swatch(color: colors.primary),- _Swatch(color: colors.warning),- _Swatch(color: colors.caution),- _Swatch(color: colors.blue),- _Swatch(color: colors.textBase),- _Swatch(color: colors.backgroundBase),- _Swatch(color: colors.fillLight),- _Swatch(color: colors.strokeDark),- ],- );- }-}--class _Swatch extends StatelessWidget {- const _Swatch({required this.color});-- final Color color;-- @override- Widget build(BuildContext context) {- return Container(- width: 34,- height: 34,- decoration: BoxDecoration(- color: color,- border: Border.all(color: context.componentColors.strokeFaint),- borderRadius: BorderRadius.circular(Radii.xs),- ),- );- }-}-class _TextStylesPreview extends StatelessWidget {const _TextStylesPreview();@@ -2752,3 +2682,344 @@ class _MenuItemExample extends StatelessWidget {};}}++class _BottomSheetPreview extends StatelessWidget {+ const _BottomSheetPreview();++ @override+ Widget build(BuildContext context) {+ return _CatalogPreviewList(+ children: [+ _CatalogPreviewGroup(+ title: 'Launch sheets',+ child: Column(+ children: [+ ButtonComponent(+ label: 'Open default sheet',+ onTap: () => _showDefaultSheet(context),+ ),+ const SizedBox(height: Spacing.md),+ ButtonComponent(+ label: 'Open choice sheet',+ variant: ButtonComponentVariant.secondary,+ onTap: () => _showChoiceSheet(context),+ ),+ const SizedBox(height: Spacing.md),+ ButtonComponent(+ label: 'Open warning sheet',+ variant: ButtonComponentVariant.neutral,+ onTap: () => _showWarningSheet(context),+ ),+ const SizedBox(height: Spacing.md),+ ButtonComponent(+ label: 'Open custom content sheet',+ variant: ButtonComponentVariant.neutral,+ onTap: () => _showCustomSheet(context),+ ),+ const SizedBox(height: Spacing.md),+ ButtonComponent(+ label: 'Open generic error sheet',+ variant: ButtonComponentVariant.critical,+ onTap: () => _showErrorSheet(context),+ ),+ ],+ ),+ ),+ const _CatalogPreviewGroup(+ title: 'Header',+ child: _InlineSheetFrame(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ BottomSheetHeaderComponent(title: 'Title'),+ SizedBox(height: Spacing.xl),+ BottomSheetHeaderComponent(),+ SizedBox(height: Spacing.xl),+ BottomSheetHeaderComponent(+ title: 'Title',+ illustration: _WarningIllustration(),+ ),+ ],+ ),+ ),+ ),+ const _CatalogPreviewGroup(+ title: 'Default sheet',+ child: _InlineSheetFrame(child: _DefaultBottomSheetContent()),+ ),+ const _CatalogPreviewGroup(+ title: 'Choice sheet',+ child: _InlineSheetFrame(child: _ChoiceBottomSheetContent()),+ ),+ const _CatalogPreviewGroup(+ title: 'Warning sheet',+ child: _InlineSheetFrame(child: _WarningBottomSheetContent()),+ ),+ const _CatalogPreviewGroup(+ title: 'Error sheet',+ child: _InlineSheetFrame(child: _ErrorBottomSheetContent()),+ ),+ const _CatalogPreviewGroup(+ title: 'Custom content',+ child: _InlineSheetFrame(child: _CustomBottomSheetContent()),+ ),+ ],+ );+ }++ Future<void> _showDefaultSheet(BuildContext context) async {+ await showBottomSheetComponent<void>(+ context: context,+ builder: (_) => const _DefaultBottomSheetContent(),+ );+ }++ Future<void> _showChoiceSheet(BuildContext context) async {+ await showBottomSheetComponent<void>(+ context: context,+ builder: (_) => const _ChoiceBottomSheetContent(),+ );+ }++ Future<void> _showWarningSheet(BuildContext context) async {+ await showBottomSheetComponent<void>(+ context: context,+ builder: (_) => const _WarningBottomSheetContent(),+ );+ }++ Future<void> _showCustomSheet(BuildContext context) async {+ await showBottomSheetComponent<void>(+ context: context,+ builder: (_) => const _CustomBottomSheetContent(),+ );+ }++ Future<void> _showErrorSheet(BuildContext context) async {+ await showErrorBottomSheetComponent<void>(+ context: context,+ message:+ 'It looks like something went wrong. Please retry after some time.',+ illustration: const _WarningIllustration(),+ actions: [+ ButtonComponent(+ label: 'Contact support',+ variant: ButtonComponentVariant.secondary,+ onTap: () async {+ await Navigator.of(context).maybePop();+ },+ ),+ ],+ );+ }+}++class _DefaultBottomSheetContent extends StatelessWidget {+ const _DefaultBottomSheetContent();++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ return BottomSheetComponent(+ title: 'Title',+ content: Text(+ 'Imagine a scenario where a message has been sent, a bridge of trust '+ 'is being built, yet the other side remains silent.',+ style: TextStyles.body.copyWith(color: colors.textLight),+ ),+ actions: [+ ButtonComponent(+ label: 'Button',+ onTap: () async {+ await Navigator.of(context).maybePop();+ },+ ),+ ButtonComponent(+ label: 'Button',+ variant: ButtonComponentVariant.secondary,+ onTap: () async {+ await Navigator.of(context).maybePop();+ },+ ),+ ],+ );+ }+}++class _ChoiceBottomSheetContent extends StatelessWidget {+ const _ChoiceBottomSheetContent();++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ return BottomSheetComponent(+ title: 'Delete link?',+ content: Text(+ 'This action removes access for anyone who has the shared link.',+ style: TextStyles.body.copyWith(color: colors.textLight),+ ),+ actions: [+ ButtonComponent(+ label: 'Delete link',+ variant: ButtonComponentVariant.critical,+ onTap: () async {+ await Navigator.of(context).maybePop();+ },+ ),+ ButtonComponent(+ label: 'Cancel',+ variant: ButtonComponentVariant.secondary,+ onTap: () async {+ await Navigator.of(context).maybePop();+ },+ ),+ ],+ );+ }+}++class _WarningBottomSheetContent extends StatelessWidget {+ const _WarningBottomSheetContent();++ @override+ Widget build(BuildContext context) {+ return BottomSheetComponent(+ title: 'Title',+ message:+ 'Imagine a scenario where a message has been sent, a bridge of trust '+ 'is being built, yet the other side remains silent.',+ illustration: const _WarningIllustration(),+ actions: [+ ButtonComponent(+ label: 'Button',+ onTap: () async {+ await Navigator.of(context).maybePop();+ },+ ),+ ButtonComponent(+ label: 'Button',+ variant: ButtonComponentVariant.secondary,+ onTap: () async {+ await Navigator.of(context).maybePop();+ },+ ),+ ],+ );+ }+}++class _ErrorBottomSheetContent extends StatelessWidget {+ const _ErrorBottomSheetContent();++ @override+ Widget build(BuildContext context) {+ return BottomSheetComponent(+ title: 'Error',+ message:+ 'It looks like something went wrong. Please retry after some time.',+ illustration: const _WarningIllustration(),+ actions: [+ ButtonComponent(+ label: 'Contact support',+ variant: ButtonComponentVariant.secondary,+ onTap: () async {+ await Navigator.of(context).maybePop();+ },+ ),+ ],+ );+ }+}++class _CustomBottomSheetContent extends StatelessWidget {+ const _CustomBottomSheetContent();++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ return BottomSheetComponent(+ title: 'Share link',+ content: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ 'Anyone with this link can view the shared item.',+ style: TextStyles.body.copyWith(color: colors.textLight),+ ),+ const SizedBox(height: Spacing.md),+ Container(+ width: double.infinity,+ padding: const EdgeInsets.fromLTRB(+ Spacing.xl,+ Spacing.xl,+ 56,+ Spacing.xl,+ ),+ decoration: BoxDecoration(+ color: colors.fillDark,+ borderRadius: BorderRadius.circular(16),+ ),+ child: Stack(+ clipBehavior: Clip.none,+ children: [+ Text(+ 'https://ente.io/share/example-link',+ style: TextStyles.body.copyWith(color: colors.textBase),+ ),+ Positioned(+ right: -44,+ top: -8,+ child: IconButtonComponent(+ tooltip: 'Copy link',+ variant: IconButtonComponentVariant.unfilled,+ icon: const _CatalogHugeIcon(HugeIcons.strokeRoundedCopy01),+ onTap: () {},+ ),+ ),+ ],+ ),+ ),+ ],+ ),+ actions: [+ ButtonComponent(+ label: 'Share link',+ onTap: () async {+ await Navigator.of(context).maybePop();+ },+ ),+ ButtonComponent(+ label: 'Delete link',+ variant: ButtonComponentVariant.tertiaryCritical,+ onTap: () async {+ await Navigator.of(context).maybePop();+ },+ ),+ ],+ );+ }+}++class _InlineSheetFrame extends StatelessWidget {+ const _InlineSheetFrame({required this.child});++ final Widget child;++ @override+ Widget build(BuildContext context) {+ return ConstrainedBox(+ constraints: const BoxConstraints(maxWidth: 375),+ child: child,+ );+ }+}++class _WarningIllustration extends StatelessWidget {+ const _WarningIllustration();++ @override+ Widget build(BuildContext context) {+ return Image.asset('assets/warning-grey.png', width: 101, height: 89);+ }+}diff --git a/mobile/packages/ente_components/example/pubspec.yaml b/mobile/packages/ente_components/example/pubspec.yamlindex 2eff3b86e2..068affb89d 100644--- a/mobile/packages/ente_components/example/pubspec.yaml+++ b/mobile/packages/ente_components/example/pubspec.yaml@@ -20,3 +20,5 @@ dev_dependencies:flutter:uses-material-design: true+ assets:+ - assets/warning-grey.pngdiff --git a/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart b/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dartnew file mode 100644index 0000000000..046cfa479f--- /dev/null+++ b/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart@@ -0,0 +1,328 @@+import 'dart:async';++import 'package:ente_components/components/buttons/icon_button_component.dart';+import 'package:ente_components/theme/radii.dart';+import 'package:ente_components/theme/spacing.dart';+import 'package:ente_components/theme/text_styles.dart';+import 'package:ente_components/theme/theme.dart';+import 'package:flutter/material.dart';+import 'package:hugeicons/hugeicons.dart';++/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=4809-7992&m=dev+/// Section: Bottom sheet / Bottom Sheet Header+/// Specs: H2 title, optional 36px circular close action, and optional centered+/// illustration slot for warning and error sheets.+class BottomSheetHeaderComponent extends StatelessWidget {+ const BottomSheetHeaderComponent({+ super.key,+ this.title,+ this.illustration,+ this.onClose,+ this.showCloseButton = true,+ this.closeTooltip = 'Close',+ this.textAlign,+ this.isCentered = false,+ });++ final String? title;+ final Widget? illustration;++ /// Called when the close button is pressed, before the sheet is dismissed.+ ///+ /// Barrier taps, drag dismissals, and system back dismissals do not call this.+ final FutureOr<void> Function()? onClose;+ final bool showCloseButton;+ final String closeTooltip;+ final TextAlign? textAlign;+ final bool isCentered;++ @override+ Widget build(BuildContext context) {+ if (isCentered || illustration != null) {+ return _CenteredHeader(+ title: title,+ illustration: illustration,+ onClose: onClose,+ showCloseButton: showCloseButton,+ closeTooltip: closeTooltip,+ );+ }++ if (title == null) {+ return Row(+ mainAxisAlignment: MainAxisAlignment.end,+ children: [+ if (showCloseButton)+ _BottomSheetCloseButton(onClose: onClose, tooltip: closeTooltip),+ ],+ );+ }++ final colors = context.componentColors;+ return SizedBox(+ height: _headerHeight,+ child: Row(+ crossAxisAlignment: CrossAxisAlignment.center,+ children: [+ Expanded(+ child: Text(+ title!,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ textAlign: textAlign,+ style: TextStyles.h2.copyWith(color: colors.textBase),+ ),+ ),+ if (showCloseButton) const SizedBox(width: Spacing.md),+ if (showCloseButton)+ _BottomSheetCloseButton(onClose: onClose, tooltip: closeTooltip),+ ],+ ),+ );+ }+}++/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=4809-8027&m=dev+/// Section: Bottom sheet / Bottom sheet template+/// Specs: 20px top radius, 20px padding, 16px content gap, stacked 12px+/// action gap.+class BottomSheetComponent extends StatelessWidget {+ const BottomSheetComponent({+ super.key,+ this.title,+ this.header,+ this.message,+ this.illustration,+ this.content,+ this.actions = const [],+ this.onClose,+ this.showCloseButton = true,+ this.closeTooltip = 'Close',+ this.textAlign,+ this.crossAxisAlignment = CrossAxisAlignment.start,+ this.padding = const EdgeInsets.all(Spacing.xl),+ this.contentSpacing = Spacing.lg,+ this.actionsTopSpacing = Spacing.lg,+ this.backgroundColor,+ this.isKeyboardAware = false,+ });++ final String? title;+ final Widget? header;+ final String? message;+ final Widget? illustration;+ final Widget? content;+ final List<Widget> actions;++ /// Called when the close button is pressed, before the sheet is dismissed.+ ///+ /// Barrier taps, drag dismissals, and system back dismissals do not call this.+ final FutureOr<void> Function()? onClose;+ final bool showCloseButton;+ final String closeTooltip;+ final TextAlign? textAlign;+ final CrossAxisAlignment crossAxisAlignment;+ final EdgeInsets padding;+ final double contentSpacing;+ final double actionsTopSpacing;+ final Color? backgroundColor;+ final bool isKeyboardAware;++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ final bottomInset = isKeyboardAware+ ? MediaQuery.viewInsetsOf(context).bottom+ : 0.0;+ final usesCenteredLayout =+ illustration != null || (message != null && content == null);+ final effectiveHeader =+ header ??+ ((title != null || showCloseButton || usesCenteredLayout)+ ? BottomSheetHeaderComponent(+ title: title,+ illustration: illustration,+ onClose: onClose,+ showCloseButton: showCloseButton,+ closeTooltip: closeTooltip,+ textAlign: textAlign,+ isCentered: usesCenteredLayout,+ )+ : null);+ final effectiveContent =+ content ??+ (message == null+ ? null+ : Text(+ message!,+ textAlign: usesCenteredLayout ? TextAlign.center : textAlign,+ style: TextStyles.body.copyWith(color: colors.textLight),+ ));+ final effectiveCrossAxisAlignment = usesCenteredLayout+ ? CrossAxisAlignment.stretch+ : crossAxisAlignment;+ final effectiveContentSpacing = usesCenteredLayout+ ? Spacing.xs+ : contentSpacing;++ return AnimatedPadding(+ duration: const Duration(milliseconds: 200),+ curve: Curves.easeOutCubic,+ padding: EdgeInsets.only(bottom: bottomInset),+ child: Container(+ decoration: BoxDecoration(+ color: backgroundColor ?? colors.backgroundBase,+ borderRadius: const BorderRadius.only(+ topLeft: Radius.circular(Radii.bottomSheet),+ topRight: Radius.circular(Radii.bottomSheet),+ ),+ ),+ child: SafeArea(+ top: false,+ child: Padding(+ padding: padding,+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: effectiveCrossAxisAlignment,+ children: [+ if (effectiveHeader != null) effectiveHeader,+ if (effectiveContent != null) ...[+ if (effectiveHeader != null)+ SizedBox(height: effectiveContentSpacing),+ effectiveContent,+ ],+ if (actions.isNotEmpty) ...[+ SizedBox(height: actionsTopSpacing),+ _BottomSheetActions(actions: actions),+ ],+ ],+ ),+ ),+ ),+ ),+ );+ }+}++/// Shows [BottomSheetComponent] with the modal behavior used by the component+/// catalog and mobile apps.+Future<T?> showBottomSheetComponent<T>({+ required BuildContext context,+ required WidgetBuilder builder,+ bool isDismissible = true,+ bool enableDrag = true,+ bool useRootNavigator = false,+ Color? barrierColor,+}) {+ final colors = context.componentColors;+ return showModalBottomSheet<T>(+ context: context,+ useRootNavigator: useRootNavigator,+ isScrollControlled: true,+ isDismissible: isDismissible,+ enableDrag: enableDrag,+ backgroundColor: Colors.transparent,+ barrierColor: barrierColor ?? colors.specialScrim.withValues(alpha: 0.55),+ builder: builder,+ );+}++class _CenteredHeader extends StatelessWidget {+ const _CenteredHeader({+ required this.title,+ required this.illustration,+ required this.onClose,+ required this.showCloseButton,+ required this.closeTooltip,+ });++ final String? title;+ final Widget? illustration;+ final FutureOr<void> Function()? onClose;+ final bool showCloseButton;+ final String closeTooltip;++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;++ return Column(+ crossAxisAlignment: CrossAxisAlignment.center,+ children: [+ Row(+ mainAxisAlignment: MainAxisAlignment.end,+ children: [+ if (showCloseButton)+ _BottomSheetCloseButton(onClose: onClose, tooltip: closeTooltip),+ ],+ ),+ if (showCloseButton && (illustration != null || title != null))+ const SizedBox(height: Spacing.xs),+ if (illustration != null) Center(child: illustration!),+ if (title != null) ...[+ SizedBox(height: illustration == null ? 0 : Spacing.lg),+ Text(+ title!,+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ textAlign: TextAlign.center,+ style: TextStyles.h2.copyWith(color: colors.textBase),+ ),+ ],+ ],+ );+ }+}++class _BottomSheetCloseButton extends StatelessWidget {+ const _BottomSheetCloseButton({required this.onClose, required this.tooltip});++ /// Called when the close button is pressed, before the sheet is dismissed.+ final FutureOr<void> Function()? onClose;+ final String tooltip;++ @override+ Widget build(BuildContext context) {+ return IconButtonComponent(+ tooltip: tooltip,+ variant: IconButtonComponentVariant.circular,+ shouldSurfaceExecutionStates: false,+ icon: const HugeIcon(icon: HugeIcons.strokeRoundedCancel01, size: 18),+ onTap: () => _handleClose(context),+ );+ }++ Future<void> _handleClose(BuildContext context) async {+ await Future.sync(onClose ?? () {});+ if (!context.mounted) {+ return;+ }++ final route = ModalRoute.of(context);+ if (route == null || route.isCurrent) {+ await Navigator.of(context).maybePop();+ }+ }+}++class _BottomSheetActions extends StatelessWidget {+ const _BottomSheetActions({required this.actions});++ final List<Widget> actions;++ @override+ Widget build(BuildContext context) {+ return Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ for (var index = 0; index < actions.length; index++) ...[+ actions[index],+ if (index != actions.length - 1) const SizedBox(height: Spacing.md),+ ],+ ],+ );+ }+}++const double _headerHeight = 38;diff --git a/mobile/packages/ente_components/lib/components/bottom_sheet/error_bottom_sheet_component.dart b/mobile/packages/ente_components/lib/components/bottom_sheet/error_bottom_sheet_component.dartnew file mode 100644index 0000000000..bff5bb5adc--- /dev/null+++ b/mobile/packages/ente_components/lib/components/bottom_sheet/error_bottom_sheet_component.dart@@ -0,0 +1,40 @@+import 'dart:async';++import 'package:ente_components/components/bottom_sheet/bottom_sheet_component.dart';+import 'package:flutter/material.dart';++/// Shows the standard error sheet while leaving app-specific+/// localization, parsing, logging, and support actions to the caller.+Future<T?> showErrorBottomSheetComponent<T>({+ required BuildContext context,+ required String message,+ String title = 'Error',+ Widget? illustration,+ List<Widget> actions = const [],++ /// Called when the close button is pressed, before the sheet is dismissed.+ ///+ /// Barrier taps, drag dismissals, and system back dismissals do not call this.+ FutureOr<void> Function()? onClose,+ bool showCloseButton = true,+ bool isDismissible = true,+ bool enableDrag = true,+ bool useRootNavigator = false,+ Color? barrierColor,+}) {+ return showBottomSheetComponent<T>(+ context: context,+ isDismissible: isDismissible,+ enableDrag: enableDrag,+ useRootNavigator: useRootNavigator,+ barrierColor: barrierColor,+ builder: (_) => BottomSheetComponent(+ title: title,+ message: message,+ illustration: illustration,+ actions: actions,+ onClose: onClose,+ showCloseButton: showCloseButton,+ ),+ );+}diff --git a/mobile/packages/ente_components/lib/ente_components.dart b/mobile/packages/ente_components/lib/ente_components.dartindex 10e6dfa12b..82e9c73d7a 100644--- a/mobile/packages/ente_components/lib/ente_components.dart+++ b/mobile/packages/ente_components/lib/ente_components.dart@@ -1,5 +1,7 @@export 'components/app_bar_component.dart';export 'components/avatar_component.dart';+export 'components/bottom_sheet/bottom_sheet_component.dart';+export 'components/bottom_sheet/error_bottom_sheet_component.dart';export 'components/buttons/button_component.dart';export 'components/buttons/icon_button_component.dart';export 'components/filter_chip_component.dart';diff --git a/mobile/packages/ente_components/lib/theme/radii.dart b/mobile/packages/ente_components/lib/theme/radii.dartindex 2cd288fe22..a1b65b430e 100644--- a/mobile/packages/ente_components/lib/theme/radii.dart+++ b/mobile/packages/ente_components/lib/theme/radii.dart@@ -11,6 +11,7 @@ class Radii {static const double md = 12;static const double lg = 16;static const double button = 20;+ static const double bottomSheet = 20;static const double sheet = 24;static const Radius buttonRadius = Radius.circular(button);static const BorderRadius buttonBorder = BorderRadius.all(buttonRadius);diff --git a/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart b/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dartnew file mode 100644index 0000000000..17fbb085d4--- /dev/null+++ b/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart@@ -0,0 +1,281 @@+import 'dart:async';++import 'package:ente_components/ente_components.dart';+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';++void main() {+ testWidgets('BottomSheetHeaderComponent renders title and close action', (+ tester,+ ) async {+ var closeCount = 0;++ await tester.pumpWidget(+ _wrap(+ BottomSheetHeaderComponent(+ title: 'Title',+ onClose: () => closeCount += 1,+ ),+ ),+ );++ expect(find.text('Title'), findsOneWidget);+ expect(find.byTooltip('Close'), findsOneWidget);++ await tester.tap(find.byTooltip('Close'));+ await tester.pump();++ expect(closeCount, 1);+ });++ testWidgets('BottomSheetComponent renders custom content and actions', (+ tester,+ ) async {+ await tester.pumpWidget(+ _wrap(+ const BottomSheetComponent(+ title: 'Title',+ content: Text('Body copy'),+ actions: [+ ButtonComponent(label: 'Primary'),+ ButtonComponent(+ label: 'Secondary',+ variant: ButtonComponentVariant.secondary,+ ),+ ],+ ),+ ),+ );++ expect(find.text('Title'), findsOneWidget);+ expect(find.text('Body copy'), findsOneWidget);+ expect(find.text('Primary'), findsOneWidget);+ expect(find.text('Secondary'), findsOneWidget);+ });++ testWidgets('BottomSheetComponent centers illustration message', (+ tester,+ ) async {+ await tester.pumpWidget(+ _wrap(+ const BottomSheetComponent(+ title: 'Title',+ message: 'Centered message',+ illustration: SizedBox(+ key: ValueKey('warning-illustration'),+ width: 80,+ height: 80,+ ),+ ),+ ),+ );++ expect(find.byKey(const ValueKey('warning-illustration')), findsOneWidget);+ expect(find.text('Centered message'), findsOneWidget);++ final message = tester.widget<Text>(find.text('Centered message'));+ expect(message.textAlign, TextAlign.center);+ });++ testWidgets('BottomSheetComponent dismisses from close button by default', (+ tester,+ ) async {+ await _pumpLauncher(+ tester,+ (context) => showBottomSheetComponent<void>(+ context: context,+ builder: (_) => const BottomSheetComponent(+ title: 'Default close',+ content: Text('Sheet body'),+ ),+ ),+ );++ await _openLauncher(tester);++ expect(find.text('Default close'), findsOneWidget);++ await tester.tap(find.byTooltip('Close'));+ await tester.pumpAndSettle();++ expect(find.text('Default close'), findsNothing);+ });++ testWidgets('BottomSheetComponent does not pop a newer route after onClose', (+ tester,+ ) async {+ final closeCompleter = Completer<void>();++ await tester.pumpWidget(+ MaterialApp(+ theme: ComponentTheme.lightTheme(),+ routes: {+ '/': (context) {+ return Scaffold(+ body: ButtonComponent(+ label: 'Show sheet',+ onTap: () {+ return showBottomSheetComponent<void>(+ context: context,+ builder: (_) => BottomSheetComponent(+ title: 'Async close',+ content: const Text('Sheet body'),+ onClose: () async {+ unawaited(+ Navigator.of(context).push<void>(+ MaterialPageRoute<void>(+ builder: (_) =>+ const Scaffold(body: Text('New route')),+ ),+ ),+ );+ await closeCompleter.future;+ },+ ),+ );+ },+ ),+ );+ },+ },+ ),+ );++ await tester.tap(find.text('Show sheet'));+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 500));+ await tester.tap(find.byTooltip('Close'));+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 500));++ expect(find.text('New route'), findsOneWidget);++ closeCompleter.complete();+ await tester.pump();++ expect(find.text('New route'), findsOneWidget);+ });++ testWidgets('showErrorBottomSheetComponent presents error content', (+ tester,+ ) async {+ var closeCount = 0;++ await _pumpLauncher(+ tester,+ (context) => showErrorBottomSheetComponent<void>(+ context: context,+ message: 'Something went wrong.',+ onClose: () => closeCount += 1,+ actions: const [+ ButtonComponent(+ label: 'Contact support',+ variant: ButtonComponentVariant.secondary,+ ),+ ],+ ),+ label: 'Show error',+ );++ await _openLauncher(tester, label: 'Show error');++ expect(find.text('Error'), findsOneWidget);+ expect(find.text('Something went wrong.'), findsOneWidget);+ expect(find.text('Contact support'), findsOneWidget);++ await tester.tap(find.byTooltip('Close'));+ await tester.pumpAndSettle();++ expect(closeCount, 1);+ expect(find.text('Error'), findsNothing);+ });++ testWidgets('showErrorBottomSheetComponent can hide close button', (+ tester,+ ) async {+ await _pumpLauncher(+ tester,+ (context) => showErrorBottomSheetComponent<void>(+ context: context,+ message: 'Something went wrong.',+ showCloseButton: false,+ ),+ label: 'Show error',+ );++ await _openLauncher(tester, label: 'Show error');++ expect(find.text('Error'), findsOneWidget);+ expect(find.byTooltip('Close'), findsNothing);+ });++ testWidgets('BottomSheetComponent applies keyboard inset padding', (+ tester,+ ) async {+ await tester.pumpWidget(+ MaterialApp(+ theme: ComponentTheme.lightTheme(),+ home: const MediaQuery(+ data: MediaQueryData(viewInsets: EdgeInsets.only(bottom: 120)),+ child: Material(+ child: BottomSheetComponent(+ title: 'Keyboard aware',+ content: Text('Input content'),+ isKeyboardAware: true,+ ),+ ),+ ),+ ),+ );++ final animatedPadding = tester.widget<AnimatedPadding>(+ find.byType(AnimatedPadding),+ );+ expect(animatedPadding.padding, const EdgeInsets.only(bottom: 120));+ });+}++Widget _wrap(Widget child) {+ return MaterialApp(+ theme: ComponentTheme.lightTheme(),+ home: Scaffold(+ body: Align(+ alignment: Alignment.topLeft,+ child: SizedBox(width: 375, child: child),+ ),+ ),+ );+}++Future<void> _pumpLauncher<T>(+ WidgetTester tester,+ Future<T?> Function(BuildContext context) onTap, {+ String label = 'Show sheet',+}) {+ return tester.pumpWidget(+ MaterialApp(+ theme: ComponentTheme.lightTheme(),+ home: Builder(+ builder: (context) {+ return Scaffold(+ body: ButtonComponent(+ label: label,+ onTap: () async {+ await onTap(context);+ },+ ),+ );+ },+ ),+ ),+ );+}++Future<void> _openLauncher(+ WidgetTester tester, {+ String label = 'Show sheet',+}) async {+ await tester.tap(find.text(label));+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 500));+}diff --git a/mobile/packages/ente_components/test/theme/theme_tokens_test.dart b/mobile/packages/ente_components/test/theme/theme_tokens_test.dartindex e7ebcfc73d..3bf14a548b 100644--- a/mobile/packages/ente_components/test/theme/theme_tokens_test.dart+++ b/mobile/packages/ente_components/test/theme/theme_tokens_test.dart@@ -14,6 +14,7 @@ void main() {expect(Radii.xs, 4);expect(Radii.md, 12);expect(Radii.button, 20);+ expect(Radii.bottomSheet, 20);expect(Radii.buttonRadius, const Radius.circular(20));expect(Radii.buttonBorder, const BorderRadius.all(Radius.circular(20)));