mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-26 22:23:51 +01:00
perf(desktop): keep resizes from rebuilding Home and hidden tabs
Home's explore sizing read the whole pane size from its state, so every resize, rail-expand and inspector frame rebuilt the full Home tree. On desktop the card scale is now the constant it always clamps to, the height cap and the empty state read MediaQuery.heightOf, and Material desktop decides tablet type sizes by height alone (its pane is always wider than 600). Library's cover size takes its desktop constant, and wideListInset depends on width only. Material PageView pages now sit in the hidden-tab MediaQuery that Mornye's LazyTabView already used (exported as HiddenTabMediaQuery), so kept-alive hidden tabs keep their last size until they show again. Under reduced motion Flutter's NavigationRail ran its 200 ms extend animation; a rail per state now snaps to its width.
This commit is contained in:
1 parent
976fa106c4
commit
ccd6badec4
9 files changed
+132
-19
No files matched your search
@@ -191,16 +191,30 @@ class _HomeTabState extends ConsumerState<HomeTab>
|
||||
double _exploreCardSize(BuildContext context) {
|
||||
// Six phone-sized cards across an iPad made the feed look like a desktop
|
||||
// page zoomed out. A higher tablet cap gives roughly five generous cards
|
||||
// in portrait while leaving all phone sizes unchanged.
|
||||
final scale = responsiveScale(context: context, min: 0.82, max: 1.32);
|
||||
// in portrait while leaving all phone sizes unchanged. A desktop pane is
|
||||
// always wider than the 515 that reaches the cap, and one shorter than
|
||||
// that takes the height cap below, so desktop skips the size read and
|
||||
// width-only resizes do not rebuild Home.
|
||||
final scale = isDesktopPlatform
|
||||
? 1.32
|
||||
: responsiveScale(context: context, min: 0.82, max: 1.32);
|
||||
final textScale = effectiveTextScale(context);
|
||||
final size = 145 * scale * (1 + (textScale - 1) * 0.12);
|
||||
// Landscape tablets are short: one carousel row should not take over a
|
||||
// third of the screen. Portrait and phone heights never reach this cap.
|
||||
final heightCap = MediaQuery.sizeOf(context).height * 0.24;
|
||||
final heightCap = MediaQuery.heightOf(context) * 0.24;
|
||||
return size < heightCap ? size : heightCap;
|
||||
}
|
||||
|
||||
/// Whether Home takes its tablet type sizes (a shortest side of at least
|
||||
/// 600). A Material desktop pane is always wider than that (an 800 window
|
||||
/// less the collapsed rail, or a 1200 window less the expanded rail and
|
||||
/// the inspector beside it), so only its height counts there.
|
||||
bool _usesTabletSizes(BuildContext context) =>
|
||||
isDesktopPlatform && !context.isMornye
|
||||
? MediaQuery.heightOf(context) >= 600
|
||||
: MediaQuery.sizeOf(context).shortestSide >= 600;
|
||||
|
||||
/// The square artwork of an explore card. Each card pads 6 on both sides,
|
||||
/// so the artwork takes the width that is left rather than the full card.
|
||||
double _exploreCoverSize(BuildContext context) =>
|
||||
@@ -835,7 +849,7 @@ class _HomeTabState extends ConsumerState<HomeTab>
|
||||
final isShowingRecentAccess =
|
||||
_showsSearch &&
|
||||
ref.watch(trackProvider.select((s) => s.isShowingRecentAccess));
|
||||
final screenHeight = MediaQuery.sizeOf(context).height;
|
||||
final screenHeight = MediaQuery.heightOf(context);
|
||||
|
||||
final recentModeRequested =
|
||||
widget.mode == HomeTabMode.search ||
|
||||
|
||||
@@ -8,7 +8,7 @@ extension _HomeTabExploreUI on _HomeTabState {
|
||||
) {
|
||||
final hasGreeting =
|
||||
!context.isMornye && greeting != null && greeting.isNotEmpty;
|
||||
final isTablet = MediaQuery.sizeOf(context).shortestSide >= 600;
|
||||
final isTablet = _usesTabletSizes(context);
|
||||
final sectionOffset = hasGreeting ? 1 : 0;
|
||||
final totalCount = sections.length + sectionOffset + 1;
|
||||
|
||||
@@ -57,7 +57,7 @@ extension _HomeTabExploreUI on _HomeTabState {
|
||||
);
|
||||
}
|
||||
final sectionHeight = _exploreSectionHeight(context);
|
||||
final isTablet = MediaQuery.sizeOf(context).shortestSide >= 600;
|
||||
final isTablet = _usesTabletSizes(context);
|
||||
if (section.isQuickPicks) {
|
||||
return _buildQuickPicksSection(section, colorScheme);
|
||||
}
|
||||
@@ -189,7 +189,7 @@ extension _HomeTabExploreUI on _HomeTabState {
|
||||
ColorScheme colorScheme,
|
||||
) {
|
||||
final isArtist = item.type == 'artist';
|
||||
final isTablet = MediaQuery.sizeOf(context).shortestSide >= 600;
|
||||
final isTablet = _usesTabletSizes(context);
|
||||
final cardSize = _exploreCardSize(context);
|
||||
final coverSize = _exploreCoverSize(context);
|
||||
final iconSize = cardSize * 0.3;
|
||||
|
||||
@@ -1082,7 +1082,12 @@ class _MainShellState extends ConsumerState<MainShell>
|
||||
key: ValueKey('page-$index'),
|
||||
child: TickerMode(
|
||||
enabled: index == _currentIndex,
|
||||
child: observeScroll(tabs[index], index),
|
||||
// Kept-alive hidden pages keep their last size, so
|
||||
// resizes and rail motion rebuild only the page shown.
|
||||
child: HiddenTabMediaQuery(
|
||||
hidden: index != _currentIndex,
|
||||
child: observeScroll(tabs[index], index),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -261,8 +261,11 @@ class _QueueTabState extends ConsumerState<QueueTab> {
|
||||
);
|
||||
|
||||
double _queueCoverSize() {
|
||||
final shortestSide = MediaQuery.sizeOf(context).shortestSide;
|
||||
final scale = (shortestSide / 390).clamp(0.82, 1.0);
|
||||
// A desktop pane's shortest side is always past 390, so desktop skips
|
||||
// the size read and resizes do not rebuild Library through it.
|
||||
final scale = isDesktopPlatform
|
||||
? 1.0
|
||||
: (MediaQuery.sizeOf(context).shortestSide / 390).clamp(0.82, 1.0);
|
||||
final textScale = effectiveTextScale(context);
|
||||
return (56 * scale * (1 + ((textScale - 1) * 0.12))).clamp(46.0, 56.0);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,8 @@ double wideInsetForWidth(
|
||||
/// instead of stretching across a wide window.
|
||||
double wideListInset(BuildContext context, {double? contentMaxWidth}) =>
|
||||
wideInsetForWidth(
|
||||
MediaQuery.sizeOf(context).width,
|
||||
// Width only, so a height change does not rebuild the caller.
|
||||
MediaQuery.widthOf(context),
|
||||
contentMaxWidth:
|
||||
contentMaxWidth ??
|
||||
(isDesktopPlatform
|
||||
|
||||
@@ -603,9 +603,12 @@ class DesktopNavigationRail extends StatelessWidget {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final background = colorScheme.surfaceContainer;
|
||||
if (!materialExpressiveEnabled(context)) {
|
||||
// Reduced motion keeps Flutter's rail; Settings stays last.
|
||||
// Reduced motion keeps Flutter's rail; Settings stays last. A new rail
|
||||
// per state snaps to its width instead of running Flutter's extend
|
||||
// animation, which ignores reduced motion.
|
||||
final index = destinations.indexWhere((d) => d.tab == selected);
|
||||
return NavigationRail(
|
||||
key: ValueKey('desktop-rail-extended:$extended'),
|
||||
extended: extended,
|
||||
minExtendedWidth: desktopSidebarWidth,
|
||||
// Collapsed, the rail shows icons alone.
|
||||
@@ -635,9 +638,11 @@ class DesktopNavigationRail extends StatelessWidget {
|
||||
final settings = destinations
|
||||
.where((destination) => destination.tab == ShellTab.settings)
|
||||
.firstOrNull;
|
||||
// Only reached with expressive motion on; reduced motion takes the
|
||||
// static rail above, so the fallback never animates.
|
||||
final motion = AppMotion.spatial(
|
||||
context,
|
||||
const AppMotionSpec(Duration(milliseconds: 300), Curves.easeInOutCubic),
|
||||
const AppMotionSpec(Duration.zero, Curves.linear),
|
||||
);
|
||||
final openLink = onOpenLibraryLink;
|
||||
// One expansion value drives the width, every pill and every label, so
|
||||
|
||||
@@ -89,7 +89,7 @@ class _LazyTabViewState extends State<LazyTabView> {
|
||||
excluding: index != widget.index,
|
||||
child: TickerMode(
|
||||
enabled: index == widget.index,
|
||||
child: _TabInsets(
|
||||
child: HiddenTabMediaQuery(
|
||||
hidden: index != widget.index,
|
||||
child: _mountedTabs.contains(_tabKey(index))
|
||||
? widget.children[index]
|
||||
@@ -102,18 +102,24 @@ class _LazyTabViewState extends State<LazyTabView> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Keeps hidden tabs at their last visible window size and without a keyboard.
|
||||
class _TabInsets extends StatefulWidget {
|
||||
const _TabInsets({required this.hidden, required this.child});
|
||||
/// Keeps hidden tabs at their last visible window size and without a keyboard,
|
||||
/// so resizes and pane motion rebuild only the tab on screen. A tab gets the
|
||||
/// current size when it shows again.
|
||||
class HiddenTabMediaQuery extends StatefulWidget {
|
||||
const HiddenTabMediaQuery({
|
||||
super.key,
|
||||
required this.hidden,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final bool hidden;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<_TabInsets> createState() => _TabInsetsState();
|
||||
State<HiddenTabMediaQuery> createState() => _HiddenTabMediaQueryState();
|
||||
}
|
||||
|
||||
class _TabInsetsState extends State<_TabInsets> {
|
||||
class _HiddenTabMediaQueryState extends State<HiddenTabMediaQuery> {
|
||||
Size? _visibleSize;
|
||||
|
||||
@override
|
||||
|
||||
@@ -637,6 +637,32 @@ void main() {
|
||||
expect(menuIcon(Icons.menu_open), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('reduced motion snaps the rail open and closed', (
|
||||
tester,
|
||||
) async {
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: true);
|
||||
addTearDown(
|
||||
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
|
||||
);
|
||||
await pumpShell(tester, mornye: false, width: 1400);
|
||||
double railWidth() => tester.getSize(find.byType(NavigationRail)).width;
|
||||
final expanded = railWidth();
|
||||
expect(expanded, greaterThan(desktopCollapsedRailWidth));
|
||||
|
||||
desktopSidebarCollapsed.value = true;
|
||||
await tester.pump();
|
||||
final collapsed = railWidth();
|
||||
expect(collapsed, lessThan(expanded));
|
||||
// Nothing is left to animate.
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(railWidth(), collapsed);
|
||||
|
||||
desktopSidebarCollapsed.value = false;
|
||||
await tester.pump();
|
||||
expect(railWidth(), expanded);
|
||||
});
|
||||
|
||||
testWidgets('narrow windows hide the rail menu button', (tester) async {
|
||||
await pumpShell(tester, mornye: false, width: 900);
|
||||
|
||||
|
||||
@@ -288,6 +288,59 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
/// The widget [type]'s state built last; a new instance means its state
|
||||
/// built again.
|
||||
Widget builtBy(WidgetTester tester, Type type) {
|
||||
late Widget child;
|
||||
tester
|
||||
.element(find.byType(type, skipOffstage: false).first)
|
||||
.visitChildElements((element) => child = element.widget);
|
||||
return child;
|
||||
}
|
||||
|
||||
testWidgets('desktop Material width changes rebuild neither Home nor a '
|
||||
'hidden Library', (tester) async {
|
||||
await pumpShell(tester, desktop: true, mornye: false);
|
||||
ShellNavigationService.requestTab(ShellTab.library);
|
||||
await settle(tester);
|
||||
ShellNavigationService.requestTab(ShellTab.home);
|
||||
await settle(tester);
|
||||
final home = builtBy(tester, HomeTab);
|
||||
final library = builtBy(tester, QueueTab);
|
||||
Size librarySize() => MediaQuery.sizeOf(
|
||||
tester.element(find.byType(QueueTab, skipOffstage: false).first),
|
||||
);
|
||||
final hiddenSize = librarySize();
|
||||
|
||||
// Width-only frames, as in a live edge drag or the rail expanding.
|
||||
for (var frame = 1; frame <= 10; frame++) {
|
||||
tester.view.physicalSize = Size(1280.0 + frame * 12, 800);
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
}
|
||||
await settle(tester);
|
||||
expect(builtBy(tester, HomeTab), same(home));
|
||||
expect(builtBy(tester, QueueTab), same(library));
|
||||
|
||||
// Home follows a height change; the hidden Library keeps its size.
|
||||
tester.view.physicalSize = const Size(1400, 760);
|
||||
await settle(tester);
|
||||
expect(builtBy(tester, HomeTab), isNot(same(home)));
|
||||
expect(builtBy(tester, QueueTab), same(library));
|
||||
expect(librarySize(), hiddenSize);
|
||||
|
||||
// Library takes the new size when it shows again.
|
||||
ShellNavigationService.requestTab(ShellTab.library);
|
||||
await settle(tester);
|
||||
expect(librarySize(), isNot(hiddenSize));
|
||||
expect(
|
||||
librarySize().height,
|
||||
MediaQuery.sizeOf(
|
||||
tester.element(find.byType(HomeTab, skipOffstage: false).first),
|
||||
).height,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a Material rail playlist link fades in like a destination', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in new issue
Block a user