Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Refine album menu spacing and responsive dismissal

r4khul0335a041d024
diff --git a/mobile/apps/photos/changes/album-actions-sheet.md b/mobile/apps/photos/changes/album-actions-sheet.md
new file mode 100644
index 0000000000..e26b5d5a30
--- /dev/null
+++ b/mobile/apps/photos/changes/album-actions-sheet.md
@@ -0,0 +1 @@
+- Made album options more compact with layouts that fit landscape and tablets.
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart
index 61ffc1a03c..377f872c6b 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart
@@ -1,4 +1,7 @@
+import "dart:math" as math;
+
import "package:ente_components/ente_components.dart";
+import "package:flutter/gestures.dart";
import "package:flutter/material.dart";
Future<T?> showAlbumActionsSheet<T>(
@@ -8,42 +11,45 @@ Future<T?> showAlbumActionsSheet<T>(
final criticalIndex = options.indexWhere(
(option) => option.labelColor != null,
);
- final tiles = [
- ...options
- .where((option) => option.labelColor == null)
- .take(criticalIndex == -1 ? _tilesPerShelf : _tilesPerShelf - 1),
- if (criticalIndex != -1) options[criticalIndex],
- ];
- final rows = options.where((option) => !tiles.contains(option)).toList();
-
- return showBottomSheetComponent<T>(
- context: context,
- barrierColor: context.componentColors.specialScrim.withValues(alpha: 0.4),
- builder: (context) {
- final colors = context.componentColors;
- return DecoratedBox(
- decoration: const BoxDecoration(
- borderRadius: BorderRadius.vertical(
- top: Radius.circular(Radii.bottomSheet),
- ),
- boxShadow: [
- BoxShadow(
- color: Color.from(alpha: 0.18, red: 0, green: 0, blue: 0),
- offset: Offset(0, -2),
- blurRadius: 80,
- ),
- ],
+ final platform = Theme.of(context).platform;
+ final isMobile =
+ platform == TargetPlatform.android || platform == TargetPlatform.iOS;
+ Widget builder(BuildContext context) {
+ final colors = context.componentColors;
+ final media = MediaQuery.of(context);
+ final isLandscape = media.orientation == Orientation.landscape;
+ return BottomSheetComponent(
+ showCloseButton: false,
+ backgroundColor: colors.fillLight,
+ padding: EdgeInsets.only(
+ top: isLandscape ? Spacing.md : Spacing.lg,
+ bottom: isLandscape ? Spacing.xs : Spacing.sm,
+ ),
+ content: ConstrainedBox(
+ constraints: BoxConstraints(
+ maxHeight: media.size.height * _maxHeightFraction,
),
- child: BottomSheetComponent(
- showCloseButton: false,
- backgroundColor: colors.fillLight,
- padding: const EdgeInsets.only(top: Spacing.lg, bottom: Spacing.sm),
- content: ConstrainedBox(
- constraints: BoxConstraints(
- maxHeight: MediaQuery.sizeOf(context).height * _maxHeightFraction,
- ),
- child: SingleChildScrollView(
- child: Column(
+ child: SingleChildScrollView(
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ final gridWidth = constraints.maxWidth - Spacing.md * 2;
+ final minTileWidth =
+ 64 *
+ media.textScaler.scale(TextStyles.mini.fontSize!) /
+ TextStyles.mini.fontSize!;
+ final columns = gridWidth >= minTileWidth * 4 + Spacing.xs * 3
+ ? 4
+ : 2;
+ final tiles = [
+ ...options
+ .where((option) => option.labelColor == null)
+ .take(criticalIndex == -1 ? columns : columns - 1),
+ if (criticalIndex != -1) options[criticalIndex],
+ ];
+ final rows = options
+ .where((option) => !tiles.contains(option))
+ .toList();
+ return Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
@@ -54,7 +60,7 @@ Future<T?> showAlbumActionsSheet<T>(
borderRadius: BorderRadius.circular(3),
),
),
- const SizedBox(height: Spacing.xxl),
+ SizedBox(height: isLandscape ? Spacing.sm : Spacing.md),
Padding(
padding: const EdgeInsets.symmetric(horizontal: Spacing.md),
child: Row(
@@ -73,12 +79,10 @@ Future<T?> showAlbumActionsSheet<T>(
),
),
if (rows.isNotEmpty)
- const DividerComponent(
- padding: EdgeInsets.fromLTRB(
- Spacing.lg,
- Spacing.lg,
- Spacing.lg,
- Spacing.xl,
+ DividerComponent(
+ padding: EdgeInsets.symmetric(
+ horizontal: Spacing.lg,
+ vertical: isLandscape ? Spacing.sm : Spacing.lg,
),
),
for (final option in rows)
@@ -86,15 +90,141 @@ Future<T?> showAlbumActionsSheet<T>(
option: option,
onTap: () => Navigator.of(context).pop(option.value),
),
- const SizedBox(height: Spacing.lg),
+ const SizedBox(height: Spacing.sm),
],
+ );
+ },
+ ),
+ ),
+ ),
+ );
+ }
+
+ if (!isMobile) {
+ return showBottomSheetComponent<T>(
+ context: context,
+ barrierColor: context.componentColors.specialScrim.withValues(alpha: 0.4),
+ builder: builder,
+ );
+ }
+ return Navigator.of(
+ context,
+ ).push(_AlbumActionsSheetRoute<T>(context, builder: builder));
+}
+
+class _AlbumActionsSheetRoute<T> extends ModalBottomSheetRoute<T> {
+ _AlbumActionsSheetRoute(BuildContext context, {required super.builder})
+ : _capturedThemes = InheritedTheme.capture(
+ from: context,
+ to: Navigator.of(context).context,
+ ),
+ super(
+ isScrollControlled: true,
+ useSafeArea: true,
+ backgroundColor: Colors.transparent,
+ modalBarrierColor: context.componentColors.specialScrim.withValues(
+ alpha: 0.4,
+ ),
+ barrierLabel: MaterialLocalizations.of(context).scrimLabel,
+ barrierOnTapHint: MaterialLocalizations.of(
+ context,
+ ).scrimOnTapHint(MaterialLocalizations.of(context).bottomSheetLabel),
+ );
+
+ final CapturedThemes _capturedThemes;
+ final _pointerOrigins = <int, Offset>{};
+ int? _dismissPointer;
+
+ @override
+ Widget buildPage(
+ BuildContext context,
+ Animation<double> animation,
+ Animation<double> secondaryAnimation,
+ ) {
+ return _capturedThemes.wrap(
+ DisplayFeatureSubScreen(
+ anchorPoint: anchorPoint,
+ child: Builder(
+ builder: (context) {
+ final media = MediaQuery.of(context);
+ final theme = Theme.of(context);
+ final availableWidth =
+ media.size.width -
+ media.padding.horizontal -
+ (media.orientation == Orientation.landscape
+ ? Spacing.lg * 2
+ : 0);
+ final width = math.min(640.0, availableWidth);
+ return Theme(
+ data: theme.copyWith(
+ bottomSheetTheme: theme.bottomSheetTheme.copyWith(
+ constraints: BoxConstraints.tightFor(width: width),
+ ),
),
+ child: super.buildPage(context, animation, secondaryAnimation),
+ );
+ },
+ ),
+ ),
+ );
+ }
+
+ void _dismiss() {
+ if (isCurrent) navigator!.pop();
+ }
+
+ void _endPointer(PointerEvent event) {
+ _pointerOrigins.remove(event.pointer);
+ if (event.pointer == _dismissPointer && isActive) {
+ if (isCurrent) {
+ navigator!.pop();
+ } else {
+ controller!.stop();
+ navigator!.removeRoute(this);
+ }
+ }
+ }
+
+ @override
+ Widget buildModalBarrier() {
+ final gestureSettings = MediaQuery.gestureSettingsOf(navigator!.context);
+ return BlockSemantics(
+ child: Semantics(
+ label: barrierLabel,
+ onTapHint: barrierOnTapHint,
+ onTap: _dismiss,
+ onDismiss: _dismiss,
+ child: Listener(
+ behavior: HitTestBehavior.translucent,
+ onPointerDown: (event) =>
+ _pointerOrigins[event.pointer] = event.position,
+ onPointerMove: (event) {
+ final origin = _pointerOrigins[event.pointer];
+ if (origin == null || !isCurrent || _dismissPointer != null) return;
+ final delta = event.position - origin;
+ if (delta.distance > computeHitSlop(event.kind, gestureSettings)) {
+ _dismissPointer = event.pointer;
+ controller!.reverse();
+ }
+ },
+ onPointerUp: _endPointer,
+ onPointerCancel: _endPointer,
+ onPointerSignal: (event) {
+ if (event is PointerScrollEvent) _dismiss();
+ },
+ child: GestureDetector(
+ behavior: HitTestBehavior.translucent,
+ onTap: _dismiss,
+ onLongPress: _dismiss,
+ excludeFromSemantics: true,
+ child: ExcludeSemantics(
+ child: IgnorePointer(child: super.buildModalBarrier()),
),
),
),
- );
- },
- );
+ ),
+ );
+ }
}
class _AlbumActionTile<T> extends StatelessWidget {
@@ -113,14 +243,12 @@ class _AlbumActionTile<T> extends StatelessWidget {
onTap: onTap,
borderRadius: BorderRadius.circular(Radii.md),
child: ConstrainedBox(
- constraints: BoxConstraints(
- minHeight: option.labelColor == null ? 0 : 64,
- ),
+ constraints: const BoxConstraints(minHeight: 64),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: Spacing.xs),
child: Column(
mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.center,
+ mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox.square(
dimension: 34,
@@ -137,6 +265,8 @@ class _AlbumActionTile<T> extends StatelessWidget {
const SizedBox(height: Spacing.xs),
Text(
option.label,
+ maxLines: 2,
+ overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
style: TextStyles.mini.copyWith(color: foreground),
),
@@ -202,5 +332,4 @@ class _AlbumActionRow<T> extends StatelessWidget {
}
}
-const _tilesPerShelf = 4;
const _maxHeightFraction = 0.8;
diff --git a/mobile/apps/photos/test/ui/viewer/gallery/album_actions_sheet_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/album_actions_sheet_test.dart
index b360257a54..170b2164d8 100644
--- a/mobile/apps/photos/test/ui/viewer/gallery/album_actions_sheet_test.dart
+++ b/mobile/apps/photos/test/ui/viewer/gallery/album_actions_sheet_test.dart
@@ -1,5 +1,8 @@
+import "dart:ui" show SemanticsAction, SemanticsActionEvent;
+
import "package:ente_components/ente_components.dart";
import "package:ente_strings/ente_strings.dart";
+import "package:flutter/gestures.dart" show PointerScrollEvent;
import "package:flutter/material.dart";
import "package:flutter_test/flutter_test.dart";
import "package:photos/ente_theme_data.dart";
@@ -10,10 +13,15 @@ void main() {
testWidgets("keeps the destructive tile last and returns its value", (
tester,
) async {
+ tester.view.physicalSize = const Size(375, 667);
+ tester.view.devicePixelRatio = 1;
+ addTearDown(tester.view.reset);
String? result;
await _pumpLauncher(tester, (value) => result = value);
+ final albumScroll = tester
+ .state<ScrollableState>(find.byType(Scrollable))
+ .position;
await _openLauncher(tester);
-
final tilePositions = [
"Edit",
"Pin",
@@ -37,30 +45,212 @@ void main() {
expect(result, "delete");
expect(find.byType(BottomSheetComponent), findsNothing);
- });
-
- testWidgets("scrolls instead of overflowing on short screens", (
- tester,
- ) async {
- tester.view.physicalSize = const Size(667, 240);
- tester.view.devicePixelRatio = 1;
- addTearDown(tester.view.reset);
- String? result;
- await _pumpLauncher(tester, (value) => result = value);
+ result = "pending";
await _openLauncher(tester);
-
- await tester.dragUntilVisible(
- find.text("Cast"),
- find.byType(SingleChildScrollView),
- const Offset(0, -50),
+ await tester.tapAt(const Offset(200, 150));
+ await tester.pumpAndSettle();
+ expect(result, isNull);
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ result = "pending";
+ await _openLauncher(tester);
+ await tester.longPressAt(const Offset(200, 150));
+ await tester.pumpAndSettle();
+ expect(result, isNull);
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ result = "pending";
+ await _openLauncher(tester);
+ final drag = await tester.startGesture(const Offset(200, 150));
+ await drag.moveBy(const Offset(0, -24));
+ await drag.moveBy(const Offset(0, -40));
+ await tester.pumpAndSettle();
+ expect(
+ tester.getTopLeft(find.byType(BottomSheetComponent)).dy,
+ greaterThanOrEqualTo(667),
);
- await tester.tap(find.text("Cast"));
+ final offset = albumScroll.pixels;
+ expect(offset, greaterThan(0));
+ await drag.moveBy(const Offset(0, -40));
+ await tester.pump();
+ expect(albumScroll.pixels, greaterThan(offset));
+ await drag.up();
await tester.pumpAndSettle();
-
- expect(tester.takeException(), isNull);
- expect(result, "cast");
+ expect(result, isNull);
expect(find.byType(BottomSheetComponent), findsNothing);
});
+
+ testWidgets(
+ "keeps landscape actions aligned and reachable on short screens",
+ (tester) async {
+ tester.view.physicalSize = const Size(667, 240);
+ tester.view.devicePixelRatio = 1;
+ addTearDown(tester.view.reset);
+ String? result;
+ await _pumpLauncher(
+ tester,
+ (value) => result = value,
+ platform: TargetPlatform.iOS,
+ );
+ final albumScroll = tester
+ .state<ScrollableState>(find.byType(Scrollable))
+ .position;
+ await _openLauncher(tester);
+ expect(find.byType(DividerComponent), findsOneWidget);
+ expect(find.byType(VerticalDivider), findsNothing);
+ final firstRow = [
+ "Edit",
+ "Pin",
+ "Archive",
+ "Delete",
+ ].map((label) => tester.getTopLeft(find.text(label)).dy);
+ expect(
+ firstRow.every((top) => (top - firstRow.first).abs() < 1),
+ isTrue,
+ );
+ expect(
+ tester.getTopLeft(find.text("Hide")).dy,
+ greaterThan(firstRow.first),
+ );
+ final sheet = tester.getRect(find.byType(BottomSheetComponent));
+ expect(sheet.left, greaterThanOrEqualTo(Spacing.lg));
+ expect(sheet.right, lessThanOrEqualTo(667 - Spacing.lg));
+ expect(sheet.bottom, 240);
+ final scrollable = tester.state<ScrollableState>(
+ find.descendant(
+ of: find.byType(SingleChildScrollView),
+ matching: find.byType(Scrollable),
+ ),
+ );
+ expect(scrollable.position.maxScrollExtent, greaterThan(0));
+ tester.view.physicalSize = const Size(375, 667);
+ await tester.pumpAndSettle();
+ expect(find.byType(DividerComponent), findsOneWidget);
+ expect(tester.getSize(find.byType(BottomSheetComponent)).width, 375);
+ tester.view.physicalSize = const Size(667, 240);
+ await tester.pumpAndSettle();
+ expect(find.byType(DividerComponent), findsOneWidget);
+ await tester.ensureVisible(find.text("Cast"));
+ await tester.pumpAndSettle();
+ await tester.tap(find.text("Cast"));
+ await tester.pumpAndSettle();
+
+ expect(tester.takeException(), isNull);
+ expect(result, "cast");
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ result = "pending";
+ await _openLauncher(tester);
+ await tester.tapAt(Offset(sheet.left / 2, sheet.center.dy));
+ await tester.pumpAndSettle();
+ expect(result, isNull);
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ final semantics = tester.ensureSemantics();
+ result = "pending";
+ await _openLauncher(tester);
+ final barrierLabel = MaterialLocalizations.of(
+ tester.element(find.byType(BottomSheetComponent)),
+ ).scrimLabel;
+ tester.binding.platformDispatcher.onSemanticsActionEvent!(
+ SemanticsActionEvent(
+ type: SemanticsAction.tap,
+ nodeId: tester.getSemantics(find.bySemanticsLabel(barrierLabel)).id,
+ viewId: tester.view.viewId,
+ ),
+ );
+ await tester.pumpAndSettle();
+ expect(result, isNull);
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ semantics.dispose();
+ result = "pending";
+ await _openLauncher(tester);
+ final drag = await tester.startGesture(
+ Offset(sheet.left / 2, sheet.center.dy),
+ );
+ await drag.moveBy(const Offset(0, -24));
+ await drag.moveBy(const Offset(0, -40));
+ await drag.up();
+ await tester.pumpAndSettle();
+ expect(result, isNull);
+ expect(albumScroll.pixels, greaterThan(0));
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ albumScroll.jumpTo(0);
+ await tester.pumpAndSettle();
+ result = "pending";
+ await _openLauncher(tester);
+ final cancelledDrag = await tester.startGesture(
+ Offset(sheet.left / 2, sheet.center.dy),
+ );
+ await cancelledDrag.moveBy(const Offset(0, -24));
+ await tester.pump();
+ await cancelledDrag.cancel();
+ await tester.pumpAndSettle();
+ expect(result, isNull);
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ result = "pending";
+ await _openLauncher(tester);
+ final interruptedDrag = await tester.startGesture(
+ Offset(sheet.left / 2, sheet.center.dy),
+ );
+ await interruptedDrag.moveBy(const Offset(0, -24));
+ await tester.pump();
+ final navigator = tester.state<NavigatorState>(find.byType(Navigator));
+ navigator.push(
+ MaterialPageRoute<void>(
+ builder: (_) => const Scaffold(body: Text("Next page")),
+ ),
+ );
+ await tester.pumpAndSettle();
+ expect(result, isNull);
+ navigator.pop();
+ await tester.pumpAndSettle();
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ await interruptedDrag.up();
+ result = "pending";
+ await _openLauncher(tester);
+ await tester.sendEventToBinding(
+ PointerScrollEvent(
+ position: Offset(sheet.left / 2, sheet.center.dy),
+ scrollDelta: const Offset(0, 60),
+ ),
+ );
+ await tester.pumpAndSettle();
+ expect(result, isNull);
+ expect(albumScroll.pixels, greaterThan(0));
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ albumScroll.jumpTo(0);
+ tester.view.physicalSize = const Size(740, 280);
+ tester.platformDispatcher.textScaleFactorTestValue = 2;
+ addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
+ await tester.pumpAndSettle();
+ await _openLauncher(tester);
+ expect(tester.getSize(find.byType(BottomSheetComponent)).width, 640);
+ await tester.drag(
+ find.byType(SingleChildScrollView),
+ const Offset(0, -200),
+ );
+ await tester.pumpAndSettle();
+ await tester.tap(find.text("Add photos"));
+ await tester.pumpAndSettle();
+ expect(result, "add photos");
+ expect(tester.takeException(), isNull);
+ await _openLauncher(tester);
+ for (final (size, width) in [
+ (const Size(1024, 1366), 640.0),
+ (const Size(1366, 1024), 640.0),
+ (const Size(320, 1024), 320.0),
+ ]) {
+ tester.view.physicalSize = size;
+ await tester.pumpAndSettle();
+ final resizedSheet = tester.getRect(
+ find.byType(BottomSheetComponent),
+ );
+ expect(resizedSheet.width, width);
+ expect(resizedSheet.bottom, size.height);
+ expect(tester.takeException(), isNull);
+ }
+ await tester.tap(find.text("Add photos"));
+ await tester.pumpAndSettle();
+ expect(result, "add photos");
+ },
+ );
});
}
@@ -80,29 +270,43 @@ List<EntePopupMenuOption<String>> _options(BuildContext context) {
option("Archive"),
option("Hide"),
option("Cast"),
+ option("Download"),
+ option("Guest view"),
+ option("Add photos"),
option("Delete", labelColor: context.componentColors.warning),
];
}
Future<void> _pumpLauncher(
WidgetTester tester,
- ValueChanged<String?> onResult,
-) async {
+ ValueChanged<String?> onResult, {
+ TargetPlatform platform = TargetPlatform.android,
+}) async {
await tester.pumpWidget(
MaterialApp(
- theme: lightThemeData,
+ theme: lightThemeData.copyWith(platform: platform),
localizationsDelegates: StringsLocalizations.localizationsDelegates,
supportedLocales: StringsLocalizations.supportedLocales,
home: Scaffold(
body: Builder(
builder: (context) {
- return TextButton(
- onPressed: () async {
- onResult(
- await showAlbumActionsSheet(context, _options(context)),
- );
- },
- child: const Text("Open sheet"),
+ return ListView(
+ children: [
+ TextButton(
+ onPressed: () async {
+ onResult(
+ await showAlbumActionsSheet(context, _options(context)),
+ );
+ },
+ child: const Text("Open sheet"),
+ ),
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => fail("A covered album action ran"),
+ onLongPress: () => fail("A covered album action ran"),
+ child: const SizedBox(height: 2000),
+ ),
+ ],
);
},
),