Skip to content

Commit ea80de0

Browse files
committed
compose: Change content input hint text statefully
Before, the content input shows the "#stream > topic" hint text as long as it has focus, and set the hint text to "#stream" when it loses focus. Now, the content input still shows "#stream > topic" when it gains focus, except that it will keep showing it even after losing focus, until the user moves focus to the topic input.
1 parent 5d57363 commit ea80de0

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

lib/widgets/compose_box.dart

+17-5
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,18 @@ class _StreamContentInputState extends State<_StreamContentInput> {
596596
});
597597
}
598598

599+
void _topicInteractionStatusChanged() {
600+
setState(() {
601+
// The relevant state lives on widget.controller.topicInteractionStatus itself.
602+
});
603+
}
604+
599605
@override
600606
void initState() {
601607
super.initState();
602608
widget.controller.topic.addListener(_topicChanged);
603609
widget.controller.contentFocusNode.addListener(_contentFocusChanged);
610+
widget.controller.topicInteractionStatus.addListener(_topicInteractionStatusChanged);
604611
}
605612

606613
@override
@@ -614,12 +621,17 @@ class _StreamContentInputState extends State<_StreamContentInput> {
614621
oldWidget.controller.contentFocusNode.removeListener(_contentFocusChanged);
615622
widget.controller.contentFocusNode.addListener(_contentFocusChanged);
616623
}
624+
if (widget.controller.topicInteractionStatus != oldWidget.controller.topicInteractionStatus) {
625+
oldWidget.controller.topicInteractionStatus.removeListener(_topicInteractionStatusChanged);
626+
widget.controller.topicInteractionStatus.addListener(_topicInteractionStatusChanged);
627+
}
617628
}
618629

619630
@override
620631
void dispose() {
621632
widget.controller.topic.removeListener(_topicChanged);
622633
widget.controller.contentFocusNode.removeListener(_contentFocusChanged);
634+
widget.controller.topicInteractionStatus.removeListener(_topicInteractionStatusChanged);
623635
super.dispose();
624636
}
625637

@@ -630,11 +642,11 @@ class _StreamContentInputState extends State<_StreamContentInput> {
630642
// The chosen topic can't be sent to, so don't show it.
631643
return null;
632644
}
633-
if (!widget.controller.contentFocusNode.hasFocus) {
634-
// Do not fall back to a vacuous topic unless the user explicitly chooses
635-
// to do so (by skipping topic input and moving focus to content input),
636-
// so that the user is not encouraged to use vacuous topic when they
637-
// have not interacted with the inputs at all.
645+
if (widget.controller.topicInteractionStatus.value !=
646+
ComposeTopicInteractionStatus.hasChosen) {
647+
// Do not fall back to a vacuous topic unless the user explicitly
648+
// chooses to do so, so that the user is not encouraged to use vacuous
649+
// topic before they have interacted with the inputs at all.
638650
return null;
639651
}
640652
}

test/widgets/compose_box_test.dart

+17
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,23 @@ void main() {
472472
contentHintText: 'Message #${channel.name}');
473473
});
474474

475+
testWidgets('with empty topic, content input has focus, then loses it', (tester) async {
476+
await prepare(tester, narrow: narrow, mandatoryTopics: false);
477+
await enterContent(tester, '');
478+
await tester.pump();
479+
checkComposeBoxHintTexts(tester,
480+
topicHintText: eg.defaultRealmEmptyTopicDisplayName,
481+
contentHintText: 'Message #${channel.name} > '
482+
'${eg.defaultRealmEmptyTopicDisplayName}');
483+
484+
FocusManager.instance.primaryFocus!.unfocus();
485+
await tester.pump();
486+
checkComposeBoxHintTexts(tester,
487+
topicHintText: eg.defaultRealmEmptyTopicDisplayName,
488+
contentHintText: 'Message #${channel.name} > '
489+
'${eg.defaultRealmEmptyTopicDisplayName}');
490+
});
491+
475492
testWidgets('with non-empty topic', (tester) async {
476493
await prepare(tester, narrow: narrow, mandatoryTopics: false);
477494
await enterTopic(tester, narrow: narrow, topic: 'new topic');

0 commit comments

Comments
 (0)