π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Refresh photo selection with an expandable action sheet
r4khul77abc8ed64a2
diff --git a/mobile/apps/photos/changes/selection-action-sheet.md b/mobile/apps/photos/changes/selection-action-sheet.mdnew file mode 100644index 0000000000..04c15bc713--- /dev/null+++ b/mobile/apps/photos/changes/selection-action-sheet.md@@ -0,0 +1 @@+- Refreshed photo selection with an expandable actions sheet that collapses while browsing.diff --git a/mobile/apps/photos/lib/ui/components/bottom_action_bar/action_bar_widget.dart b/mobile/apps/photos/lib/ui/components/bottom_action_bar/action_bar_widget.dartindex f2d70551c5..cc69707f2b 100644--- a/mobile/apps/photos/lib/ui/components/bottom_action_bar/action_bar_widget.dart+++ b/mobile/apps/photos/lib/ui/components/bottom_action_bar/action_bar_widget.dart@@ -1,105 +1,107 @@-import 'package:ente_components/ente_components.dart' as components;+import "package:ente_components/components/chip_surface.dart";+import "package:ente_components/ente_components.dart";import "package:ente_strings/ente_strings.dart";-import 'package:flutter/material.dart';-import 'package:photos/core/configuration.dart';-import 'package:photos/models/selected_files.dart';--class ActionBarWidget extends StatefulWidget {- final SelectedFiles? selectedFiles;- final VoidCallback? onCancel;+import "package:flutter/material.dart";+import "package:hugeicons/hugeicons.dart";+import "package:photos/core/configuration.dart";+import "package:photos/models/selected_files.dart";+class ActionBarWidget extends StatelessWidget {const ActionBarWidget({+ required this.selectedFiles,required this.onCancel,- this.selectedFiles,super.key,});- @override- State<ActionBarWidget> createState() => _ActionBarWidgetState();-}--class _ActionBarWidgetState extends State<ActionBarWidget> {- final ValueNotifier<int> _selectedFilesNotifier = ValueNotifier(0);- final ValueNotifier<int> _selectedOwnedFilesNotifier = ValueNotifier(0);-- //User ID will be null if the user is not logged in (links-in-app)- final int currentUserID = Configuration.instance.getUserID() ?? -1;+ final SelectedFiles selectedFiles;+ final VoidCallback onCancel;@override- void initState() {- super.initState();- widget.selectedFiles?.addListener(_selectedFilesListener);- _selectedFilesListener();+ Widget build(BuildContext context) {+ return ListenableBuilder(+ listenable: selectedFiles,+ builder: (context, _) {+ final currentUserID = Configuration.instance.getUserID() ?? -1;+ final ownedCount = selectedFiles.files+ .where(+ (file) => file.ownerID == null || file.ownerID == currentUserID,+ )+ .length;+ final summary = ownedCount == selectedFiles.files.length+ ? context.strings.selectedPhotos(count: selectedFiles.files.length)+ : context.strings.selectedPhotosWithYours(+ count: selectedFiles.files.length,+ yourCount: ownedCount,+ );+ return SelectionControlChip(+ label: selectedFiles.files.length.toString(),+ semanticLabel: "${context.strings.cancel}, $summary",+ icon: const HugeIcon(+ icon: HugeIcons.strokeRoundedCancel01,+ size: IconSizes.small,+ ),+ onTap: onCancel,+ );+ },+ );}+}- @override- void dispose() {- _selectedFilesNotifier.dispose();- _selectedOwnedFilesNotifier.dispose();- widget.selectedFiles?.removeListener(_selectedFilesListener);- super.dispose();- }+class SelectionControlChip extends StatelessWidget {+ const SelectionControlChip({+ required this.label,+ required this.semanticLabel,+ required this.icon,+ required this.onTap,+ this.isSelected = false,+ super.key,+ });++ final String label;+ final String semanticLabel;+ final Widget icon;+ final VoidCallback? onTap;+ final bool isSelected;@overrideWidget build(BuildContext context) {- final colors = components.ComponentTheme.colorsOf(context);- final miniStyle = components.TextStyles.mini.copyWith(- color: colors.textBase,- );- return SizedBox(- child: Padding(- padding: const EdgeInsets.fromLTRB(20, 8, 20, 8),- child: Row(- mainAxisAlignment: MainAxisAlignment.spaceBetween,- children: [- Flexible(- flex: 1,- child: ValueListenableBuilder(- valueListenable: _selectedFilesNotifier,- builder: (context, value, child) {- return Text(- _selectedOwnedFilesNotifier.value !=- _selectedFilesNotifier.value- ? context.strings.selectedPhotosWithYours(- count: _selectedFilesNotifier.value,- yourCount: _selectedOwnedFilesNotifier.value,- )- : context.strings.selectedPhotos(- count: _selectedFilesNotifier.value,- ),- style: miniStyle,- );- },- ),- ),- Flexible(- flex: 1,- child: Padding(- padding: const EdgeInsets.symmetric(vertical: 12),- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: () {- widget.onCancel?.call();- },- child: Align(- alignment: Alignment.centerRight,- child: Text(context.strings.cancel, style: miniStyle),- ),- ),- ),+ final colors = context.componentColors;+ final color = onTap == null ? colors.textLightest : colors.textBase;+ return ChipSurface(+ surfaceKey: const ValueKey("selection-control-chip"),+ enabled: onTap != null,+ selected: isSelected,+ semanticLabel: semanticLabel,+ tooltip: semanticLabel,+ minHeight: 44,+ minWidth: 64,+ padding: const EdgeInsets.symmetric(+ horizontal: Spacing.lg,+ vertical: Spacing.md,+ ),+ background: colors.fillLight,+ borderRadius: BorderRadius.circular(100),+ onTap: onTap,+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Flexible(+ child: Text(+ label,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: TextStyles.body.copyWith(color: color),),- ],- ),+ ),+ const SizedBox(width: Spacing.md),+ ChipIconSlot(+ color: color,+ size: IconSizes.small,+ slotSize: IconSizes.small,+ child: icon,+ ),+ ],),);}-- void _selectedFilesListener() {- if (widget.selectedFiles?.files.isNotEmpty ?? false) {- _selectedFilesNotifier.value = widget.selectedFiles!.files.length;- _selectedOwnedFilesNotifier.value = widget.selectedFiles!.files- .where((f) => f.ownerID == null || f.ownerID! == currentUserID)- .length;- }- }}diff --git a/mobile/apps/photos/lib/ui/components/bottom_action_bar/bottom_action_bar_widget.dart b/mobile/apps/photos/lib/ui/components/bottom_action_bar/bottom_action_bar_widget.dartdeleted file mode 100644index 2d395e6aa4..0000000000--- a/mobile/apps/photos/lib/ui/components/bottom_action_bar/bottom_action_bar_widget.dart+++ /dev/null@@ -1,72 +0,0 @@-import "package:ente_components/ente_components.dart" as components;-import "package:ente_ui/components/divider_widget.dart";-import 'package:flutter/material.dart';-import 'package:photos/core/constants.dart';-import 'package:photos/models/collection/collection.dart';-import "package:photos/models/gallery_type.dart";-import "package:photos/models/ml/face/person.dart";-import 'package:photos/models/selected_files.dart';-import 'package:photos/ui/components/bottom_action_bar/action_bar_widget.dart';-import "package:photos/ui/viewer/actions/file_selection_actions_widget.dart";--class BottomActionBarWidget extends StatelessWidget {- final GalleryType galleryType;- final Collection? collection;- final PersonEntity? person;- final String? clusterID;- final SelectedFiles selectedFiles;- final VoidCallback? onCancel;- final Color? backgroundColor;-- const BottomActionBarWidget({- required this.galleryType,- required this.selectedFiles,- this.collection,- this.person,- this.clusterID,- this.onCancel,- this.backgroundColor,- super.key,- });-- @override- Widget build(BuildContext context) {- final bottomPadding = MediaQuery.paddingOf(context).bottom;- final widthOfScreen = MediaQuery.of(context).size.width;- final colors = components.ComponentTheme.colorsOf(context);- final double leftRightPadding = widthOfScreen > restrictedMaxWidth- ? (widthOfScreen - restrictedMaxWidth) / 2- : 0;- return Container(- decoration: BoxDecoration(- color: backgroundColor ?? colors.backgroundBase,- border: Border(top: BorderSide(color: colors.strokeDark)),- borderRadius: const BorderRadius.only(- topLeft: Radius.circular(20),- topRight: Radius.circular(20),- ),- ),- padding: EdgeInsets.only(- top: 4,- bottom: bottomPadding,- right: leftRightPadding,- left: leftRightPadding,- ),- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- const SizedBox(height: 8),- FileSelectionActionsWidget(- galleryType,- selectedFiles,- collection: collection,- person: person,- clusterID: clusterID,- ),- const DividerWidget(dividerType: DividerType.bottomBar),- ActionBarWidget(selectedFiles: selectedFiles, onCancel: onCancel),- ],- ),- );- }-}diff --git a/mobile/apps/photos/lib/ui/components/bottom_action_bar/selection_action_sheet.dart b/mobile/apps/photos/lib/ui/components/bottom_action_bar/selection_action_sheet.dartnew file mode 100644index 0000000000..801846d7a5--- /dev/null+++ b/mobile/apps/photos/lib/ui/components/bottom_action_bar/selection_action_sheet.dart@@ -0,0 +1,548 @@+import "dart:async";+import "dart:math" as math;++import "package:ente_components/ente_components.dart";+import "package:ente_strings/ente_strings.dart";+import "package:flutter/material.dart";+import "package:flutter/rendering.dart" show ScrollDirection;+import "package:hugeicons/hugeicons.dart";+import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";++class SelectionSheetAction {+ const SelectionSheetAction({+ required this.labelText,+ required this.onTap,+ this.hugeIcon,+ this.iconWidget,+ this.shouldShow = true,+ this.isCritical = false,+ this.gridOrder,+ this.key,+ }) : assert(hugeIcon != null || iconWidget != null);++ final String labelText;+ final VoidCallback? onTap;+ final List<List<dynamic>>? hugeIcon;+ final Widget? iconWidget;+ final bool shouldShow;+ final bool isCritical;+ final int? gridOrder;+ final Key? key;+}++class SelectionActionSheet extends StatefulWidget {+ const SelectionActionSheet({+ required this.actions,+ required this.selectionControls,+ this.backgroundColor,+ super.key,+ });++ final List<SelectionSheetAction> actions;+ final Widget selectionControls;+ final Color? backgroundColor;++ @override+ State<SelectionActionSheet> createState() => _SelectionActionSheetState();+}++class _SelectionActionSheetState extends State<SelectionActionSheet> {+ final _sheetController = DraggableScrollableController();+ InheritedGalleryBoundaries? _boundaries;+ ScrollController? _galleryController;+ ValueNotifier<bool>? _galleryScrolling;+ ScrollController? _actionsController;+ double _minExtent = 0;+ double _maxExtent = 1;+ bool _isCollapsing = false;++ static const _duration = Motion.slow;++ @override+ void didChangeDependencies() {+ super.didChangeDependencies();+ final boundaries = GalleryBoundariesProvider.of(context);+ if (_boundaries != boundaries) {+ _boundaries?.scrollControllerNotifier.removeListener(_bindGallery);+ _boundaries = boundaries;+ _boundaries?.scrollControllerNotifier.addListener(_bindGallery);+ _bindGallery();+ }+ }++ void _bindGallery() {+ _galleryController?.removeListener(_onGalleryScroll);+ _galleryScrolling?.removeListener(_onGalleryActivityChanged);+ _galleryController = _boundaries?.scrollControllerNotifier.value;+ _galleryController?.addListener(_onGalleryScroll);+ _galleryScrolling = _galleryController?.positions.length == 1+ ? _galleryController!.position.isScrollingNotifier+ : null;+ _galleryScrolling?.addListener(_onGalleryActivityChanged);+ }++ void _onGalleryScroll() {+ if (_isCollapsing ||+ !_sheetController.isAttached ||+ _galleryController?.positions.length != 1 ||+ _galleryController!.position.userScrollDirection ==+ ScrollDirection.idle ||+ _sheetController.size <= _minExtent + 0.001) {+ return;+ }+ _isCollapsing = true;+ unawaited(_moveTo(_minExtent));+ }++ void _onGalleryActivityChanged() {+ if (!(_galleryScrolling?.value ?? false)) _isCollapsing = false;+ }++ void _toggleSheet() {+ if (!_sheetController.isAttached) return;+ unawaited(+ _moveTo(+ _sheetController.size >= _maxExtent - 0.001 ? _minExtent : _maxExtent,+ ),+ );+ }++ Future<void> _moveTo(double extent) async {+ if (!_sheetController.isAttached) return;+ if (extent == _minExtent && (_actionsController?.hasClients ?? false)) {+ _actionsController!.jumpTo(0);+ }+ if (MediaQuery.disableAnimationsOf(context)) {+ _sheetController.jumpTo(extent);+ } else {+ await _sheetController.animateTo(+ extent,+ duration: _duration,+ curve: Curves.easeOutCubic,+ );+ }+ }++ @override+ void dispose() {+ _boundaries?.scrollControllerNotifier.removeListener(_bindGallery);+ _galleryController?.removeListener(_onGalleryScroll);+ _galleryScrolling?.removeListener(_onGalleryActivityChanged);+ _sheetController.dispose();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ final visible = widget.actions+ .where((action) => action.shouldShow)+ .toList();+ final preferred =+ visible.where((action) => action.gridOrder != null).toList()+ ..sort((a, b) => a.gridOrder!.compareTo(b.gridOrder!));+ final grid = preferred.isEmpty ? visible.take(4).toList() : preferred;+ final rows = visible.where((action) => !grid.contains(action)).toList();+ if (visible.isEmpty) return const SizedBox.shrink();+ final media = MediaQuery.of(context);+ final isLandscape = media.orientation == Orientation.landscape;+ final handlePadding = EdgeInsets.only(+ top: isLandscape ? Spacing.md : Spacing.lg,+ bottom: isLandscape ? Spacing.sm : Spacing.md,+ );+ final handleHeight = handlePadding.vertical + 5;+ final controlsSpacing = isLandscape ? Spacing.xs : Spacing.sm;+ final dividerSpacing = isLandscape ? Spacing.sm : Spacing.lg;+ final gridRowSpacing = isLandscape ? Spacing.sm : Spacing.md;+ final colors = context.componentColors;+ final sheetColor = widget.backgroundColor ?? colors.fillLight;+ final miniHeight =+ media.textScaler.scale(TextStyles.mini.fontSize!) *+ TextStyles.mini.height!;+ final rowHeight = math.max(48.0, miniHeight * 2 + Spacing.lg);+ final controlsHeight = math.max(+ 44.0,+ media.textScaler.scale(TextStyles.body.fontSize!) *+ TextStyles.body.height! ++ Spacing.md * 2,+ );+ final dividerHeight = dividerSpacing * 2 + 1 + Spacing.xs;+ final baseHeight =+ controlsHeight + controlsSpacing + handleHeight + media.padding.bottom;++ return LayoutBuilder(+ builder: (context, constraints) {+ final availableWidth = constraints.maxWidth - media.padding.horizontal;+ final sheetWidth = math.min(+ 640.0,+ availableWidth - (isLandscape ? Spacing.lg * 2 : 0),+ );+ final minTileWidth =+ 64 *+ media.textScaler.scale(TextStyles.mini.fontSize!) /+ TextStyles.mini.fontSize!;+ final gridWidth = sheetWidth - Spacing.md * 2;+ final availableColumns =+ isLandscape &&+ grid.length > 4 &&+ gridWidth >= minTileWidth * 8 + Spacing.xs * 7+ ? 8+ : gridWidth >= minTileWidth * 4 + Spacing.xs * 3+ ? 4+ : 2;+ final columns = math.min(availableColumns, grid.length);+ final gridRows = (grid.length / columns).ceil();+ final labelWidth =+ (sheetWidth - Spacing.md * 2 - Spacing.xs * (columns - 1)) /+ columns;+ var labelHeight = miniHeight;+ for (final action in grid) {+ final painter = TextPainter(+ text: TextSpan(text: action.labelText, style: TextStyles.mini),+ textDirection: Directionality.of(context),+ textScaler: media.textScaler,+ maxLines: 2,+ ellipsis: "β¦",+ )..layout(maxWidth: math.max(0, labelWidth));+ labelHeight = math.max(labelHeight, painter.height);+ painter.dispose();+ }+ final tileHeight = math.max(+ 64.0,+ IconSizes.small + Spacing.sm * 2 + Spacing.xs * 3 + labelHeight,+ );+ final gridHeight =+ gridRows * tileHeight + (gridRows - 1) * gridRowSpacing;+ final bottomSpacing = rows.isEmpty+ ? Spacing.sm+ : isLandscape+ ? Spacing.lg+ : Spacing.xxl;+ final fullHeight =+ baseHeight ++ gridHeight ++ bottomSpacing ++ (rows.isEmpty ? 0 : dividerHeight + rows.length * rowHeight);+ final availableHeight = math.min(+ constraints.maxHeight,+ media.size.height,+ );+ final maxHeight = math.min(+ fullHeight,+ math.max(+ 0.0,+ availableHeight - media.viewPadding.top - kToolbarHeight,+ ),+ );+ if (maxHeight <= controlsHeight + controlsSpacing) {+ return const SizedBox.shrink();+ }+ final minHeight = math.min(+ baseHeight + tileHeight + Spacing.sm,+ maxHeight,+ );+ final peekHeight = math.min(+ baseHeight ++ gridHeight ++ (rows.isEmpty ? Spacing.sm : dividerHeight + rowHeight / 2),+ maxHeight,+ );+ _minExtent = minHeight / availableHeight;+ _maxExtent = maxHeight / availableHeight;+ final peekExtent = peekHeight / availableHeight;++ return SafeArea(+ top: false,+ bottom: false,+ child: Align(+ alignment: Alignment.bottomCenter,+ heightFactor: 1,+ child: SizedBox(+ width: sheetWidth,+ child: DraggableScrollableSheet(+ controller: _sheetController,+ expand: false,+ initialChildSize: peekExtent,+ minChildSize: _minExtent,+ maxChildSize: _maxExtent,+ shouldCloseOnMinExtent: false,+ snap: true,+ snapSizes: peekExtent > _minExtent && peekExtent < _maxExtent+ ? [peekExtent]+ : null,+ snapAnimationDuration: MediaQuery.disableAnimationsOf(context)+ ? const Duration(milliseconds: 1)+ : _duration,+ builder: (context, scrollController) {+ _actionsController = scrollController;+ return Column(+ children: [+ SizedBox(+ height: controlsHeight,+ child: widget.selectionControls,+ ),+ SizedBox(height: controlsSpacing),+ Expanded(+ child: Material(+ color: sheetColor,+ borderRadius: const BorderRadius.vertical(+ top: Radius.circular(Radii.bottomSheet),+ ),+ clipBehavior: Clip.antiAlias,+ child: SafeArea(+ top: false,+ child: CustomScrollView(+ controller: scrollController,+ slivers: [+ SliverPersistentHeader(+ pinned: true,+ delegate: _SheetHandle(+ height: handleHeight,+ backgroundColor: sheetColor,+ child: Semantics(+ button: true,+ label: context.strings.more,+ onTap: _toggleSheet,+ onIncrease: () => _moveTo(_maxExtent),+ onDecrease: () => _moveTo(_minExtent),+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: _toggleSheet,+ child: Padding(+ padding: handlePadding,+ child: Center(+ child: Container(+ width: 36,+ height: 5,+ decoration: BoxDecoration(+ color: colors.textLightest,+ borderRadius:+ BorderRadius.circular(3),+ ),+ ),+ ),+ ),+ ),+ ),+ ),+ ),+ SliverToBoxAdapter(+ child: Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: Spacing.md,+ ),+ child: Column(+ spacing: gridRowSpacing,+ children: [+ for (+ var start = 0;+ start < grid.length;+ start += columns+ )+ Row(+ spacing: Spacing.xs,+ children: [+ for (final action+ in grid+ .skip(start)+ .take(columns))+ Expanded(+ child: _SheetAction(+ key: action.key,+ action: action,+ height: tileHeight,+ ),+ ),+ for (+ var i = grid+ .skip(start)+ .take(columns)+ .length;+ i < columns;+ i+++ )+ const Expanded(+ child: SizedBox.shrink(),+ ),+ ],+ ),+ ],+ ),+ ),+ ),+ if (rows.isNotEmpty) ...[+ SliverToBoxAdapter(+ child: DividerComponent(+ padding: EdgeInsets.symmetric(+ horizontal: Spacing.lg,+ vertical: dividerSpacing,+ ),+ ),+ ),+ SliverToBoxAdapter(+ child: ListenableBuilder(+ listenable: _sheetController,+ builder: (context, child) {+ final enabled =+ _sheetController.isAttached+ ? _sheetController.size >=+ _maxExtent - 0.001+ : peekExtent >= _maxExtent;+ return IgnorePointer(+ ignoring: !enabled,+ child: ExcludeSemantics(+ excluding: !enabled,+ child: child,+ ),+ );+ },+ child: Padding(+ padding: const EdgeInsets.only(+ top: Spacing.xs,+ ),+ child: Column(+ children: [+ for (final action in rows)+ _SheetAction(+ key: action.key,+ action: action,+ height: rowHeight,+ isRow: true,+ ),+ ],+ ),+ ),+ ),+ ),+ ],+ SliverToBoxAdapter(+ child: SizedBox(height: bottomSpacing),+ ),+ ],+ ),+ ),+ ),+ ),+ ],+ );+ },+ ),+ ),+ ),+ );+ },+ );+ }+}++class _SheetHandle extends SliverPersistentHeaderDelegate {+ _SheetHandle({+ required this.child,+ required this.backgroundColor,+ required this.height,+ });++ final Widget child;+ final Color backgroundColor;+ final double height;++ @override+ double get minExtent => height;++ @override+ double get maxExtent => height;++ @override+ Widget build(+ BuildContext context,+ double shrinkOffset,+ bool overlapsContent,+ ) => ColoredBox(color: backgroundColor, child: child);++ @override+ bool shouldRebuild(covariant _SheetHandle oldDelegate) =>+ child != oldDelegate.child ||+ backgroundColor != oldDelegate.backgroundColor ||+ height != oldDelegate.height;+}++class _SheetAction extends StatelessWidget {+ const _SheetAction({+ required this.action,+ required this.height,+ this.isRow = false,+ super.key,+ });++ final SelectionSheetAction action;+ final double height;+ final bool isRow;++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ final iconColor = action.onTap == null+ ? colors.textLightest+ : action.isCritical+ ? colors.warning+ : colors.textLight;+ final textColor = action.onTap != null && isRow && !action.isCritical+ ? colors.textBase+ : iconColor;+ final icon = action.hugeIcon != null+ ? HugeIcon(+ icon: action.hugeIcon!,+ size: IconSizes.small,+ color: iconColor,+ )+ : IconTheme.merge(+ data: IconThemeData(size: IconSizes.small, color: iconColor),+ child: action.iconWidget!,+ );+ final label = Text(+ action.labelText,+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ textAlign: isRow ? TextAlign.start : TextAlign.center,+ style: TextStyles.mini.copyWith(color: textColor),+ );+ return Semantics(+ button: true,+ enabled: action.onTap != null,+ child: InkWell(+ onTap: action.onTap,+ borderRadius: isRow ? null : BorderRadius.circular(Radii.md),+ child: SizedBox(+ height: height,+ child: Padding(+ padding: EdgeInsets.symmetric(+ horizontal: isRow ? Spacing.lg : 0,+ vertical: isRow ? 0 : Spacing.xs,+ ),+ child: isRow+ ? Row(+ children: [+ Padding(+ padding: const EdgeInsets.all(Spacing.sm),+ child: icon,+ ),+ const SizedBox(width: Spacing.md),+ Expanded(child: label),+ ],+ )+ : Column(+ mainAxisAlignment: MainAxisAlignment.start,+ children: [+ Padding(+ padding: const EdgeInsets.all(Spacing.sm),+ child: icon,+ ),+ const SizedBox(height: Spacing.xs),+ label,+ ],+ ),+ ),+ ),+ ),+ );+ }+}diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dartindex 6a8ff77b38..c31097f9ff 100644--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart@@ -2,7 +2,6 @@ import "dart:async";import "dart:io";import "package:ente_components/ente_components.dart";-import "package:ente_icons/ente_icons.dart";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:ente_strings/ente_strings.dart";import 'package:flutter/material.dart';@@ -43,7 +42,7 @@ import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';import 'package:photos/ui/collections/collection_action_sheet.dart';import "package:photos/ui/common/photo_library_add_permission.dart";import 'package:photos/ui/components/action_sheet_widget.dart';-import "package:photos/ui/components/bottom_action_bar/selection_action_button_widget.dart";+import "package:photos/ui/components/bottom_action_bar/selection_action_sheet.dart";import 'package:photos/ui/components/buttons/button_widget.dart';import 'package:photos/ui/components/models/button_type.dart';import 'package:photos/ui/notification/toast.dart';@@ -66,11 +65,15 @@ class FileSelectionActionsWidget extends StatefulWidget {final SelectedFiles selectedFiles;final PersonEntity? person;final String? clusterID;+ final Widget selectionControls;+ final Color? backgroundColor;const FileSelectionActionsWidget(this.type,this.selectedFiles, {super.key,+ required this.selectionControls,+ this.backgroundColor,this.collection,this.person,this.clusterID,@@ -95,7 +98,6 @@ class _FileSelectionActionsWidgetStatefinal GlobalKey sendLinkButtonKey = GlobalKey();final StreamController<double> _progressController =StreamController<double>();- final ScrollController _scrollController = ScrollController();bool get _canRemoveOthersFiles =>widget.collection != null &&@@ -119,7 +121,6 @@ class _FileSelectionActionsWidgetState@overridevoid dispose() {_progressController.close();- _scrollController.dispose();widget.selectedFiles.removeListener(_selectFileChangeListener);super.dispose();}@@ -172,18 +173,17 @@ class _FileSelectionActionsWidgetStateisCollectionOwnerOrAdmin &&split.ownedByOtherUsers.isNotEmpty;- // Hidden items remain in the list so their removal can animate.- final List<SelectionActionButton> items = [];+ final List<SelectionSheetAction> items = [];if (widget.type == GalleryType.trash) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedRestoreBin,labelText: context.strings.restore,onTap: _restore,),);items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedDelete01,labelText: context.strings.permanentlyDelete,onTap: _permanentlyDeleteFromTrash,@@ -192,7 +192,7 @@ class _FileSelectionActionsWidgetState);} else if (widget.type == GalleryType.cleanupHiddenFromDevice) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedDelete01,labelText: context.strings.deleteFromDevice,onTap: _deleteSelectedFromDevice,@@ -201,7 +201,7 @@ class _FileSelectionActionsWidgetState);} else if (widget.type == GalleryType.deleteSuggestions) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedDelete01,labelText: context.strings.delete,onTap: split.ownedByCurrentUser.isNotEmpty ? _onDeleteClick : null,@@ -209,7 +209,7 @@ class _FileSelectionActionsWidgetState),);items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedCancel01,labelText: context.strings.rejectSuggestions,onTap: widget.selectedFiles.files.isNotEmpty@@ -220,8 +220,9 @@ class _FileSelectionActionsWidgetState} else {if (widget.type != GalleryType.sharedPublicCollection) {items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.share,+ gridOrder: 0,hugeIcon: Platform.isIOS? HugeIcons.strokeRoundedShare03: HugeIcons.strokeRoundedShare08,@@ -233,7 +234,7 @@ class _FileSelectionActionsWidgetStateif (_canShowOfflineLinkOption(widget.selectedFiles.files)) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedLink02,labelText: pendingTranslation("(i) Offline link"),onTap: _showOfflineLinkShareSheet,@@ -244,17 +245,19 @@ class _FileSelectionActionsWidgetStateif (widget.type.showCreateLink()) {if (_cachedCollectionForSharedLink != null && anyUploadedFiles) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedCopy01,labelText: context.strings.copyLink,+ gridOrder: 1,onTap: anyUploadedFiles ? _sendLink : null,),);} else {items.add(- SelectionActionButton(- hugeIcon: HugeIcons.strokeRoundedNavigation03,+ SelectionSheetAction(+ hugeIcon: HugeIcons.strokeRoundedLink02,labelText: context.strings.sendLink,+ gridOrder: 1,onTap: anyUploadedFiles ? _onSendLinkTapped : null,shouldShow: ownedFilesCount > 0,key: sendLinkButtonKey,@@ -269,17 +272,19 @@ class _FileSelectionActionsWidgetStateif (widget.type.showAddToAlbum() && !isLocalGalleryMode) {if (showUploadIcon) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedCloudUpload,labelText: context.strings.addToEnte,+ gridOrder: 4,onTap: _addToAlbum,),);} else {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedImageAdd01,labelText: context.strings.addToAlbum,+ gridOrder: 4,onTap: _addToAlbum,),);@@ -288,9 +293,10 @@ class _FileSelectionActionsWidgetStateif (widget.type.showAddtoHiddenAlbum()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedImageAdd01,labelText: context.strings.addToAlbum,+ gridOrder: 4,onTap: _addToHiddenAlbum,),);@@ -298,7 +304,7 @@ class _FileSelectionActionsWidgetStateif (widget.type.showMoveToAlbum()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedArrowRight01,labelText: context.strings.moveToAlbum,onTap: anyUploadedFiles ? _moveFiles : null,@@ -309,7 +315,7 @@ class _FileSelectionActionsWidgetStateif (widget.type.showMovetoHiddenAlbum()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedArrowRight01,labelText: context.strings.moveToAlbum,onTap: _moveFilesToHiddenAlbum,@@ -319,7 +325,7 @@ class _FileSelectionActionsWidgetStateif (widget.type.showRemoveFromAlbum()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedRemove01,labelText: context.strings.removeFromAlbum,onTap: removeCount > 0 ? _removeFilesFromAlbum : null,@@ -330,7 +336,7 @@ class _FileSelectionActionsWidgetStateif (widget.type.showRemoveFromHiddenAlbum()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedRemove01,labelText: context.strings.removeFromAlbum,onTap: _removeFilesFromHiddenAlbum,@@ -340,7 +346,7 @@ class _FileSelectionActionsWidgetStateif (canSuggestDeleteAction) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedFlag01,labelText: context.strings.suggestDeletion,onTap: _onSuggestDelete,@@ -350,9 +356,10 @@ class _FileSelectionActionsWidgetStateif (widget.type.showDeleteOption()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedDelete01,labelText: context.strings.delete,+ gridOrder: 3,onTap: anyOwnedFiles ? _onDeleteClick : null,shouldShow: allOwnedFiles,isCritical: true,@@ -362,7 +369,7 @@ class _FileSelectionActionsWidgetStateif (widget.type.showRestoreOption()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedRestoreBin,labelText: context.strings.restore,onTap: _restore,@@ -372,7 +379,7 @@ class _FileSelectionActionsWidgetStateif (widget.type.showPermanentlyDeleteOption()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedDelete01,labelText: context.strings.permanentlyDelete,onTap: _permanentlyDeleteFromTrash,@@ -383,8 +390,9 @@ class _FileSelectionActionsWidgetStateif (showDownloadOption) {items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.download,+ gridOrder: 7,hugeIcon: HugeIcons.strokeRoundedDownload01,onTap: () => _download(widget.selectedFiles.files.toList()),),@@ -393,18 +401,20 @@ class _FileSelectionActionsWidgetStateif (widget.type.showFavoriteOption()) {items.add(- SelectionActionButton(- iconWidget: const Icon(EnteIcons.favoriteStroke),+ SelectionSheetAction(+ hugeIcon: HugeIcons.strokeRoundedStar,labelText: context.strings.favorite,+ gridOrder: 2,onTap: anyUploadedFiles ? _onFavoriteClick : null,shouldShow: ownedFilesCount > 0,),);} else if (widget.type.showUnFavoriteOption()) {items.add(- SelectionActionButton(- iconWidget: const Icon(EnteIcons.favoriteFilled),+ SelectionSheetAction(+ iconWidget: const Icon(Icons.star_rounded),labelText: context.strings.removeFromFavorite,+ gridOrder: 2,onTap: _onUnFavoriteClick,shouldShow: ownedFilesCount > 0,),@@ -414,7 +424,7 @@ class _FileSelectionActionsWidgetStateif (flagService.manualTagFileToPerson &&widget.type.showAddToPersonOption()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedUserAdd01,labelText: context.strings.addToPerson,onTap: hasUploadedFileIDs ? _onAddFilesToPerson : null,@@ -425,7 +435,7 @@ class _FileSelectionActionsWidgetStateif (widget.type == GalleryType.peopleTag && widget.person != null) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedUserRemove01,labelText: context.strings.notPersonLabel(name: widget.person!.data.name,@@ -435,7 +445,7 @@ class _FileSelectionActionsWidgetState);if (ownedFilesCount == 1) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedImage01,labelText: context.strings.useAsCover,onTap: anyUploadedFiles ? _setPersonCover : null,@@ -446,7 +456,7 @@ class _FileSelectionActionsWidgetStateif (widget.type == GalleryType.cluster && widget.clusterID != null) {items.add(- SelectionActionButton(+ SelectionSheetAction(labelText: context.strings.notThisPerson,hugeIcon: HugeIcons.strokeRoundedUserRemove01,onTap: _onRemoveFromClusterClicked,@@ -456,7 +466,7 @@ class _FileSelectionActionsWidgetStateif (widget.type != GalleryType.sharedPublicCollection) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedGridView,labelText: context.strings.createCollage,onTap: _onCreateCollageClicked,@@ -467,18 +477,20 @@ class _FileSelectionActionsWidgetStateif (widget.type.showHideOption()) {items.add(- SelectionActionButton(- hugeIcon: HugeIcons.strokeRoundedViewOffSlash,+ SelectionSheetAction(+ hugeIcon: HugeIcons.strokeRoundedViewOff,labelText: context.strings.hide,+ gridOrder: 5,onTap: anyUploadedFiles ? _onHideClick : null,shouldShow: ownedFilesCount > 0,),);} else if (widget.type.showUnHideOption()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedView,labelText: context.strings.unhide,+ gridOrder: 5,onTap: _onUnhideClick,shouldShow: ownedFilesCount > 0,),@@ -487,18 +499,20 @@ class _FileSelectionActionsWidgetStateif (widget.type.showArchiveOption()) {items.add(- SelectionActionButton(- hugeIcon: HugeIcons.strokeRoundedArchive03,+ SelectionSheetAction(+ hugeIcon: HugeIcons.strokeRoundedInboxDownload,labelText: context.strings.archive,+ gridOrder: 6,onTap: anyUploadedFiles ? _onArchiveClick : null,shouldShow: ownedFilesCount > 0,),);} else if (widget.type.showUnArchiveOption()) {items.add(- SelectionActionButton(- hugeIcon: HugeIcons.strokeRoundedUnarchive03,+ SelectionSheetAction(+ hugeIcon: HugeIcons.strokeRoundedInboxUpload,labelText: context.strings.unarchive,+ gridOrder: 6,onTap: _onUnArchiveClick,shouldShow: ownedFilesCount > 0,),@@ -507,7 +521,7 @@ class _FileSelectionActionsWidgetStateif (widget.type.showRestoreOption()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedRestoreBin,labelText: context.strings.restore,onTap: _restore,@@ -517,7 +531,7 @@ class _FileSelectionActionsWidgetStateif (widget.type.showPermanentlyDeleteOption()) {items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedDelete01,labelText: context.strings.permanentlyDelete,onTap: _permanentlyDeleteFromTrash,@@ -528,12 +542,12 @@ class _FileSelectionActionsWidgetStateif (widget.type.showBulkEditTime()) {items.add(- SelectionActionButton(+ SelectionSheetAction(shouldShow: widget.selectedFiles.files.every((element) => (element.ownerID == currentUserID),),labelText: context.strings.editTime,- hugeIcon: HugeIcons.strokeRoundedDateTime,+ hugeIcon: HugeIcons.strokeRoundedClock01,onTap: () async {final newDate = await showEditDateSheet(context,@@ -549,19 +563,19 @@ class _FileSelectionActionsWidgetStateif (widget.type.showEditLocation()) {items.add(- SelectionActionButton(+ SelectionSheetAction(shouldShow: widget.selectedFiles.files.any((element) => (element.ownerID == currentUserID),),labelText: context.strings.editLocation,- hugeIcon: HugeIcons.strokeRoundedMapsEditing,+ hugeIcon: HugeIcons.strokeRoundedLocation01,onTap: _editLocation,),);}items.add(- SelectionActionButton(+ SelectionSheetAction(hugeIcon: HugeIcons.strokeRoundedIncognito,labelText: context.strings.guestView,onTap: _onGuestViewClick,@@ -569,40 +583,11 @@ class _FileSelectionActionsWidgetState);}- if (items.isNotEmpty) {- // h4ck: https://github.com/flutter/flutter/issues/57920#issuecomment-893970066- return MediaQuery(- data: MediaQuery.of(context).removePadding(removeBottom: true),- child: SafeArea(- top: false,- child: Scrollbar(- radius: const Radius.circular(1),- thickness: 2,- controller: _scrollController,- thumbVisibility: true,- child: SingleChildScrollView(- controller: _scrollController,- physics: const BouncingScrollPhysics(- decelerationRate: ScrollDecelerationRate.fast,- ),- scrollDirection: Axis.horizontal,- child: Container(- padding: const EdgeInsets.only(bottom: 24),- child: Row(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- const SizedBox(width: 4),- ...items,- const SizedBox(width: 4),- ],- ),- ),- ),- ),- ),- );- }- return const SizedBox();+ return SelectionActionSheet(+ actions: items,+ selectionControls: widget.selectionControls,+ backgroundColor: widget.backgroundColor,+ );}Future<void> _editLocation() async {diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_overlay_bar.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_overlay_bar.dartindex 8e218949ca..0d49a10e65 100644--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_overlay_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_overlay_bar.dart@@ -11,7 +11,8 @@ import "package:photos/models/search/hierarchical/face_filter.dart";import "package:photos/models/search/hierarchical/hierarchical_search_filter.dart";import "package:photos/models/search/hierarchical/only_them_filter.dart";import 'package:photos/models/selected_files.dart';-import 'package:photos/ui/components/bottom_action_bar/bottom_action_bar_widget.dart';+import "package:photos/ui/components/bottom_action_bar/action_bar_widget.dart";+import "package:photos/ui/viewer/actions/file_selection_actions_widget.dart";import "package:photos/ui/viewer/actions/select_all_status_icon.dart";import "package:photos/ui/viewer/gallery/state/boundary_reporter_mixin.dart";import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";@@ -20,7 +21,6 @@ import "package:photos/ui/viewer/gallery/state/search_filter_data_provider.dart"import "package:photos/ui/viewer/gallery/state/selection_state.dart";class FileSelectionOverlayBar extends StatefulWidget {- static double roughHeight = Platform.isIOS ? 240.0 : 232.0;final GalleryType galleryType;final SelectedFiles selectedFiles;final Collection? collection;@@ -50,7 +50,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar>SearchFilterDataProvider? _searchFilterDataProvider;bool? _galleryInitialFilterStillApplied;bool _wasEmpty = true;- static const Duration animationDuration = Duration(milliseconds: 400);+ static const Duration animationDuration = components.Motion.slow;@overridevoid initState() {@@ -134,40 +134,52 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar>valueListenable: _hasSelectedFilesNotifier,builder: (context, value, child) {return AnimatedCrossFade(- firstCurve: Curves.easeInOutExpo,- secondCurve: Curves.easeInOutExpo,- sizeCurve: Curves.easeInOutExpo,+ firstCurve: Curves.easeOutCubic,+ secondCurve: Curves.easeOutCubic,+ sizeCurve: Curves.easeOutCubic,crossFadeState: _hasSelectedFilesNotifier.value? CrossFadeState.showFirst: CrossFadeState.showSecond,- duration: _FileSelectionOverlayBarState.animationDuration,- firstChild: boundaryWidget(- position: BoundaryPosition.bottom,- child: Column(- mainAxisSize: MainAxisSize.min,- crossAxisAlignment: CrossAxisAlignment.end,- children: [- Padding(- padding: const EdgeInsets.only(right: 4),- child: SelectAllButton(- backgroundColor: widget.backgroundColor,+ duration: MediaQuery.disableAnimationsOf(context)+ ? Duration.zero+ : animationDuration,+ firstChild: NotificationListener<DraggableScrollableNotification>(+ onNotification: (_) {+ reportBoundary(BoundaryPosition.bottom);+ return true;+ },+ child: boundaryWidget(+ position: BoundaryPosition.bottom,+ child: FileSelectionActionsWidget(+ _galleryType,+ widget.selectedFiles,+ collection: widget.collection,+ person: widget.person,+ clusterID: widget.clusterID,+ selectionControls: SafeArea(+ top: false,+ bottom: false,+ child: Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: components.Spacing.sm,+ ),+ child: Row(+ mainAxisAlignment: MainAxisAlignment.spaceBetween,+ children: [+ const Flexible(child: SelectAllButton()),+ const SizedBox(width: components.Spacing.sm),+ Flexible(+ child: ActionBarWidget(+ selectedFiles: widget.selectedFiles,+ onCancel: widget.selectedFiles.clearAll,+ ),+ ),+ ],+ ),),),- const SizedBox(height: 8),- BottomActionBarWidget(- selectedFiles: widget.selectedFiles,- galleryType: _galleryType,- collection: widget.collection,- person: widget.person,- clusterID: widget.clusterID,- onCancel: () {- if (widget.selectedFiles.files.isNotEmpty) {- widget.selectedFiles.clearAll();- }- },- backgroundColor: widget.backgroundColor,- ),- ],+ backgroundColor: widget.backgroundColor,+ ),),),secondChild: const SizedBox(width: double.infinity),@@ -182,6 +194,7 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar>void _boundaryUpdateListener() {Future.delayed(_FileSelectionOverlayBarState.animationDuration, () {+ if (!mounted) return;final isEmpty = widget.selectedFiles.files.isEmpty;if (_wasEmpty != isEmpty) {@@ -236,80 +249,48 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar>}}-class SelectAllButton extends StatefulWidget {- final Color? backgroundColor;- const SelectAllButton({super.key, required this.backgroundColor});+class SelectAllButton extends StatelessWidget {+ const SelectAllButton({super.key});- @override- State<SelectAllButton> createState() => _SelectAllButtonState();-}--class _SelectAllButtonState extends State<SelectAllButton> {- bool _allSelected = false;@overrideWidget build(BuildContext context) {final selectionState = SelectionState.of(context);- final allGalleryFiles = GalleryFilesState.of(context).galleryFilesOrNull;- if (allGalleryFiles == null) {- return const SizedBox.shrink();- }- assert(- selectionState != null,- "SelectionState not found in context, SelectionState should be an ancestor of FileSelectionOverlayBar",- );- final colors = components.ComponentTheme.colorsOf(context);- return GestureDetector(- onTap: () {- HapticFeedback.selectionClick();- setState(() {- if (_allSelected) {- selectionState.selectedFiles.clearAll();- } else {- selectionState.selectedFiles.selectAll(allGalleryFiles.toSet());- }- _allSelected = !_allSelected;- });- },- child: Padding(- padding: const EdgeInsets.only(top: 8),- child: Container(- padding: const EdgeInsets.all(12),- decoration: BoxDecoration(- color: widget.backgroundColor ?? colors.backgroundBase,- border: Border.all(color: colors.strokeDark),- borderRadius: BorderRadius.circular(32),+ if (selectionState == null) return const SizedBox.shrink();+ return ListenableBuilder(+ listenable: selectionState.selectedFiles,+ builder: (context, _) {+ final allGalleryFiles = GalleryFilesState.of(+ context,+ ).galleryFilesOrNull;+ if (allGalleryFiles == null) return const SizedBox.shrink();+ final allSelected =+ allGalleryFiles.isNotEmpty &&+ allGalleryFiles.every(selectionState.selectedFiles.files.contains);+ return SelectionControlChip(+ label: context.strings.selectAllShort,+ semanticLabel: context.strings.selectAll,+ isSelected: allSelected,+ icon: SelectAllStatusIcon(+ isSelected: allSelected,+ size: components.IconSizes.small,+ unselectedColor: components.ComponentTheme.colorsOf(+ context,+ ).textLighter,),- child: Row(- mainAxisAlignment: MainAxisAlignment.end,- mainAxisSize: MainAxisSize.min,- children: [- Text(- context.strings.selectAllShort,- style: components.TextStyles.mini.copyWith(- color: colors.textBase,- ),- ),- const SizedBox(width: 4),- ListenableBuilder(- listenable: selectionState!.selectedFiles,- builder: (context, _) {- if (selectionState.selectedFiles.files.length ==- allGalleryFiles.length) {- _allSelected = true;+ onTap: allGalleryFiles.isEmpty+ ? null+ : () {+ HapticFeedback.selectionClick();+ if (allSelected) {+ selectionState.selectedFiles.clearAll();} else {- _allSelected = false;+ selectionState.selectedFiles.selectAll(+ allGalleryFiles.toSet(),+ );}- return SelectAllStatusIcon(- isSelected: _allSelected,- size: 16,- unselectedColor: colors.textLighter,- );},- ),- ],- ),- ),- ),+ );+ },);}}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dartindex 23a46d53bd..189b804940 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart@@ -24,7 +24,6 @@ import "package:photos/models/gallery_type.dart";import 'package:photos/models/selected_files.dart';import "package:photos/service_locator.dart" show localSettings;import "package:photos/settings/local_settings.dart" show GalleryLayoutType;-import "package:photos/ui/viewer/actions/file_selection_overlay_bar.dart";import "package:photos/ui/viewer/gallery/component/gallery_file_widget.dart";import "package:photos/ui/viewer/gallery/component/group/group_header_widget.dart";import "package:photos/ui/viewer/gallery/component/group/type.dart";@@ -368,7 +367,16 @@ class GalleryState extends State<Gallery> {void didChangeDependencies() {super.didChangeDependencies();_inheritedSearchFilterData = InheritedSearchFilterData.maybeOf(context);- _boundariesProvider = GalleryBoundariesProvider.of(context);+ final boundaries = GalleryBoundariesProvider.of(context);+ if (_boundariesProvider != boundaries) {+ _boundariesProvider?.bottomBoundaryNotifier.removeListener(+ _selectedFilesListener,+ );+ _boundariesProvider = boundaries;+ _boundariesProvider?.bottomBoundaryNotifier.addListener(+ _selectedFilesListener,+ );+ }}void _updateGalleryGroups({bool callSetState = true}) {@@ -487,10 +495,15 @@ class GalleryState extends State<Gallery> {void _selectedFilesListener() {final bottomInset = MediaQuery.paddingOf(context).bottom;final extra = widget.galleryType == GalleryType.homepage ? 76.0 : 0.0;- widget.selectedFiles?.files.isEmpty ?? true- ? scrollbarBottomPaddingNotifier.value = bottomInset + extra- : scrollbarBottomPaddingNotifier.value =- FileSelectionOverlayBar.roughHeight + bottomInset;+ final bottomBoundary = _boundariesProvider?.bottomBoundaryNotifier.value;+ scrollbarBottomPaddingNotifier.value =+ (widget.selectedFiles?.files.isNotEmpty ?? false) &&+ bottomBoundary != null+ ? (MediaQuery.sizeOf(context).height - bottomBoundary).clamp(+ 0.0,+ double.infinity,+ )+ : bottomInset + extra;}void _setGroupType() {@@ -728,6 +741,9 @@ class GalleryState extends State<Gallery> {@overridevoid dispose() {+ _boundariesProvider?.bottomBoundaryNotifier.removeListener(+ _selectedFilesListener,+ );_boundariesProvider?.setScrollController(null);_reloadEventSubscription?.cancel();@@ -1000,7 +1016,27 @@ class GalleryState extends State<Gallery> {SectionedListSliver(sectionLayouts: groups.groupLayouts,),- SliverToBoxAdapter(child: widget.footer),+ SliverToBoxAdapter(+ child: ValueListenableBuilder<double>(+ valueListenable:+ scrollbarBottomPaddingNotifier,+ builder: (context, height, child) =>+ ConstrainedBox(+ constraints: BoxConstraints(+ minHeight:+ (widget+ .selectedFiles+ ?.files+ .isNotEmpty ??+ false)+ ? height+ : 0,+ ),+ child: child,+ ),+ child: widget.footer,+ ),+ ),],),);diff --git a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dartindex e1c18c74b4..acd6b2350a 100644--- a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart+++ b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart@@ -31,6 +31,8 @@ import "package:photos/services/collections_service.dart";import "package:photos/services/favorites_service.dart";import "package:photos/services/ignored_files_service.dart";import "package:photos/ui/collections/album/row_item.dart";+import "package:photos/ui/components/bottom_action_bar/action_bar_widget.dart";+import "package:photos/ui/viewer/actions/file_selection_overlay_bar.dart";import "package:photos/ui/viewer/gallery/collection_page.dart";import "package:photos/ui/viewer/gallery/component/album_cover_app_bar.dart";import "package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart";@@ -188,10 +190,14 @@ void main() {.selectedFiles;expect(find.byType(AlbumCoverActionButton), findsNWidgets(2));selectedFiles.toggleSelection(newest);- await tester.pump();+ await tester.pumpAndSettle();expect(find.byType(AlbumCoverActionButton), findsNothing);- selectedFiles.toggleSelection(newest);- await tester.pump();+ await tester.tap(find.byType(SelectAllButton));+ await tester.pumpAndSettle();+ expect(selectedFiles.files, containsAll([oldest, newest]));+ await tester.tap(find.byType(ActionBarWidget));+ await tester.pumpAndSettle();+ expect(selectedFiles.files, isEmpty);expect(find.byType(AlbumCoverActionButton), findsNWidgets(2));collection.pubMagicMetadata = CollectionPubMagicMetadata(asc: true);diff --git a/mobile/apps/photos/test/ui/viewer/gallery/selection_action_sheet_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/selection_action_sheet_test.dartnew file mode 100644index 0000000000..cafa0feff6--- /dev/null+++ b/mobile/apps/photos/test/ui/viewer/gallery/selection_action_sheet_test.dart@@ -0,0 +1,300 @@+import "package:ente_strings/ente_strings.dart";+import "package:flutter/material.dart";+import "package:flutter_test/flutter_test.dart";+import "package:photos/ente_theme_data.dart";+import "package:photos/ui/components/bottom_action_bar/action_bar_widget.dart";+import "package:photos/ui/components/bottom_action_bar/selection_action_sheet.dart";+import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";+import "package:photos/utils/share_util.dart";++void main() {+ testWidgets("opens a preview, collapses on gallery scroll, and expands", (+ tester,+ ) async {+ final gallery = ScrollController();+ addTearDown(gallery.dispose);+ var tapped = "";+ await _pumpSheet(tester, gallery, onTap: (label) => tapped = label);+ final sheet = tester.widget<DraggableScrollableSheet>(+ find.byType(DraggableScrollableSheet),+ );+ final controller = sheet.controller!;+ expect(controller.size, sheet.initialChildSize);+ final previewHeight = tester+ .getSize(find.byType(DraggableScrollableSheet))+ .height;+ gallery.jumpTo(30);+ await tester.pumpAndSettle();+ expect(controller.size, sheet.initialChildSize);+ await tester.tapAt(const Offset(180, 660));+ expect(tapped, isEmpty);+ await tester.tap(find.text("Share"));+ expect(tapped, "Share");+ await tester.dragFrom(const Offset(180, 200), const Offset(0, -100));+ await tester.pumpAndSettle();+ expect(gallery.offset, greaterThan(0));+ expect(controller.size, sheet.minChildSize);+ expect(+ tester.getSize(find.byType(DraggableScrollableSheet)).height,+ lessThan(previewHeight),+ );+ await tester.drag(find.byType(CustomScrollView), const Offset(0, -320));+ await tester.pumpAndSettle();+ expect(controller.size, sheet.maxChildSize);+ await tester.tap(find.text("Guest view"));+ expect(tapped, "Guest view");+ final galleryOffset = gallery.offset;+ await tester.drag(find.byType(CustomScrollView), const Offset(0, 330));+ await tester.pumpAndSettle();+ expect(gallery.offset, galleryOffset);+ expect(controller.size, sheet.minChildSize);+ expect(tester.takeException(), isNull);+ });++ testWidgets("contains tablets, split view, and large text while resizing", (+ tester,+ ) async {+ final gallery = ScrollController();+ addTearDown(gallery.dispose);+ final shareKey = GlobalKey();+ DraggableScrollableController? controller;+ var tapped = "";+ for (final (size, padding, width) in [+ (const Size(740, 280), EdgeInsets.zero, 640.0),+ (+ const Size(1024, 1366),+ const EdgeInsets.only(top: 24, bottom: 20),+ 640.0,+ ),+ (const Size(1366, 1024), const EdgeInsets.all(24), 640.0),+ (+ const Size(320, 1024),+ const EdgeInsets.only(top: 24, bottom: 20),+ 320.0,+ ),+ ]) {+ await _pumpSheet(+ tester,+ gallery,+ size: size,+ padding: padding,+ textScale: 2,+ dark: true,+ shareKey: shareKey,+ onTap: (label) => tapped = label,+ );+ final sheet = tester.widget<DraggableScrollableSheet>(+ find.byType(DraggableScrollableSheet),+ );+ controller ??= sheet.controller;+ expect(sheet.controller, same(controller));+ sheet.controller!.jumpTo(sheet.maxChildSize);+ final scrollable = find.descendant(+ of: find.byType(CustomScrollView),+ matching: find.byType(Scrollable),+ );+ tester.state<ScrollableState>(scrollable).position.jumpTo(0);+ await tester.pumpAndSettle();+ final material = find.descendant(+ of: find.byType(SelectionActionSheet),+ matching: find.byType(Material),+ );+ final rect = tester.getRect(material);+ expect(rect.width, width);+ expect(rect.left, (size.width - width) / 2);+ expect(rect.bottom, size.height);+ expect(rect.top, greaterThanOrEqualTo(padding.top + kToolbarHeight));+ final origin = shareButtonRect(tester.element(material), shareKey);+ expect(origin.isEmpty, isFalse);+ expect(rect.contains(origin.center), isTrue);+ await tester.drag(find.byType(CustomScrollView), const Offset(0, -600));+ await tester.pumpAndSettle();+ await tester.tap(find.text("Guest view"));+ expect(tapped, "Guest view");+ expect(gallery.offset, 0);+ expect(tester.takeException(), isNull);+ }+ await tester.pumpWidget(const SizedBox.shrink());+ expect(tester.takeException(), isNull);+ });++ testWidgets("preserves hidden and disabled actions and reduced motion", (+ tester,+ ) async {+ final gallery = ScrollController();+ addTearDown(gallery.dispose);+ var tapped = "";+ await _pumpSheet(+ tester,+ gallery,+ reduceMotion: true,+ onTap: (label) => tapped = label,+ );+ expect(find.text("Hidden action"), findsNothing);+ await tester.tap(find.text("Send link"));+ expect(tapped, isEmpty);+ final sheet = tester.widget<DraggableScrollableSheet>(+ find.byType(DraggableScrollableSheet),+ );+ await tester.tap(find.bySemanticsLabel("More"));+ await tester.pump();+ expect(sheet.controller!.size, sheet.maxChildSize);+ final semantics = tester.ensureSemantics();+ expect(+ tester.getSemantics(find.text("Send link")),+ matchesSemantics(+ label: "Send link",+ isButton: true,+ hasEnabledState: true,+ ),+ );+ semantics.dispose();+ await _pumpSheet(+ tester,+ gallery,+ onTap: (label) => tapped = label,+ actions: [+ for (final label in ["Delete", "Reject suggestions"])+ SelectionSheetAction(+ labelText: label,+ iconWidget: const Icon(Icons.circle),+ onTap: () => tapped = label,+ ),+ ],+ );+ await tester.tap(find.text("Reject suggestions"));+ expect(tapped, "Reject suggestions");+ await tester.pumpWidget(+ MaterialApp(+ home: Scaffold(+ body: ListView(+ controller: gallery,+ children: const [SizedBox(height: 2000)],+ ),+ ),+ ),+ );+ gallery.jumpTo(10);+ await tester.pumpAndSettle();+ expect(tester.takeException(), isNull);+ });+}++Future<void> _pumpSheet(+ WidgetTester tester,+ ScrollController gallery, {+ Size size = const Size(375, 667),+ EdgeInsets padding = EdgeInsets.zero,+ double textScale = 1,+ bool reduceMotion = false,+ bool dark = false,+ List<SelectionSheetAction>? actions,+ GlobalKey? shareKey,+ required ValueChanged<String> onTap,+}) async {+ tester.view.physicalSize = size;+ tester.view.devicePixelRatio = 1;+ addTearDown(tester.view.reset);+ const labels = [+ "Share",+ "Send link",+ "Favourite",+ "Delete",+ "Add to album",+ "Hide",+ "Archive",+ "Download",+ "Add person",+ "Edit time",+ "Edit location",+ "Guest view",+ ];+ await tester.pumpWidget(+ MaterialApp(+ theme: dark ? darkThemeData : lightThemeData,+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: StringsLocalizations.supportedLocales,+ builder: (context, child) => MediaQuery(+ data: MediaQuery.of(context).copyWith(+ textScaler: TextScaler.linear(textScale),+ disableAnimations: reduceMotion,+ padding: padding,+ viewPadding: padding,+ ),+ child: child!,+ ),+ home: Scaffold(+ body: GalleryBoundariesProvider(+ child: Builder(+ builder: (context) {+ WidgetsBinding.instance.addPostFrameCallback(+ (_) => GalleryBoundariesProvider.of(+ context,+ )!.setScrollController(gallery),+ );+ return Stack(+ alignment: Alignment.bottomCenter,+ children: [+ ListView(+ controller: gallery,+ children: [+ Container(+ key: const ValueKey("gallery"),+ height: 2000,+ color: Colors.transparent,+ ),+ ],+ ),+ SelectionActionSheet(+ selectionControls: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 8),+ child: Row(+ mainAxisAlignment: MainAxisAlignment.spaceBetween,+ children: [+ for (final (label, semanticLabel, icon) in [+ ("All", "Select all", Icons.check_circle),+ ("3", "Cancel", Icons.close),+ ])+ Flexible(+ child: SelectionControlChip(+ label: label,+ semanticLabel: semanticLabel,+ icon: Icon(icon),+ onTap: () {},+ ),+ ),+ ],+ ),+ ),+ actions:+ actions ??+ [+ for (final (index, label) in labels.indexed)+ SelectionSheetAction(+ key: index == 0 ? shareKey : null,+ labelText: label,+ iconWidget: const Icon(Icons.circle),+ gridOrder: index < 8 ? index : null,+ isCritical: label == "Delete",+ onTap: label == "Send link"+ ? null+ : () => onTap(label),+ ),+ SelectionSheetAction(+ labelText: "Hidden action",+ iconWidget: const Icon(Icons.circle),+ shouldShow: false,+ onTap: () => onTap("Hidden action"),+ ),+ ],+ ),+ ],+ );+ },+ ),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();+}