Skip to content

Commit 5d57363

Browse files
committed
compose: Change topic input hint text
This is similar to web's behavior. When topics are not mandatory: - an alternative hint text "Enter a topic (skip for “general chat”)" is shown when the topic input has focus; - an opaque placeholder text (e.g.: "general chat") is shown if the user skipped to content input; Because the topic input is always shown in a message list page channel narrow (assuming permission to send messages), this also adds an initial state: - a short hint text, "Topic", is shown if the user hasn't interacted with topic or content inputs at all, or when the user unfocused topic input without moving focus to content input. This only changes the topic input's hint text. See CZO discussion for design details: https://chat.zulip.org/#narrow/channel/530-mobile-design/topic/general.20chat.20design.20.23F1297/near/2106736
1 parent f029b68 commit 5d57363

13 files changed

+266
-10
lines changed

assets/l10n/app_en.arb

+7
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@
379379
"@composeBoxTopicHintText": {
380380
"description": "Hint text for topic input widget in compose box."
381381
},
382+
"composeBoxEnterTopicOrSkipHintText": "Enter a topic (skip for “{defaultTopicName}”)",
383+
"@composeBoxEnterTopicOrSkipHintText": {
384+
"description": "Hint text for topic input widget in compose box when topics are optional.",
385+
"placeholders": {
386+
"defaultTopicName": {"type": "String", "example": "general chat"}
387+
}
388+
},
382389
"composeBoxUploadingFilename": "Uploading {filename}…",
383390
"@composeBoxUploadingFilename": {
384391
"description": "Placeholder in compose box showing the specified file is currently uploading.",

lib/generated/l10n/zulip_localizations.dart

+6
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,12 @@ abstract class ZulipLocalizations {
611611
/// **'Topic'**
612612
String get composeBoxTopicHintText;
613613

614+
/// Hint text for topic input widget in compose box when topics are optional.
615+
///
616+
/// In en, this message translates to:
617+
/// **'Enter a topic (skip for “{defaultTopicName}”)'**
618+
String composeBoxEnterTopicOrSkipHintText(String defaultTopicName);
619+
614620
/// Placeholder in compose box showing the specified file is currently uploading.
615621
///
616622
/// In en, this message translates to:

lib/generated/l10n/zulip_localizations_ar.dart

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
298298
@override
299299
String get composeBoxTopicHintText => 'Topic';
300300

301+
@override
302+
String composeBoxEnterTopicOrSkipHintText(String defaultTopicName) {
303+
return 'Enter a topic (skip for “$defaultTopicName”)';
304+
}
305+
301306
@override
302307
String composeBoxUploadingFilename(String filename) {
303308
return 'Uploading $filename…';

lib/generated/l10n/zulip_localizations_en.dart

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
298298
@override
299299
String get composeBoxTopicHintText => 'Topic';
300300

301+
@override
302+
String composeBoxEnterTopicOrSkipHintText(String defaultTopicName) {
303+
return 'Enter a topic (skip for “$defaultTopicName”)';
304+
}
305+
301306
@override
302307
String composeBoxUploadingFilename(String filename) {
303308
return 'Uploading $filename…';

lib/generated/l10n/zulip_localizations_ja.dart

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
298298
@override
299299
String get composeBoxTopicHintText => 'Topic';
300300

301+
@override
302+
String composeBoxEnterTopicOrSkipHintText(String defaultTopicName) {
303+
return 'Enter a topic (skip for “$defaultTopicName”)';
304+
}
305+
301306
@override
302307
String composeBoxUploadingFilename(String filename) {
303308
return 'Uploading $filename…';

lib/generated/l10n/zulip_localizations_nb.dart

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
298298
@override
299299
String get composeBoxTopicHintText => 'Topic';
300300

301+
@override
302+
String composeBoxEnterTopicOrSkipHintText(String defaultTopicName) {
303+
return 'Enter a topic (skip for “$defaultTopicName”)';
304+
}
305+
301306
@override
302307
String composeBoxUploadingFilename(String filename) {
303308
return 'Uploading $filename…';

lib/generated/l10n/zulip_localizations_pl.dart

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
298298
@override
299299
String get composeBoxTopicHintText => 'Wątek';
300300

301+
@override
302+
String composeBoxEnterTopicOrSkipHintText(String defaultTopicName) {
303+
return 'Enter a topic (skip for “$defaultTopicName”)';
304+
}
305+
301306
@override
302307
String composeBoxUploadingFilename(String filename) {
303308
return 'Przekazywanie $filename…';

lib/generated/l10n/zulip_localizations_ru.dart

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
298298
@override
299299
String get composeBoxTopicHintText => 'Тема';
300300

301+
@override
302+
String composeBoxEnterTopicOrSkipHintText(String defaultTopicName) {
303+
return 'Enter a topic (skip for “$defaultTopicName”)';
304+
}
305+
301306
@override
302307
String composeBoxUploadingFilename(String filename) {
303308
return 'Загрузка $filename…';

lib/generated/l10n/zulip_localizations_sk.dart

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
298298
@override
299299
String get composeBoxTopicHintText => 'Topic';
300300

301+
@override
302+
String composeBoxEnterTopicOrSkipHintText(String defaultTopicName) {
303+
return 'Enter a topic (skip for “$defaultTopicName”)';
304+
}
305+
301306
@override
302307
String composeBoxUploadingFilename(String filename) {
303308
return 'Uploading $filename…';

lib/generated/l10n/zulip_localizations_uk.dart

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ class ZulipLocalizationsUk extends ZulipLocalizations {
298298
@override
299299
String get composeBoxTopicHintText => 'Тема';
300300

301+
@override
302+
String composeBoxEnterTopicOrSkipHintText(String defaultTopicName) {
303+
return 'Enter a topic (skip for “$defaultTopicName”)';
304+
}
305+
301306
@override
302307
String composeBoxUploadingFilename(String filename) {
303308
return 'Завантаження $filename…';

lib/widgets/compose_box.dart

+149-5
Original file line numberDiff line numberDiff line change
@@ -681,16 +681,113 @@ class _TopicInput extends StatefulWidget {
681681
}
682682

683683
class _TopicInputState extends State<_TopicInput> {
684+
void _topicFocusChanged() {
685+
setState(() {
686+
if (widget.controller.topicFocusNode.hasFocus) {
687+
widget.controller.topicInteractionStatus.value =
688+
ComposeTopicInteractionStatus.isEditing;
689+
} else if (!widget.controller.contentFocusNode.hasFocus) {
690+
widget.controller.topicInteractionStatus.value =
691+
ComposeTopicInteractionStatus.notEditingNotChosen;
692+
}
693+
});
694+
}
695+
696+
void _contentFocusChanged() {
697+
setState(() {
698+
if (widget.controller.contentFocusNode.hasFocus) {
699+
widget.controller.topicInteractionStatus.value =
700+
ComposeTopicInteractionStatus.hasChosen;
701+
}
702+
});
703+
}
704+
705+
void _topicInteractionStatusChanged() {
706+
setState(() {
707+
// The actual state lives in widget.controller.topicInteractionStatus
708+
});
709+
}
710+
711+
@override
712+
void initState() {
713+
super.initState();
714+
widget.controller.topicFocusNode.addListener(_topicFocusChanged);
715+
widget.controller.contentFocusNode.addListener(_contentFocusChanged);
716+
widget.controller.topicInteractionStatus.addListener(_topicInteractionStatusChanged);
717+
}
718+
719+
@override
720+
void didUpdateWidget(covariant _TopicInput oldWidget) {
721+
super.didUpdateWidget(oldWidget);
722+
if (oldWidget.controller != widget.controller) {
723+
oldWidget.controller.topicFocusNode.removeListener(_topicFocusChanged);
724+
widget.controller.topicFocusNode.addListener(_topicFocusChanged);
725+
oldWidget.controller.contentFocusNode.removeListener(_contentFocusChanged);
726+
widget.controller.contentFocusNode.addListener(_contentFocusChanged);
727+
oldWidget.controller.topicInteractionStatus.removeListener(_topicInteractionStatusChanged);
728+
widget.controller.topicInteractionStatus.addListener(_topicInteractionStatusChanged);
729+
}
730+
}
731+
732+
@override
733+
void dispose() {
734+
widget.controller.topicFocusNode.removeListener(_topicFocusChanged);
735+
widget.controller.contentFocusNode.removeListener(_contentFocusChanged);
736+
widget.controller.topicInteractionStatus.removeListener(_topicInteractionStatusChanged);
737+
super.dispose();
738+
}
739+
684740
@override
685741
Widget build(BuildContext context) {
686742
final zulipLocalizations = ZulipLocalizations.of(context);
687743
final designVariables = DesignVariables.of(context);
688-
TextStyle topicTextStyle = TextStyle(
744+
final store = PerAccountStoreWidget.of(context);
745+
746+
final topicTextStyle = TextStyle(
689747
fontSize: 20,
690748
height: 22 / 20,
691749
color: designVariables.textInput.withFadedAlpha(0.9),
692750
).merge(weightVariableTextStyle(context, wght: 600));
693751

752+
// TODO(server-10) simplify away
753+
final emptyTopicsSupported = store.zulipFeatureLevel >= 334;
754+
755+
final String hintText;
756+
TextStyle hintStyle = topicTextStyle.copyWith(
757+
color: designVariables.textInput.withFadedAlpha(0.5));
758+
759+
if (store.realmMandatoryTopics) {
760+
// Something short and not distracting.
761+
hintText = zulipLocalizations.composeBoxTopicHintText;
762+
} else {
763+
switch (widget.controller.topicInteractionStatus.value) {
764+
case ComposeTopicInteractionStatus.notEditingNotChosen:
765+
// Something short and not distracting.
766+
hintText = zulipLocalizations.composeBoxTopicHintText;
767+
case ComposeTopicInteractionStatus.isEditing:
768+
// The user is actively interacting with the input. Since topics are
769+
// not mandatory, show a long hint text mentioning that they can be
770+
// left empty.
771+
hintText = zulipLocalizations.composeBoxEnterTopicOrSkipHintText(
772+
emptyTopicsSupported
773+
? store.realmEmptyTopicDisplayName
774+
: kNoTopicTopic);
775+
case ComposeTopicInteractionStatus.hasChosen:
776+
// The topic has likely been chosen. Since topics are not mandatory,
777+
// show the default topic display name as if the user has entered that
778+
// when they left the input empty.
779+
if (emptyTopicsSupported) {
780+
hintText = store.realmEmptyTopicDisplayName;
781+
hintStyle = topicTextStyle.copyWith(fontStyle: FontStyle.italic);
782+
} else {
783+
hintText = kNoTopicTopic;
784+
hintStyle = topicTextStyle;
785+
}
786+
}
787+
}
788+
789+
final decoration = InputDecoration(hintText: hintText, hintStyle: hintStyle);
790+
694791
return TopicAutocomplete(
695792
streamId: widget.streamId,
696793
controller: widget.controller.topic,
@@ -706,10 +803,7 @@ class _TopicInputState extends State<_TopicInput> {
706803
focusNode: widget.controller.topicFocusNode,
707804
textInputAction: TextInputAction.next,
708805
style: topicTextStyle,
709-
decoration: InputDecoration(
710-
hintText: zulipLocalizations.composeBoxTopicHintText,
711-
hintStyle: topicTextStyle.copyWith(
712-
color: designVariables.textInput.withFadedAlpha(0.5))))));
806+
decoration: decoration)));
713807
}
714808
}
715809

@@ -1382,17 +1476,67 @@ sealed class ComposeBoxController {
13821476
}
13831477
}
13841478

1479+
/// Represent how a user has interacted with topic and content inputs.
1480+
///
1481+
/// State-transition diagram:
1482+
///
1483+
/// ```
1484+
/// (default)
1485+
/// Topic input │ Content input
1486+
/// lost focus. ▼ gained focus.
1487+
/// ┌────────────► notEditingNotChosen ────────────┐
1488+
/// │ │ │
1489+
/// │ Topic input │ │
1490+
/// │ gained focus. │ │
1491+
/// │ ◄─────────────────────────┘ ▼
1492+
/// isEditing ◄───────────────────────────── hasChosen
1493+
/// │ Focus moved from ▲ │ ▲
1494+
/// │ content to topic. │ │ │
1495+
/// │ │ │ │
1496+
/// └──────────────────────────────────────┘ └─────┘
1497+
/// Focus moved from Content input loses focus
1498+
/// topic to content. without topic input gaining it.
1499+
/// ```
1500+
///
1501+
/// This state machine offers the following invariants:
1502+
/// - When topic input has focus, the status must be [isEditing].
1503+
/// - When content input has focus, the status must be [hasChosen].
1504+
/// - When neither inputs have focus, and content input was the last
1505+
/// input among the two to be focused, the status must be [hasChosen].
1506+
/// - Otherwise, the status must be [notEditingNotChosen].
1507+
enum ComposeTopicInteractionStatus {
1508+
/// The topic has likely not been chosen if left empty,
1509+
/// and is not being actively edited.
1510+
///
1511+
/// When in this status neither the topic input nor the content input has focus.
1512+
notEditingNotChosen,
1513+
1514+
/// The topic is being actively edited.
1515+
///
1516+
/// When in this status, the topic input must have focus.
1517+
isEditing,
1518+
1519+
/// The topic has likely been chosen, even if it is left empty.
1520+
///
1521+
/// When in this status, the topic input must have no focus;
1522+
/// the content input might have focus.
1523+
hasChosen,
1524+
}
1525+
13851526
class StreamComposeBoxController extends ComposeBoxController {
13861527
StreamComposeBoxController({required PerAccountStore store})
13871528
: topic = ComposeTopicController(store: store);
13881529

13891530
final ComposeTopicController topic;
13901531
final topicFocusNode = FocusNode();
1532+
final ValueNotifier<ComposeTopicInteractionStatus> topicInteractionStatus =
1533+
ValueNotifier(ComposeTopicInteractionStatus.notEditingNotChosen);
13911534

13921535
@override
13931536
void dispose() {
13941537
topic.dispose();
13951538
topicFocusNode.dispose();
1539+
topicInteractionStatus.dispose();
13961540
super.dispose();
13971541
}
13981542
}

test/flutter_checks.dart

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ extension TextStyleChecks on Subject<TextStyle> {
9999
Subject<bool> get inherit => has((t) => t.inherit, 'inherit');
100100
Subject<Color?> get color => has((t) => t.color, 'color');
101101
Subject<double?> get fontSize => has((t) => t.fontSize, 'fontSize');
102+
Subject<FontStyle?> get fontStyle => has((t) => t.fontStyle, 'fontStyle');
102103
Subject<FontWeight?> get fontWeight => has((t) => t.fontWeight, 'fontWeight');
103104
Subject<double?> get letterSpacing => has((t) => t.letterSpacing, 'letterSpacing');
104105
Subject<List<FontVariation>?> get fontVariations => has((t) => t.fontVariations, 'fontVariations');
@@ -170,6 +171,7 @@ extension MaterialChecks on Subject<Material> {
170171

171172
extension InputDecorationChecks on Subject<InputDecoration> {
172173
Subject<String?> get hintText => has((x) => x.hintText, 'hintText');
174+
Subject<TextStyle?> get hintStyle => has((x) => x.hintStyle, 'hintStyle');
173175
}
174176

175177
extension RadioListTileChecks<T> on Subject<RadioListTile<T>> {

0 commit comments

Comments
 (0)