diff --git a/lib/screens/main_shell.dart b/lib/screens/main_shell.dart index 70924316e..182a71bd0 100644 --- a/lib/screens/main_shell.dart +++ b/lib/screens/main_shell.dart @@ -505,6 +505,13 @@ class _MainShellState extends ConsumerState } } + /// Reads the keyboard inset without depending on it, so keyboard frames + /// do not rebuild the shell. + bool get _keyboardVisible { + final media = context.getInheritedWidgetOfExactType()!; + return media.data.viewInsets.bottom > 0; + } + Future _handleBackPress() async { final rootNavigator = Navigator.of(context, rootNavigator: true); final handledByRootNavigator = await rootNavigator.maybePop(); @@ -530,8 +537,6 @@ class _MainShellState extends ConsumerState final isSearchTab = _currentIndex == (context.isMornye ? (showStore ? 3 : 2) : 0); - final isKeyboardVisible = MediaQuery.viewInsetsOf(context).bottom > 0; - if (isSearchTab && trackState.isShowingRecentAccess && !trackState.isLoading && @@ -562,7 +567,7 @@ class _MainShellState extends ConsumerState return; } - if (isSearchTab && isKeyboardVisible) { + if (isSearchTab && _keyboardVisible) { FocusManager.instance.primaryFocus?.unfocus(); _lastBackPress = null; return; @@ -982,19 +987,14 @@ class _MainShellState extends ConsumerState context.isMornye && !useNavigationRail && MediaQuery.textScalerOf(context).scale(15) <= 20; - // The chrome stays expanded while the keyboard is up. The shell reads the - // insets without depending on them, so keyboard frames do not rebuild it. - bool keyboardHidden() { - final media = context.getInheritedWidgetOfExactType()!; - return media.data.viewInsets.bottom == 0; - } Widget observeScroll(Widget child, int index) => NotificationListener( onNotification: (notification) { + // The chrome stays expanded while the keyboard is up. if (canMinimizeChrome && index == _currentIndex && - keyboardHidden()) { + !_keyboardVisible) { return _mornyeChrome.handleScroll(notification); } return false; diff --git a/test/main_shell_keyboard_test.dart b/test/main_shell_keyboard_test.dart index 9d23b6295..482de48c8 100644 --- a/test/main_shell_keyboard_test.dart +++ b/test/main_shell_keyboard_test.dart @@ -95,6 +95,10 @@ void main() { ) async { await pumpShell(tester); expect(languageTags, ['en']); + // A back press at a tab root checks the keyboard too. + await tester.binding.handlePopRoute(); + await tester.pump(); + expect(find.text('Press back again to exit'), findsOneWidget); final homeTab = find.byKey(const ValueKey('tab-home')).first; final tabs = tester.widget(homeTab); @@ -106,6 +110,9 @@ void main() { expect(languageTags, ['en']); // The shell did not rebuild its tab navigators. expect(tester.widget(homeTab), same(tabs)); + // Lets the back press snack bar time out. + await tester.pump(const Duration(seconds: 3)); + await tester.pump(const Duration(seconds: 1)); expect(tester.takeException(), isNull); });