mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-21 20:00:49 +01:00
perf(shell): read the keyboard inset without a dependency on back press
The back handler read the insets through MediaQuery.viewInsetsOf on the shell context, so the first back press at a tab root made keyboard frames rebuild the shell again. It now shares the scroll observer's lookup.
This commit is contained in:
1 parent
f4cc5a6131
commit
a155dc5c80
2 files changed
+17
-10
No files matched your search
+10
-10
@@ -505,6 +505,13 @@ class _MainShellState extends ConsumerState<MainShell>
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads the keyboard inset without depending on it, so keyboard frames
|
||||
/// do not rebuild the shell.
|
||||
bool get _keyboardVisible {
|
||||
final media = context.getInheritedWidgetOfExactType<MediaQuery>()!;
|
||||
return media.data.viewInsets.bottom > 0;
|
||||
}
|
||||
|
||||
Future<void> _handleBackPress() async {
|
||||
final rootNavigator = Navigator.of(context, rootNavigator: true);
|
||||
final handledByRootNavigator = await rootNavigator.maybePop();
|
||||
@@ -530,8 +537,6 @@ class _MainShellState extends ConsumerState<MainShell>
|
||||
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<MainShell>
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSearchTab && isKeyboardVisible) {
|
||||
if (isSearchTab && _keyboardVisible) {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
_lastBackPress = null;
|
||||
return;
|
||||
@@ -982,19 +987,14 @@ class _MainShellState extends ConsumerState<MainShell>
|
||||
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<MediaQuery>()!;
|
||||
return media.data.viewInsets.bottom == 0;
|
||||
}
|
||||
|
||||
Widget observeScroll(Widget child, int index) =>
|
||||
NotificationListener<ScrollNotification>(
|
||||
onNotification: (notification) {
|
||||
// The chrome stays expanded while the keyboard is up.
|
||||
if (canMinimizeChrome &&
|
||||
index == _currentIndex &&
|
||||
keyboardHidden()) {
|
||||
!_keyboardVisible) {
|
||||
return _mornyeChrome.handleScroll(notification);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user