π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile] Extend TextInputComponent for Locker forms
aman-pilot66ff075c3b96
diff --git a/mobile/packages/ente_components/lib/components/text_input_component.dart b/mobile/packages/ente_components/lib/components/text_input_component.dartindex 3a9865df79..8f6c40408a 100644--- a/mobile/packages/ente_components/lib/components/text_input_component.dart+++ b/mobile/packages/ente_components/lib/components/text_input_component.dart@@ -43,6 +43,7 @@ class TextInputComponent extends StatefulWidget {this.isEmptyNotifier,this.inputFormatters,this.keyboardType,+ this.textInputAction,this.enableFillColor = true,this.autocorrect = true,this.enableSuggestions = true,@@ -53,6 +54,7 @@ class TextInputComponent extends StatefulWidget {this.messageType = TextInputComponentMessageType.helper,this.messageIcon,this.isDisabled = false,+ this.readOnly = false,this.autofillHints,this.maxLines,this.minLines,@@ -88,6 +90,10 @@ class TextInputComponent extends StatefulWidget {final ValueNotifier<bool>? isEmptyNotifier;final List<TextInputFormatter>? inputFormatters;final TextInputType? keyboardType;++ /// Platform IME action. When set to [TextInputAction.next], completing the+ /// field moves focus to the next node instead of doing nothing.+ final TextInputAction? textInputAction;final bool enableFillColor;final bool autocorrect;final bool enableSuggestions;@@ -96,7 +102,9 @@ class TextInputComponent extends StatefulWidget {/// Caller-owned leading widget. Pass explicit color and size when needed.final Widget? prefix;- /// Caller-owned trailing widget. Multiline fields pin this slot to the top.+ /// Caller-owned trailing widget. Sits in an icon slot that is at least+ /// [IconSizes.medium] square and grows to fit wider content (e.g. a row of+ /// affordances). Multiline fields pin this slot to the top.final Widget? suffix;/// Optional tap handler for [suffix]. When provided, the trailing affordance@@ -105,6 +113,11 @@ class TextInputComponent extends StatefulWidget {final TextInputComponentMessageType messageType;final IconData? messageIcon;final bool isDisabled;++ /// When true the field is non-editable but keeps the enabled visual style+ /// (unlike [isDisabled], which also mutes the text and disables the suffix+ /// tap). Text stays selectable and the soft keyboard is suppressed.+ final bool readOnly;final Iterable<String>? autofillHints;final int? maxLines;final int? minLines;@@ -290,6 +303,7 @@ class _TextInputComponentState extends State<TextInputComponent> {controller: _controller,focusNode: _focusNode,enabled: !widget.isDisabled,+ readOnly: widget.readOnly,autofocus: widget.autofocus,obscureText: _obscureText,maxLines: widget.isPasswordInput@@ -299,6 +313,7 @@ class _TextInputComponentState extends State<TextInputComponent> {? null: widget.minLines,keyboardType: widget.keyboardType,+ textInputAction: widget.textInputAction,textCapitalization: widget.textCapitalization,inputFormatters: _inputFormatters,autofillHints:@@ -534,9 +549,12 @@ class _TextInputComponentState extends State<TextInputComponent> {}Widget _slot(Widget child) {- return SizedBox.square(- dimension: _kIconContainerSize,- child: Center(child: child),+ return ConstrainedBox(+ constraints: const BoxConstraints(+ minWidth: _kIconContainerSize,+ minHeight: _kIconContainerSize,+ ),+ child: Center(widthFactor: 1, heightFactor: 1, child: child),);}@@ -571,7 +589,9 @@ class _TextInputComponentState extends State<TextInputComponent> {TextInput.finishAutofillContext();}if (widget.onSubmit == null) {- if (widget.shouldUnfocusOnClearOrSubmit) {+ if (widget.textInputAction == TextInputAction.next) {+ _focusNode.nextFocus();+ } else if (widget.shouldUnfocusOnClearOrSubmit) {FocusScope.of(context).unfocus();}return;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 e3cefc44be..002de43173 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@@ -178,6 +178,26 @@ void main() {},);+ testWidgets(+ "TextInputComponent forwards read-only state while staying enabled",+ (tester) async {+ await tester.pumpWidget(+ _wrap(+ const TextInputComponent(+ label: "Username",+ initialValue: "hello",+ readOnly: true,+ ),+ ),+ );++ final input = tester.widget<TextField>(find.byType(TextField));+ expect(input.readOnly, isTrue);+ expect(input.enabled, isTrue);+ expect(_fieldDecoration(tester).color, ColorTokens.light.fillLight);+ },+ );+testWidgets("TextInputComponent supports the multiline layout", (tester,) async {@@ -382,6 +402,27 @@ void main() {},);+ testWidgets("TextInputComponent grows the suffix slot to fit wide suffixes", (+ tester,+ ) async {+ await tester.pumpWidget(+ _wrap(+ const SizedBox(+ width: 240,+ child: TextInputComponent(+ suffix: SizedBox(+ key: ValueKey("wide-suffix"),+ width: 80,+ height: 48,+ ),+ ),+ ),+ ),+ );++ expect(tester.getSize(find.byKey(const ValueKey("wide-suffix"))).width, 80);+ });+testWidgets("TextInputComponent centers single-line affixes vertically", (tester,) async {