Skip to content

Commit 0f9aa1a

Browse files
chrisbobbegnprice
andcommitted
compose [nfc]: New helper widget for _ContentInput's typing-notifier logic
This prepares for the edit-message compose box (upcoming), which we'll want to implement without this typing-notifier logic. After this change, we can accomplish that by using _ContentInput without the new helper widget. Co-authored-by: Greg Price <[email protected]>
1 parent e932a05 commit 0f9aa1a

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

lib/widgets/compose_box.dart

+37-15
Original file line numberDiff line numberDiff line change
@@ -394,24 +394,22 @@ class ComposeContentController extends ComposeController<ContentValidationError>
394394
}
395395
}
396396

397-
class _ContentInput extends StatefulWidget {
398-
const _ContentInput({
399-
required this.narrow,
397+
class _TypingNotifier extends StatefulWidget {
398+
const _TypingNotifier({
400399
required this.destination,
401400
required this.controller,
402-
required this.hintText,
401+
required this.child,
403402
});
404403

405-
final Narrow narrow;
406404
final SendableNarrow destination;
407405
final ComposeBoxController controller;
408-
final String hintText;
406+
final Widget child;
409407

410408
@override
411-
State<_ContentInput> createState() => _ContentInputState();
409+
State<_TypingNotifier> createState() => _TypingNotifierState();
412410
}
413411

414-
class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserver {
412+
class _TypingNotifierState extends State<_TypingNotifier> with WidgetsBindingObserver {
415413
@override
416414
void initState() {
417415
super.initState();
@@ -421,7 +419,7 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve
421419
}
422420

423421
@override
424-
void didUpdateWidget(covariant _ContentInput oldWidget) {
422+
void didUpdateWidget(covariant _TypingNotifier oldWidget) {
425423
super.didUpdateWidget(oldWidget);
426424
if (widget.controller != oldWidget.controller) {
427425
oldWidget.controller.content.removeListener(_contentChanged);
@@ -484,6 +482,26 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve
484482
}
485483
}
486484

485+
@override
486+
Widget build(BuildContext context) => widget.child;
487+
}
488+
489+
class _ContentInput extends StatefulWidget {
490+
const _ContentInput({
491+
required this.narrow,
492+
required this.controller,
493+
required this.hintText,
494+
});
495+
496+
final Narrow narrow;
497+
final ComposeBoxController controller;
498+
final String hintText;
499+
500+
@override
501+
State<StatefulWidget> createState() => _ContentInputState();
502+
}
503+
504+
class _ContentInputState<T extends _ContentInput> extends State<T> {
487505
static double maxHeight(BuildContext context) {
488506
final clampingTextScaler = MediaQuery.textScalerOf(context)
489507
.clamp(maxScaleFactor: 1.5);
@@ -645,12 +663,14 @@ class _StreamContentInputState extends State<_StreamContentInput> {
645663
// ignore: dead_null_aware_expression // null topic names soon to be enabled
646664
: '#$streamName > ${hintTopic.displayName ?? store.realmEmptyTopicDisplayName}';
647665

648-
return _ContentInput(
649-
narrow: widget.narrow,
666+
return _TypingNotifier(
650667
destination: TopicNarrow(widget.narrow.streamId,
651668
TopicName(widget.controller.topic.textNormalized)),
652669
controller: widget.controller,
653-
hintText: zulipLocalizations.composeBoxChannelContentHint(hintDestination));
670+
child: _ContentInput(
671+
narrow: widget.narrow,
672+
controller: widget.controller,
673+
hintText: zulipLocalizations.composeBoxChannelContentHint(hintDestination)));
654674
}
655675
}
656676

@@ -732,11 +752,13 @@ class _FixedDestinationContentInput extends StatelessWidget {
732752

733753
@override
734754
Widget build(BuildContext context) {
735-
return _ContentInput(
736-
narrow: narrow,
755+
return _TypingNotifier(
737756
destination: narrow,
738757
controller: controller,
739-
hintText: _hintText(context));
758+
child: _ContentInput(
759+
narrow: narrow,
760+
controller: controller,
761+
hintText: _hintText(context)));
740762
}
741763
}
742764

0 commit comments

Comments
 (0)