π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Expand back-button tap targets without changing layout
ashil-pilota67870907cc3
diff --git a/mobile/packages/ente_components/lib/components/app_bar_component.dart b/mobile/packages/ente_components/lib/components/app_bar_component.dartindex 61cd031c05..0f3e181011 100644--- a/mobile/packages/ente_components/lib/components/app_bar_component.dart+++ b/mobile/packages/ente_components/lib/components/app_bar_component.dart@@ -547,6 +547,20 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {child: Stack(fit: StackFit.expand,children: [+ if (showExpandedBackButton && backButton == null)+ Positioned(+ top: 0,+ left: 0,+ // Include the header gutter in the touch target without moving+ // the icon or title. Keep this behind the moving content so+ // title and leading gestures win where they overlap it.+ child: _HeaderAppBarBackButton(+ onBack: onBack,+ width: horizontalPadding + collapsedTitleLeft,+ height: collapsedHeight,+ leftPadding: horizontalPadding,+ ),+ ),Positioned.fill(bottom: bottomHeight + visibleCollapsibleBottomHeight,child: Padding(@@ -620,7 +634,6 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {bottom: 0,child: _PinnedHeaderChrome(backButton: backButton,- onBack: onBack,actions: actions,actionsTop: actionsTop,chromeHeight: collapsedHeight,@@ -703,7 +716,6 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {class _PinnedHeaderChrome extends StatelessWidget {const _PinnedHeaderChrome({required this.backButton,- required this.onBack,required this.actions,required this.actionsTop,required this.chromeHeight,@@ -711,7 +723,6 @@ class _PinnedHeaderChrome extends StatelessWidget {});final Widget? backButton;- final VoidCallback? onBack;final List<Widget> actions;final double actionsTop;final double chromeHeight;@@ -722,16 +733,21 @@ class _PinnedHeaderChrome extends StatelessWidget {return Stack(fit: StackFit.expand,children: [- if (showBackButton)+ if (showBackButton && backButton != null)Align(alignment: Alignment.topLeft,child: Row(mainAxisSize: MainAxisSize.min,children: [- _HeaderAppBarBackButton(- backButton: backButton,- onBack: onBack,+ SizedBox(+ width: _headerControlSize,height: chromeHeight,+ child: Center(+ child: SizedBox.square(+ dimension: _headerControlSize,+ child: Center(child: backButton),+ ),+ ),),const SizedBox(width: Spacing.md),],@@ -769,14 +785,16 @@ class _PinnedHeaderChrome extends StatelessWidget {class _HeaderAppBarBackButton extends StatelessWidget {const _HeaderAppBarBackButton({- required this.backButton,required this.onBack,+ required this.width,required this.height,+ required this.leftPadding,});- final Widget? backButton;final VoidCallback? onBack;+ final double width;final double height;+ final double leftPadding;@overrideWidget build(BuildContext context) {@@ -784,31 +802,26 @@ class _HeaderAppBarBackButton extends StatelessWidget {final tooltip = MaterialLocalizations.of(context).backButtonTooltip;return SizedBox(- width: backButton == null ? _defaultBackIconSize : _headerControlSize,+ width: width,height: height,- child: Align(- alignment: Alignment.centerLeft,- child: backButton == null- ? Semantics(- button: true,- label: tooltip,- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: onBack ?? () => Navigator.maybePop(context),- child: SizedBox.square(- dimension: _defaultBackIconSize,- child: Icon(- Icons.arrow_back,- color: colors.textBase,- size: _defaultBackIconSize,- ),- ),- ),- )- : SizedBox.square(- dimension: _headerControlSize,- child: Center(child: backButton),+ child: Semantics(+ button: true,+ label: tooltip,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: onBack ?? () => Navigator.maybePop(context),+ child: Padding(+ padding: EdgeInsets.only(left: leftPadding),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Icon(+ Icons.arrow_back,+ color: colors.textBase,+ size: _defaultBackIconSize,),+ ),+ ),+ ),),);}diff --git a/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart b/mobile/packages/ente_components/test/components/app_surface_widgets_test.dartindex 8a9bc24d79..571eac166e 100644--- a/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart+++ b/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart@@ -234,6 +234,206 @@ void main() {expect(find.text('Menu items'), findsWidgets);});+ testWidgets(+ 'header back target includes surrounding space without stealing title taps',+ (tester) async {+ final semantics = tester.ensureSemantics();+ final controller = ScrollController();+ addTearDown(controller.dispose);+ var backTaps = 0;+ var titleTaps = 0;+ var actionTaps = 0;++ await pumpComponent(+ tester,+ CustomScrollView(+ controller: controller,+ slivers: [+ SliverAppBarComponent(+ title: 'A long album title that should stay constrained',+ onBack: () => backTaps++,+ onTitleTap: () => titleTaps++,+ actions: [+ IconButton(+ icon: const Icon(Icons.more_vert),+ onPressed: () => actionTaps++,+ ),+ ],+ ),+ const SliverToBoxAdapter(child: SizedBox(height: 1000)),+ ],+ ),+ width: 320,+ height: 600,+ );++ final title = find.text(+ 'A long album title that should stay constrained',+ );+ for (final offset in [0.0, 300.0]) {+ controller.jumpTo(offset);+ await tester.pump();+ final back = tester.getSemantics(find.bySemanticsLabel('Back'));+ expect(back.rect.width, greaterThanOrEqualTo(48));+ expect(back.rect.height, greaterThanOrEqualTo(48));+ expect(+ tester.getRect(find.byIcon(Icons.arrow_back)),+ const Rect.fromLTWH(16, 16, 24, 24),+ );+ expect(tester.getTopLeft(title).dx, offset == 0 ? 16 : 52);++ // All four corners are outside the arrow, including the left gutter.+ for (final point in const [+ Offset(1, 1),+ Offset(47, 1),+ Offset(1, 47),+ Offset(47, 47),+ ]) {+ final previousBackTaps = backTaps;+ await tester.tapAt(point);+ expect(backTaps, previousBackTaps + 1);+ }++ final previousBackTaps = backTaps;+ final previousTitleTaps = titleTaps;+ await tester.tapAt(tester.getTopLeft(title) + const Offset(1, 1));+ expect(titleTaps, previousTitleTaps + 1);+ await tester.tap(find.byIcon(Icons.more_vert));+ expect(backTaps, previousBackTaps);+ }+ expect(actionTaps, 2);++ // While collapsing, the title moves through the enlarged back target.+ controller.jumpTo(20);+ await tester.pump();+ final previousBackTaps = backTaps;+ final previousTitleTaps = titleTaps;+ await tester.tapAt(tester.getTopLeft(title) + const Offset(1, 1));+ expect(titleTaps, previousTitleTaps + 1);+ expect(backTaps, previousBackTaps);+ expect(tester.takeException(), isNull);+ semantics.dispose();+ },+ );++ testWidgets('header back target respects the status bar and pops its route', (+ tester,+ ) async {+ final navigator = GlobalKey<NavigatorState>();+ await tester.pumpWidget(+ MaterialApp(+ navigatorKey: navigator,+ theme: ComponentTheme.lightTheme(),+ home: const Scaffold(body: Text('Home')),+ ),+ );+ unawaited(+ navigator.currentState!.push<void>(+ MaterialPageRoute<void>(+ builder: (_) => const MediaQuery(+ data: MediaQueryData(padding: EdgeInsets.only(top: 44)),+ child: Scaffold(+ body: AppBarComponent(title: 'Settings', slivers: []),+ ),+ ),+ ),+ ),+ );+ await tester.pumpAndSettle();++ await tester.tapAt(const Offset(1, 43));+ await tester.pumpAndSettle();+ expect(find.text('Settings'), findsOneWidget);++ await tester.tapAt(const Offset(1, 45));+ await tester.pumpAndSettle();+ expect(find.text('Home'), findsOneWidget);+ expect(find.text('Settings'), findsNothing);+ });++ testWidgets('custom header dimensions keep existing back and title spacing', (+ tester,+ ) async {+ final controller = ScrollController();+ addTearDown(controller.dispose);+ await pumpComponent(+ tester,+ CustomScrollView(+ controller: controller,+ slivers: const [+ SliverAppBarComponent(+ title: 'Compact header',+ horizontalPadding: 0,+ collapsedHeight: 38,+ ),+ SliverToBoxAdapter(child: SizedBox(height: 1000)),+ ],+ ),+ );++ for (final offset in [0.0, 300.0]) {+ controller.jumpTo(offset);+ await tester.pump();+ expect(+ tester.getRect(find.byIcon(Icons.arrow_back)),+ const Rect.fromLTWH(0, 7, 24, 24),+ );+ expect(+ tester.getTopLeft(find.text('Compact header')).dx,+ offset == 0 ? 0 : 36,+ );+ }+ expect(tester.takeException(), isNull);+ });++ testWidgets('header preserves custom and hidden back controls', (+ tester,+ ) async {+ var backTaps = 0;+ var closeTaps = 0;+ for (final showBack in [true, false]) {+ await pumpComponent(+ tester,+ AppBarComponent(+ title: 'Settings',+ showExpandedBackButton: showBack,+ onBack: () => backTaps++,+ backButton: IconButton(+ icon: const Icon(Icons.close),+ onPressed: () => closeTaps++,+ ),+ slivers: const [],+ ),+ );+ expect(find.byIcon(Icons.arrow_back), findsNothing);+ if (showBack) {+ expect(+ tester.getCenter(find.byIcon(Icons.close)),+ const Offset(35, 28),+ );+ await tester.tap(find.byIcon(Icons.close));+ } else {+ expect(find.byIcon(Icons.close), findsNothing);+ }+ await tester.tapAt(const Offset(1, 1));+ }++ await pumpComponent(+ tester,+ AppBarComponent(+ title: 'Onboarding',+ showExpandedBackButton: false,+ onBack: () => backTaps++,+ slivers: const [],+ ),+ );+ expect(find.byIcon(Icons.arrow_back), findsNothing);+ await tester.tapAt(const Offset(1, 1));+ expect(backTaps, 0);+ expect(closeTaps, 1);+ expect(tester.takeException(), isNull);+ });+testWidgets('SliverAppBarComponent supports tap tooltip title reveal', (tester,) async {