Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Limit back-button touch targets to 48dp

ashil-pilot82b5ed9ac8e0
diff --git a/mobile/packages/ente_components/lib/components/app_bar_component.dart b/mobile/packages/ente_components/lib/components/app_bar_component.dart
index 0f3e181011..c91df9ab8c 100644
--- a/mobile/packages/ente_components/lib/components/app_bar_component.dart
+++ b/mobile/packages/ente_components/lib/components/app_bar_component.dart
@@ -548,18 +548,12 @@ class _HeaderAppBarDelegate extends SliverPersistentHeaderDelegate {
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,
- ),
+ // Keep this behind the moving content so title and leading
+ // gestures win where they overlap the larger touch target.
+ _HeaderAppBarBackButton(
+ onBack: onBack,
+ chromeHeight: collapsedHeight,
+ horizontalPadding: horizontalPadding,
),
Positioned.fill(
bottom: bottomHeight + visibleCollapsibleBottomHeight,
@@ -786,38 +780,46 @@ class _PinnedHeaderChrome extends StatelessWidget {
class _HeaderAppBarBackButton extends StatelessWidget {
const _HeaderAppBarBackButton({
required this.onBack,
- required this.width,
- required this.height,
- required this.leftPadding,
+ required this.chromeHeight,
+ required this.horizontalPadding,
});
final VoidCallback? onBack;
- final double width;
- final double height;
- final double leftPadding;
+ final double chromeHeight;
+ final double horizontalPadding;
@override
Widget build(BuildContext context) {
final colors = context.componentColors;
final tooltip = MaterialLocalizations.of(context).backButtonTooltip;
+ const iconPadding = (kMinInteractiveDimension - _defaultBackIconSize) / 2;
+ final left = math.max(0.0, horizontalPadding - iconPadding);
+ final top = _centeredTop(chromeHeight, kMinInteractiveDimension);
- return SizedBox(
- width: width,
- height: height,
- 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,
+ return Positioned(
+ left: left,
+ top: top,
+ child: SizedBox.square(
+ dimension: kMinInteractiveDimension,
+ child: Semantics(
+ button: true,
+ label: tooltip,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onBack ?? () => Navigator.maybePop(context),
+ child: Padding(
+ // Preserve the icon position even with custom, compact headers.
+ padding: EdgeInsets.only(
+ left: horizontalPadding - left,
+ top: _centeredTop(chromeHeight, _defaultBackIconSize) - top,
+ ),
+ child: Align(
+ alignment: Alignment.topLeft,
+ 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.dart
index 571eac166e..9661f09b97 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
@@ -273,21 +273,22 @@ void main() {
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));
+ final backButton = find.bySemanticsLabel('Back');
+ expect(tester.getSemantics(backButton).rect.size, const Size(48, 48));
+ expect(tester.getRect(backButton), const Rect.fromLTWH(4, 4, 48, 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),
+ // Tap near each corner outside the arrow. The expanded title starts
+ // at y=48 and retains its own taps where it overlaps the target.
+ for (final point in [
+ const Offset(5, 5),
+ const Offset(51, 5),
+ const Offset(5, 51),
+ Offset(51, offset == 0 ? 47 : 51),
]) {
final previousBackTaps = backTaps;
await tester.tapAt(point);
@@ -296,6 +297,16 @@ void main() {
final previousBackTaps = backTaps;
final previousTitleTaps = titleTaps;
+ // The area just outside each edge must no longer trigger back.
+ for (final point in const [
+ Offset(3, 28),
+ Offset(53, 5),
+ Offset(28, 3),
+ Offset(5, 53),
+ ]) {
+ await tester.tapAt(point);
+ expect(backTaps, previousBackTaps);
+ }
await tester.tapAt(tester.getTopLeft(title) + const Offset(1, 1));
expect(titleTaps, previousTitleTaps + 1);
await tester.tap(find.byIcon(Icons.more_vert));
@@ -341,11 +352,12 @@ void main() {
);
await tester.pumpAndSettle();
- await tester.tapAt(const Offset(1, 43));
+ await tester.tapAt(const Offset(5, 43));
+ await tester.tapAt(const Offset(5, 47));
await tester.pumpAndSettle();
expect(find.text('Settings'), findsOneWidget);
- await tester.tapAt(const Offset(1, 45));
+ await tester.tapAt(const Offset(5, 49));
await tester.pumpAndSettle();
expect(find.text('Home'), findsOneWidget);
expect(find.text('Settings'), findsNothing);
@@ -760,11 +772,13 @@ void main() {
expect(tester.takeException(), isNull);
expect(find.text(title), findsOneWidget);
expect(tester.getBottomLeft(find.text(title)).dy, lessThanOrEqualTo(128));
+ expect(tester.getSize(find.bySemanticsLabel('Back')), const Size(48, 48));
await tester.drag(find.byType(CustomScrollView), const Offset(0, -240));
await tester.pump();
expect(tester.takeException(), isNull);
expect(find.text(title), findsOneWidget);
+ expect(tester.getSize(find.bySemanticsLabel('Back')), const Size(48, 48));
});
}