Skip to content

Commit c22eaa9

Browse files
committed
compose [nfc]: Make narrow nullable on _ContentInput
This will disable autocomplete on the input, since narrow is required for MentionAutocomplete… classes to function. In the future, a better solution can make these autocomplete classes support null narrow, by perhaps disabling wildcard mentions autocomplete, while still allowing other types of autocompletion that make sense in a saved snippet's compose box.
1 parent 683b977 commit c22eaa9

File tree

1 file changed

+51
-40
lines changed

1 file changed

+51
-40
lines changed

lib/widgets/compose_box.dart

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,12 @@ class _ContentInput extends StatelessWidget {
498498
required this.hintText,
499499
});
500500

501-
final Narrow narrow;
501+
/// The narrow used for autocomplete.
502+
///
503+
/// If `null`, autocomplete is disabled.
504+
// TODO support autocomplete without a narrow
505+
final Narrow? narrow;
506+
502507
final BaseComposeBoxController controller;
503508
final String hintText;
504509

@@ -531,48 +536,54 @@ class _ContentInput extends StatelessWidget {
531536
Widget build(BuildContext context) {
532537
final designVariables = DesignVariables.of(context);
533538

539+
final inputWidget = ConstrainedBox(
540+
constraints: BoxConstraints(maxHeight: maxHeight(context)),
541+
// This [ClipRect] replaces the [TextField] clipping we disable below.
542+
child: ClipRect(
543+
child: InsetShadowBox(
544+
top: _verticalPadding, bottom: _verticalPadding,
545+
color: designVariables.composeBoxBg,
546+
child: TextField(
547+
controller: controller.content,
548+
focusNode: controller.contentFocusNode,
549+
// Let the content show through the `contentPadding` so that
550+
// our [InsetShadowBox] can fade it smoothly there.
551+
clipBehavior: Clip.none,
552+
style: TextStyle(
553+
fontSize: _fontSize,
554+
height: _lineHeightRatio,
555+
color: designVariables.textInput),
556+
// From the spec at
557+
// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=3960-5147&node-type=text&m=dev
558+
// > Compose box has the height to fit 2 lines. This is [done] to
559+
// > have a bigger hit area for the user to start the input. […]
560+
minLines: 2,
561+
maxLines: null,
562+
textCapitalization: TextCapitalization.sentences,
563+
decoration: InputDecoration(
564+
// This padding ensures that the user can always scroll long
565+
// content entirely out of the top or bottom shadow if desired.
566+
// With this and the `minLines: 2` above, an empty content input
567+
// gets 60px vertical distance (with no text-size scaling)
568+
// between the top of the top shadow and the bottom of the
569+
// bottom shadow. That's a bit more than the 54px given in the
570+
// Figma, and we can revisit if needed, but it's tricky to get
571+
// that 54px distance while also making the scrolling work like
572+
// this and offering two lines of touchable area.
573+
contentPadding: const EdgeInsets.symmetric(vertical: _verticalPadding),
574+
hintText: hintText,
575+
hintStyle: TextStyle(
576+
color: designVariables.textInput.withFadedAlpha(0.5)))))));
577+
578+
if (narrow == null) {
579+
return inputWidget;
580+
}
581+
534582
return ComposeAutocomplete(
535-
narrow: narrow,
583+
narrow: narrow!,
536584
controller: controller.content,
537585
focusNode: controller.contentFocusNode,
538-
fieldViewBuilder: (context) => ConstrainedBox(
539-
constraints: BoxConstraints(maxHeight: maxHeight(context)),
540-
// This [ClipRect] replaces the [TextField] clipping we disable below.
541-
child: ClipRect(
542-
child: InsetShadowBox(
543-
top: _verticalPadding, bottom: _verticalPadding,
544-
color: designVariables.composeBoxBg,
545-
child: TextField(
546-
controller: controller.content,
547-
focusNode: controller.contentFocusNode,
548-
// Let the content show through the `contentPadding` so that
549-
// our [InsetShadowBox] can fade it smoothly there.
550-
clipBehavior: Clip.none,
551-
style: TextStyle(
552-
fontSize: _fontSize,
553-
height: _lineHeightRatio,
554-
color: designVariables.textInput),
555-
// From the spec at
556-
// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=3960-5147&node-type=text&m=dev
557-
// > Compose box has the height to fit 2 lines. This is [done] to
558-
// > have a bigger hit area for the user to start the input. […]
559-
minLines: 2,
560-
maxLines: null,
561-
textCapitalization: TextCapitalization.sentences,
562-
decoration: InputDecoration(
563-
// This padding ensures that the user can always scroll long
564-
// content entirely out of the top or bottom shadow if desired.
565-
// With this and the `minLines: 2` above, an empty content input
566-
// gets 60px vertical distance (with no text-size scaling)
567-
// between the top of the top shadow and the bottom of the
568-
// bottom shadow. That's a bit more than the 54px given in the
569-
// Figma, and we can revisit if needed, but it's tricky to get
570-
// that 54px distance while also making the scrolling work like
571-
// this and offering two lines of touchable area.
572-
contentPadding: const EdgeInsets.symmetric(vertical: _verticalPadding),
573-
hintText: hintText,
574-
hintStyle: TextStyle(
575-
color: designVariables.textInput.withFadedAlpha(0.5))))))));
586+
fieldViewBuilder: (context) => inputWidget);
576587
}
577588
}
578589

0 commit comments

Comments
 (0)