Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Improve Add more sheet selection

r4khuldc798a684d17
diff --git a/mobile/apps/photos/changes/add-photos-sheet.md b/mobile/apps/photos/changes/add-photos-sheet.md
new file mode 100644
index 0000000000..3b8ee55f02
--- /dev/null
+++ b/mobile/apps/photos/changes/add-photos-sheet.md
@@ -0,0 +1 @@
+- Made the Add more sheet taller, added a selected photo count, and fixed scrolling while selecting photos.
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart
index 533db35f48..cbd13fa465 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart
@@ -16,6 +16,7 @@ import "package:photos/services/collections_service.dart";
import "package:photos/services/filter/db_filters.dart";
import "package:photos/ui/actions/collection/collection_file_actions.dart";
import "package:photos/ui/actions/collection/collection_sharing_actions.dart";
+import "package:photos/ui/components/bottom_action_bar/action_bar_widget.dart";
import "package:photos/ui/viewer/gallery/gallery.dart";
import "package:photos/ui/viewer/gallery/state/boundary_reporter_mixin.dart";
import "package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart";
@@ -30,11 +31,13 @@ Future<dynamic> showAddPhotosSheet(
return await showBottomSheetComponent<dynamic>(
context: context,
builder: (context) {
- return FractionallySizedBox(
- heightFactor: _sheetHeightFactor,
- alignment: Alignment.bottomCenter,
- child: GalleryBoundariesProvider(
- child: AddPhotosPhotoWidget(collection),
+ return LayoutBuilder(
+ builder: (context, _) => FractionallySizedBox(
+ heightFactor: _sheetHeightFactor,
+ alignment: Alignment.bottomCenter,
+ child: GalleryBoundariesProvider(
+ child: AddPhotosPhotoWidget(collection),
+ ),
),
);
},
@@ -42,23 +45,31 @@ Future<dynamic> showAddPhotosSheet(
);
}
-const double _sheetHeightFactor = 0.86;
+const double _sheetHeightFactor = 0.95;
-class AddPhotosPhotoWidget extends StatelessWidget {
+class AddPhotosPhotoWidget extends StatefulWidget {
final Collection collection;
const AddPhotosPhotoWidget(this.collection, {super.key});
+ @override
+ State<AddPhotosPhotoWidget> createState() => _AddPhotosPhotoWidgetState();
+}
+
+class _AddPhotosPhotoWidgetState extends State<AddPhotosPhotoWidget> {
+ final _selectedFiles = SelectedFiles();
+
+ @override
+ void dispose() {
+ _selectedFiles.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
- final ValueNotifier<bool> isFileSelected = ValueNotifier(false);
- final selectedFiles = SelectedFiles();
- selectedFiles.addListener(() {
- isFileSelected.value = selectedFiles.files.isNotEmpty;
- });
final Set<int> hiddenCollectionIDs = CollectionsService.instance
.getHiddenCollectionIds();
- hiddenCollectionIDs.add(collection.id);
+ hiddenCollectionIDs.add(widget.collection.id);
return Container(
clipBehavior: Clip.antiAlias,
@@ -75,7 +86,8 @@ class AddPhotosPhotoWidget extends StatelessWidget {
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
- _AppBarWithBoundary(
+ _SheetBoundary(
+ position: BoundaryPosition.top,
child: Padding(
padding: const EdgeInsets.fromLTRB(
Spacing.xl,
@@ -112,65 +124,91 @@ class AddPhotosPhotoWidget extends StatelessWidget {
),
const SizedBox(height: Spacing.lg),
Expanded(
- child: DelayedGallery(
- hiddenCollectionIDs: hiddenCollectionIDs,
- selectedFiles: selectedFiles,
+ child: Stack(
+ fit: StackFit.expand,
+ children: [
+ DelayedGallery(
+ hiddenCollectionIDs: hiddenCollectionIDs,
+ selectedFiles: _selectedFiles,
+ ),
+ PositionedDirectional(
+ start: Spacing.lg,
+ end: Spacing.lg,
+ bottom: Spacing.md,
+ child: Align(
+ alignment: AlignmentDirectional.centerEnd,
+ child: ListenableBuilder(
+ listenable: _selectedFiles,
+ builder: (context, _) => _selectedFiles.files.isEmpty
+ ? const SizedBox.shrink()
+ : ActionBarWidget(
+ selectedFiles: _selectedFiles,
+ onCancel: () => _selectedFiles.clearAll(),
+ ),
+ ),
+ ),
+ ),
+ ],
),
),
- Center(
- child: ConstrainedBox(
- constraints: const BoxConstraints(maxWidth: 428),
- child: Padding(
- padding: const EdgeInsets.fromLTRB(
- Spacing.xl,
- Spacing.lg,
- Spacing.xl,
- Spacing.sm,
- ),
- child: Column(
- children: [
- ValueListenableBuilder(
- valueListenable: isFileSelected,
- builder: (context, bool value, _) {
- return AnimatedSwitcher(
- duration: const Duration(milliseconds: 300),
- switchInCurve: Curves.easeInOutExpo,
- switchOutCurve: Curves.easeInOutExpo,
- child: ButtonComponent(
- key: ValueKey(value),
- variant: ButtonComponentVariant.primary,
- isDisabled: !value,
- label: context.strings.addSelected,
+ ListenableBuilder(
+ listenable: _selectedFiles,
+ builder: (context, _) {
+ final isFileSelected = _selectedFiles.files.isNotEmpty;
+ return _SheetBoundary(
+ position: BoundaryPosition.bottom,
+ child: Center(
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 428),
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(
+ Spacing.xl,
+ Spacing.lg,
+ Spacing.xl,
+ Spacing.sm,
+ ),
+ child: Column(
+ children: [
+ AnimatedSwitcher(
+ duration: const Duration(milliseconds: 300),
+ switchInCurve: Curves.easeInOutExpo,
+ switchOutCurve: Curves.easeInOutExpo,
+ child: ButtonComponent(
+ key: ValueKey(isFileSelected),
+ variant: ButtonComponentVariant.primary,
+ isDisabled: !isFileSelected,
+ label: context.strings.addSelected,
+ onTap: () async {
+ final selectedFile = _selectedFiles.files;
+ final ca = CollectionActions(
+ CollectionsService.instance,
+ );
+ await ca.addToCollection(
+ context,
+ widget.collection.id,
+ false,
+ selectedFiles: selectedFile.toList(),
+ );
+ if (!context.mounted) return;
+ Navigator.pop(context, selectedFile);
+ },
+ ),
+ ),
+ const SizedBox(height: Spacing.md),
+ ButtonComponent(
+ variant: ButtonComponentVariant.secondary,
+ label: context.strings.addFromDevice,
onTap: () async {
- final selectedFile = selectedFiles.files;
- final ca = CollectionActions(
- CollectionsService.instance,
- );
- await ca.addToCollection(
- context,
- collection.id,
- false,
- selectedFiles: selectedFile.toList(),
- );
- if (!context.mounted) return;
- Navigator.pop(context, selectedFile);
+ await _onPickFromDeviceClicked(context);
},
),
- );
- },
- ),
- const SizedBox(height: Spacing.md),
- ButtonComponent(
- variant: ButtonComponentVariant.secondary,
- label: context.strings.addFromDevice,
- onTap: () async {
- await _onPickFromDeviceClicked(context);
- },
+ ],
+ ),
),
- ],
+ ),
),
- ),
- ),
+ );
+ },
),
],
),
@@ -197,7 +235,7 @@ class AddPhotosPhotoWidget extends StatelessWidget {
if (!context.mounted) return;
await ca.addToCollection(
context,
- collection.id,
+ widget.collection.id,
false,
picketAssets: result,
);
@@ -318,6 +356,14 @@ class _DelayedGalleryState extends State<DelayedGallery> {
},
tagPrefix: "pick_add_photos_gallery",
selectedFiles: widget.selectedFiles,
+ footer: ListenableBuilder(
+ listenable: widget.selectedFiles,
+ builder: (context, _) => SizedBox(
+ height: widget.selectedFiles.files.isEmpty
+ ? 0
+ : MediaQuery.textScalerOf(context).scale(kToolbarHeight),
+ ),
+ ),
showSelectAll: true,
sortAsyncFn: () => false,
disablePinnedGroupHeader: true,
@@ -333,19 +379,24 @@ class _DelayedGalleryState extends State<DelayedGallery> {
}
}
-class _AppBarWithBoundary extends StatefulWidget {
+class _SheetBoundary extends StatefulWidget {
+ final BoundaryPosition position;
final Widget child;
- const _AppBarWithBoundary({required this.child});
+ const _SheetBoundary({required this.position, required this.child});
@override
- State<_AppBarWithBoundary> createState() => _AppBarWithBoundaryState();
+ State<_SheetBoundary> createState() => _SheetBoundaryState();
}
-class _AppBarWithBoundaryState extends State<_AppBarWithBoundary>
- with BoundaryReporter {
+class _SheetBoundaryState extends State<_SheetBoundary> with BoundaryReporter {
@override
Widget build(BuildContext context) {
- return boundaryWidget(position: BoundaryPosition.top, child: widget.child);
+ return AnimatedBuilder(
+ animation: ModalRoute.of(context)?.animation ?? kAlwaysCompleteAnimation,
+ builder: (context, child) =>
+ boundaryWidget(position: widget.position, child: child!),
+ child: widget.child,
+ );
}
}