π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Increase text field suffix tap target
ashilkna10e130632d7
diff --git a/mobile/apps/photos/lib/ui/components/searchable_appbar.dart b/mobile/apps/photos/lib/ui/components/searchable_appbar.dartindex df18d4abf4..91f5c5ebfd 100644--- a/mobile/apps/photos/lib/ui/components/searchable_appbar.dart+++ b/mobile/apps/photos/lib/ui/components/searchable_appbar.dart@@ -151,15 +151,12 @@ class _SearchableAppBarState extends State<SearchableAppBar> {size: 18,color: colors.textLight,),- suffix: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: _deactivateSearch,- child: HugeIcon(- icon: HugeIcons.strokeRoundedCancel01,- size: 18,- color: colors.textLight,- ),+ suffix: HugeIcon(+ icon: HugeIcons.strokeRoundedCancel01,+ size: 18,+ color: colors.textLight,),+ onSuffixTap: _deactivateSearch,onChanged: widget.onSearch,),);diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_page.dart b/mobile/apps/photos/lib/ui/settings/search/settings_search_page.dartindex c986bcff15..71abc667b5 100644--- a/mobile/apps/photos/lib/ui/settings/search/settings_search_page.dart+++ b/mobile/apps/photos/lib/ui/settings/search/settings_search_page.dart@@ -166,21 +166,15 @@ class _SettingsSearchPageState extends State<SettingsSearchPage> {color: colors.textLight,strokeWidth: 1.6,),- suffix: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: _searchQuery.isNotEmpty- ? _clearSearch- : () => Navigator.of(context).pop(),- child: SizedBox.square(- dimension: 24,- child: HugeIcon(- icon: HugeIcons.strokeRoundedCancel01,- size: 18,- color: colors.textLight,- strokeWidth: 1.6,- ),- ),+ suffix: HugeIcon(+ icon: HugeIcons.strokeRoundedCancel01,+ size: 18,+ color: colors.textLight,+ strokeWidth: 1.6,),+ onSuffixTap: _searchQuery.isNotEmpty+ ? _clearSearch+ : () => Navigator.of(context).pop(),),);}diff --git a/mobile/apps/photos/lib/ui/tabs/albums_tab.dart b/mobile/apps/photos/lib/ui/tabs/albums_tab.dartindex adfa9cccc6..43357c33da 100644--- a/mobile/apps/photos/lib/ui/tabs/albums_tab.dart+++ b/mobile/apps/photos/lib/ui/tabs/albums_tab.dart@@ -781,15 +781,12 @@ class _AlbumsTabState extends State<AlbumsTab>size: 18,color: componentColors.textLight,),- suffix: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: _deactivateSearch,- child: HugeIcon(- icon: HugeIcons.strokeRoundedCancel01,- size: 18,- color: componentColors.textLight,- ),+ suffix: HugeIcon(+ icon: HugeIcons.strokeRoundedCancel01,+ size: 18,+ color: componentColors.textLight,),+ onSuffixTap: _deactivateSearch,onChanged: (value) {final hadSearchQuery = _hasSearchQuery;if (!hadSearchQuery &&diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dartindex cc845210c5..66a6e050f6 100644--- a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart@@ -980,15 +980,12 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {size: 18,color: colors.textLight,),- suffix: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: _closeSearch,- child: HugeIcon(- icon: HugeIcons.strokeRoundedCancel01,- size: 18,- color: colors.textLight,- ),+ suffix: HugeIcon(+ icon: HugeIcons.strokeRoundedCancel01,+ size: 18,+ color: colors.textLight,),+ onSuffixTap: _closeSearch,onChanged: _updateSearchQuery,);}diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dartindex 2c6e7cc0a3..a9ed7bda53 100644--- a/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/result/search_section_all_page.dart@@ -354,15 +354,12 @@ class _SearchSectionAllPageState extends State<SearchSectionAllPage> {size: 18,color: colors.textLight,),- suffix: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: _closeSearch,- child: HugeIcon(- icon: HugeIcons.strokeRoundedCancel01,- size: 18,- color: colors.textLight,- ),+ suffix: HugeIcon(+ icon: HugeIcons.strokeRoundedCancel01,+ size: 18,+ color: colors.textLight,),+ onSuffixTap: _closeSearch,onChanged: _updateSearchQuery,);}diff --git a/mobile/packages/ente_components/lib/components/text_input_component.dart b/mobile/packages/ente_components/lib/components/text_input_component.dartindex 3866a879d6..fa119d400e 100644--- a/mobile/packages/ente_components/lib/components/text_input_component.dart+++ b/mobile/packages/ente_components/lib/components/text_input_component.dart@@ -48,6 +48,7 @@ class TextInputComponent extends StatefulWidget {this.isRequired = false,this.prefix,this.suffix,+ this.onSuffixTap,this.messageType = TextInputComponentMessageType.helper,this.messageIcon,this.isDisabled = false,@@ -95,6 +96,10 @@ class TextInputComponent extends StatefulWidget {/// Caller-owned trailing widget. Multiline fields pin this slot to the top.final Widget? suffix;++ /// Optional tap handler for [suffix]. When provided, the trailing affordance+ /// gets a 48px tap target without changing the field's visual layout.+ final VoidCallback? onSuffixTap;final TextInputComponentMessageType messageType;final IconData? messageIcon;final bool isDisabled;@@ -110,6 +115,7 @@ class TextInputComponent extends StatefulWidget {class _TextInputComponentState extends State<TextInputComponent> {static const _kHeight = 52.0;static const _kIconContainerSize = IconSizes.medium;+ static const _kSuffixTapTargetSize = 48.0;TextEditingController? _internalController;FocusNode? _internalFocusNode;@@ -201,6 +207,7 @@ class _TextInputComponentState extends State<TextInputComponent> {final messageColor = _messageColor(colors);final prefix = _buildPrefix();final suffix = _buildSuffix(colors);+ final suffixTap = _suffixTapHandler;return Column(crossAxisAlignment: CrossAxisAlignment.start,@@ -233,68 +240,82 @@ class _TextInputComponentState extends State<TextInputComponent> {constraints: _isMultiline? const BoxConstraints(minHeight: _kHeight): null,- padding: EdgeInsets.symmetric(- horizontal: Spacing.lg,- vertical: _isMultiline ? Spacing.lg : 0,- ),decoration: BoxDecoration(color: _backgroundColor(colors),borderRadius: BorderRadius.circular(Radii.lg),border: Border.all(color: _borderColor(colors)),),- child: Row(- crossAxisAlignment: _isMultiline- ? CrossAxisAlignment.start- : CrossAxisAlignment.center,+ child: Stack(+ clipBehavior: Clip.none,+ fit: _isMultiline ? StackFit.loose : StackFit.expand,children: [- if (prefix != null) ...[- prefix,- const SizedBox(width: Spacing.sm),- ],- Expanded(- child: TextField(- controller: _controller,- focusNode: _focusNode,- enabled: !widget.isDisabled,- autofocus: widget.autofocus,- obscureText: _obscureText,- maxLines: widget.isPasswordInput- ? 1- : widget.maxLines ?? (_isMultiline ? null : 1),- minLines: widget.isPasswordInput ? null : widget.minLines,- keyboardType: widget.keyboardType,- textCapitalization: widget.textCapitalization,- inputFormatters: _inputFormatters,- autofillHints:- widget.autofillHints ??- (widget.isPasswordInput- ? const [AutofillHints.password]- : const []),- autocorrect: widget.autocorrect && !widget.isPasswordInput,- enableSuggestions: !widget.isPasswordInput,- textAlignVertical: _isMultiline- ? TextAlignVertical.top- : TextAlignVertical.center,- onEditingComplete: _handleEditingComplete,- style: TextStyles.body.copyWith(color: _textColor(colors)),- decoration: InputDecoration(- hintText: widget.hintText,- hintStyle: TextStyles.body.copyWith(- color: _hintColor(colors),+ Padding(+ padding: EdgeInsets.symmetric(+ horizontal: Spacing.lg,+ vertical: _isMultiline ? Spacing.lg : 0,+ ),+ child: Row(+ crossAxisAlignment: _isMultiline+ ? CrossAxisAlignment.start+ : CrossAxisAlignment.center,+ children: [+ if (prefix != null) ...[+ prefix,+ const SizedBox(width: Spacing.sm),+ ],+ Expanded(+ child: TextField(+ controller: _controller,+ focusNode: _focusNode,+ enabled: !widget.isDisabled,+ autofocus: widget.autofocus,+ obscureText: _obscureText,+ maxLines: widget.isPasswordInput+ ? 1+ : widget.maxLines ?? (_isMultiline ? null : 1),+ minLines: widget.isPasswordInput+ ? null+ : widget.minLines,+ keyboardType: widget.keyboardType,+ textCapitalization: widget.textCapitalization,+ inputFormatters: _inputFormatters,+ autofillHints:+ widget.autofillHints ??+ (widget.isPasswordInput+ ? const [AutofillHints.password]+ : const []),+ autocorrect:+ widget.autocorrect && !widget.isPasswordInput,+ enableSuggestions: !widget.isPasswordInput,+ textAlignVertical: _isMultiline+ ? TextAlignVertical.top+ : TextAlignVertical.center,+ onEditingComplete: _handleEditingComplete,+ style: TextStyles.body.copyWith(+ color: _textColor(colors),+ ),+ decoration: InputDecoration(+ hintText: widget.hintText,+ hintStyle: TextStyles.body.copyWith(+ color: _hintColor(colors),+ ),+ border: InputBorder.none,+ focusedBorder: InputBorder.none,+ enabledBorder: InputBorder.none,+ disabledBorder: InputBorder.none,+ isDense: true,+ contentPadding: EdgeInsets.zero,+ ),+ ),),- border: InputBorder.none,- focusedBorder: InputBorder.none,- enabledBorder: InputBorder.none,- disabledBorder: InputBorder.none,- isDense: true,- contentPadding: EdgeInsets.zero,- ),+ if (suffix != null) ...[+ const SizedBox(width: Spacing.sm),+ suffix,+ ],+ ],),),- if (suffix != null) ...[- const SizedBox(width: Spacing.sm),- suffix,- ],+ if (suffixTap != null) _suffixTapTarget(suffixTap),],),),@@ -396,37 +417,18 @@ class _TextInputComponentState extends State<TextInputComponent> {Widget? _buildSuffix(ColorTokens colors) {final Widget child;if (widget.isPasswordInput) {- child = GestureDetector(- key: const ValueKey('text-field-password-toggle'),- behavior: HitTestBehavior.opaque,- onTap: widget.isDisabled- ? null- : () => setState(() => _obscureText = !_obscureText),- child: Icon(- _obscureText- ? Icons.visibility_off_outlined- : Icons.visibility_outlined,- size: IconSizes.small,- color: colors.textLighter,- ),+ child = Icon(+ _obscureText+ ? Icons.visibility_off_outlined+ : Icons.visibility_outlined,+ size: IconSizes.small,+ color: colors.textLighter,);} else if (widget.isClearable && _hasText) {- child = GestureDetector(- key: const ValueKey('text-field-clear'),- behavior: HitTestBehavior.opaque,- onTap: widget.isDisabled- ? null- : () {- _controller.clear();- if (widget.shouldUnfocusOnClearOrSubmit) {- FocusScope.of(context).unfocus();- }- },- child: Icon(- Icons.close_rounded,- size: IconSizes.small,- color: colors.textLighter,- ),+ child = Icon(+ Icons.close_rounded,+ size: IconSizes.small,+ color: colors.textLighter,);} else if (widget.suffix != null) {child = widget.suffix!;@@ -437,6 +439,54 @@ class _TextInputComponentState extends State<TextInputComponent> {return _slot(child);}+ VoidCallback? get _suffixTapHandler {+ if (widget.isDisabled) return null;+ if (widget.isPasswordInput) {+ return () => setState(() => _obscureText = !_obscureText);+ }+ if (widget.isClearable && _hasText) {+ return () {+ _controller.clear();+ if (widget.shouldUnfocusOnClearOrSubmit) {+ FocusScope.of(context).unfocus();+ }+ };+ }+ return widget.onSuffixTap;+ }++ Widget _suffixTapTarget(VoidCallback onTap) {+ return PositionedDirectional(+ top: _suffixTapTargetTop,+ end: Spacing.lg - (_kSuffixTapTargetSize - _kIconContainerSize) / 2,+ width: _kSuffixTapTargetSize,+ height: _kSuffixTapTargetSize,+ child: GestureDetector(+ key: _suffixTapTargetKey,+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: const SizedBox.expand(),+ ),+ );+ }++ double get _suffixTapTargetTop {+ if (_isMultiline) {+ return Spacing.lg - (_kSuffixTapTargetSize - _kIconContainerSize) / 2;+ }+ return (_kHeight - _kSuffixTapTargetSize) / 2;+ }++ Key? get _suffixTapTargetKey {+ if (widget.isPasswordInput) {+ return const ValueKey('text-field-password-toggle');+ }+ if (widget.isClearable && _hasText) {+ return const ValueKey('text-field-clear');+ }+ return null;+ }+Widget? _messageIcon(Color color) {if (widget.messageIcon != null) {return Icon(widget.messageIcon, size: IconSizes.small, color: color);diff --git a/mobile/packages/ente_components/test/components/text_input_component_test.dart b/mobile/packages/ente_components/test/components/text_input_component_test.dartindex 9f4d05fc90..d337090aeb 100644--- a/mobile/packages/ente_components/test/components/text_input_component_test.dart+++ b/mobile/packages/ente_components/test/components/text_input_component_test.dart@@ -166,11 +166,23 @@ void main() {);final input = tester.widget<TextField>(find.byType(TextField));- final container = tester.widget<Container>(_fieldContainers().first);+ final padding = tester.widget<Padding>(+ find+ .descendant(+ of: _fieldContainers().first,+ matching: find.byWidgetPredicate(+ (widget) =>+ widget is Padding &&+ widget.padding ==+ const EdgeInsets.symmetric(horizontal: 16, vertical: 16),+ ),+ )+ .first,+ );expect(input.maxLines, 4);expect(- container.padding,+ padding.padding,const EdgeInsets.symmetric(horizontal: 16, vertical: 16),);expect(_fieldDecoration(tester).borderRadius, BorderRadius.circular(16));@@ -308,6 +320,67 @@ void main() {},);+ testWidgets(+ "TextInputComponent gives suffix actions a 48px tap target without resizing",+ (tester) async {+ var suffixTapCount = 0;++ await tester.pumpWidget(+ _wrap(+ SizedBox(+ width: 240,+ child: TextInputComponent(+ suffix: const Icon(+ Icons.close_rounded,+ key: ValueKey("custom-suffix-icon"),+ ),+ onSuffixTap: () => suffixTapCount++,+ ),+ ),+ ),+ );++ final fieldFinder = _fieldContainers().first;+ final fieldRect = tester.getRect(fieldFinder);++ expect(fieldRect.height, 52);++ await tester.tapAt(Offset(fieldRect.right - 51, fieldRect.center.dy));+ await tester.pump();++ expect(suffixTapCount, 1);+ expect(tester.getRect(fieldFinder).height, 52);+ },+ );++ testWidgets("TextInputComponent centers single-line affixes vertically", (+ tester,+ ) async {+ await tester.pumpWidget(+ _wrap(+ const SizedBox(+ width: 240,+ child: TextInputComponent(+ prefix: Icon(Icons.search, key: ValueKey("prefix-icon")),+ suffix: Icon(Icons.close_rounded, key: ValueKey("suffix-icon")),+ onSuffixTap: _noop,+ ),+ ),+ ),+ );++ final fieldCenter = tester.getRect(_fieldContainers().first).center.dy;++ expect(+ tester.getRect(find.byKey(const ValueKey("prefix-icon"))).center.dy,+ fieldCenter,+ );+ expect(+ tester.getRect(find.byKey(const ValueKey("suffix-icon"))).center.dy,+ fieldCenter,+ );+ });+testWidgets("TextInputComponent renders alert message visuals", (tester,) async {@@ -448,3 +521,5 @@ Widget _wrap(Widget child) {),);}++void _noop() {}