diff --git a/lib/widgets/app.dart b/lib/widgets/app.dart index 7091a2a927..6a0d298f7f 100644 --- a/lib/widgets/app.dart +++ b/lib/widgets/app.dart @@ -97,6 +97,8 @@ class ZulipApp extends StatefulWidget { /// Useful in tests. final List? navigatorObservers; + static final routeObserver = RouteObserver>(); + static int _snackBarCount = 0; /// The callback we normally use as [reportErrorToUserBriefly]. @@ -191,7 +193,7 @@ class _ZulipAppState extends State with WidgetsBindingObserver { theme: themeData, navigatorKey: ZulipApp.navigatorKey, - navigatorObservers: widget.navigatorObservers ?? const [], + navigatorObservers: widget.navigatorObservers ?? [ZulipApp.routeObserver], builder: (BuildContext context, Widget? child) { if (!ZulipApp.ready.value) { SchedulerBinding.instance.addPostFrameCallback( diff --git a/lib/widgets/compose_box.dart b/lib/widgets/compose_box.dart index 435af74cd7..8e32c566b2 100644 --- a/lib/widgets/compose_box.dart +++ b/lib/widgets/compose_box.dart @@ -13,6 +13,7 @@ import '../model/binding.dart'; import '../model/compose.dart'; import '../model/narrow.dart'; import '../model/store.dart'; +import 'app.dart'; import 'autocomplete.dart'; import 'dialog.dart'; import 'store.dart'; @@ -288,7 +289,7 @@ class _ContentInput extends StatefulWidget { State<_ContentInput> createState() => _ContentInputState(); } -class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserver { +class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserver, RouteAware { @override void initState() { super.initState(); @@ -297,6 +298,12 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve WidgetsBinding.instance.addObserver(this); } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + ZulipApp.routeObserver.subscribe(this, ModalRoute.of(context)!); + } + @override void didUpdateWidget(covariant _ContentInput oldWidget) { super.didUpdateWidget(oldWidget); @@ -315,6 +322,7 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve widget.controller.removeListener(_contentChanged); widget.focusNode.removeListener(_focusChanged); WidgetsBinding.instance.removeObserver(this); + ZulipApp.routeObserver.unsubscribe(this); super.dispose(); } @@ -333,6 +341,18 @@ class _ContentInputState extends State<_ContentInput> with WidgetsBindingObserve } // Losing focus usually indicates that the user has navigated away // or clicked on other UI elements. + // final store = PerAccountStoreWidget.of(context); + // store.typingNotifier.stoppedComposing(); + } + + @override + void didPop() { + final store = PerAccountStoreWidget.of(context); + store.typingNotifier.stoppedComposing(); + } + + @override + void didPushNext() { final store = PerAccountStoreWidget.of(context); store.typingNotifier.stoppedComposing(); }