Skip to content

Commit

Permalink
routing wip;
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan James Li <[email protected]>
  • Loading branch information
PIG208 committed Oct 31, 2024
1 parent d59cd87 commit b315b7a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/widgets/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class ZulipApp extends StatefulWidget {
/// Useful in tests.
final List<NavigatorObserver>? navigatorObservers;

static final routeObserver = RouteObserver<ModalRoute<void>>();

static int _snackBarCount = 0;

/// The callback we normally use as [reportErrorToUserBriefly].
Expand Down Expand Up @@ -191,7 +193,7 @@ class _ZulipAppState extends State<ZulipApp> 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(
Expand Down
22 changes: 21 additions & 1 deletion lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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();
}

Expand All @@ -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();
}
Expand Down

0 comments on commit b315b7a

Please sign in to comment.