perf(collection): decode the blurred header backdrop small

Material album, playlist and local album headers decoded their blurred
backdrop at full cover size. It now uses the small decode the track
details backdrop already has. The stretch of the header artwork rebuilds
only while the list is pulled past its start, header title heights are
remembered, the quality the songs of an album share is worked out once
per song list, and the collapsing header reads its expanded height once
per layout change instead of on every scroll report.
This commit is contained in:
zarzet committed 2026-11-21 22:06:24 +07:00
1 parent 6649359075
commit cc0e55b078
7 files changed
+121 -46

No files matched your search

@@ -13,6 +13,7 @@ double collectionHeaderExpandedHeight(BuildContext context) {
mixin CollapsingHeaderScrollMixin<T extends StatefulWidget> on State<T> {
final ScrollController scrollController = ScrollController();
final ValueNotifier<bool> showTitleNotifier = ValueNotifier(false);
double? _cachedExpandedHeight;
@override
void initState() {
@@ -20,6 +21,12 @@ mixin CollapsingHeaderScrollMixin<T extends StatefulWidget> on State<T> {
scrollController.addListener(_onHeaderScroll);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_cachedExpandedHeight = calculateExpandedHeight(context);
}
@override
void dispose() {
scrollController.removeListener(_onHeaderScroll);
@@ -32,7 +39,8 @@ mixin CollapsingHeaderScrollMixin<T extends StatefulWidget> on State<T> {
collectionHeaderExpandedHeight(context);
void _onHeaderScroll() {
final expandedHeight = calculateExpandedHeight(context);
final expandedHeight =
_cachedExpandedHeight ?? calculateExpandedHeight(context);
showTitleNotifier.value =
scrollController.offset > (expandedHeight - kToolbarHeight - 20);
}
+16 -3
View File
@@ -39,6 +39,7 @@ import 'package:mornye/widgets/desktop/detail_header.dart';
import 'package:mornye/widgets/desktop/desktop_selection.dart';
import 'package:mornye/widgets/desktop/track_list_table.dart';
import 'package:mornye/widgets/audio_quality_badges.dart';
import 'package:mornye/widgets/cached_cover_image.dart';
import 'package:mornye/widgets/motion_header_banner.dart';
import 'package:mornye/widgets/track_detail_actions.dart';
import 'package:mornye/widgets/selection_action_button.dart';
@@ -107,6 +108,8 @@ class _AlbumScreenState extends ConsumerState<AlbumScreen>
String? _headerImageUrl;
List<String> _audioTraits = const [];
String? _description;
List<Track>? _commonQualitySource;
Track? _commonQualityCache;
/// Double click and Enter actions of the desktop table rows, by row id.
final Map<String, VoidCallback> _desktopActivations = {};
@@ -297,6 +300,9 @@ class _AlbumScreenState extends ConsumerState<AlbumScreen>
);
Track? _commonQualityTrack(List<Track> tracks) {
if (identical(_commonQualitySource, tracks)) {
return _commonQualityCache;
}
final counts = <(String, bool?), int>{};
for (final track in tracks) {
final signature = _qualitySignature(track);
@@ -305,12 +311,16 @@ class _AlbumScreenState extends ConsumerState<AlbumScreen>
}
// A strict majority avoids choosing an arbitrary baseline for mixed albums.
// Unknown metadata counts towards the total, but never implies a quality.
Track? result;
for (final track in tracks) {
if ((counts[_qualitySignature(track)] ?? 0) > tracks.length / 2) {
return track;
result = track;
break;
}
}
return null;
_commonQualitySource = tracks;
_commonQualityCache = result;
return result;
}
List<Widget> _audioTraitInline({Track? commonQualityTrack}) {
@@ -558,13 +568,16 @@ class _AlbumScreenState extends ConsumerState<AlbumScreen>
final showSquareCover = context.isMornye || !hasMotion;
final expandedHeight = calculateExpandedHeight(context);
final cacheWidth = coverCacheWidthForViewport(context);
final bgCacheWidth = !context.isMornye && showSquareCover
? metadataBackdropCacheExtent(context)
: cacheWidth;
final headerBgUrl =
_headerImageUrl ?? widget.headerImageUrl ?? widget.coverUrl;
Widget headerBgImage() => headerBgUrl != null
? CachedNetworkImage(
imageUrl: highResCoverUrl(headerBgUrl) ?? headerBgUrl,
fit: BoxFit.cover,
memCacheWidth: cacheWidth,
memCacheWidth: bgCacheWidth,
cacheManager: CoverCacheManager.instance,
placeholder: (_, _) => Container(color: colorScheme.surface),
errorWidget: (_, _, _) => Container(color: colorScheme.surface),
+5 -2
View File
@@ -408,17 +408,20 @@ class _DownloadedAlbumScreenState extends ConsumerState<DownloadedAlbumScreen>
: null;
final cacheWidth = coverCacheWidthForViewport(context);
final bgCacheWidth = !context.isMornye
? metadataBackdropCacheExtent(context)
: cacheWidth;
final Widget background = embeddedCoverPath != null
? LocalOrNetworkCoverImage(
url: embeddedCoverPath,
localCacheWidth: cacheWidth,
localCacheWidth: bgCacheWidth,
placeholder: (_) => Container(color: colorScheme.surface),
)
: widget.coverUrl != null
? CachedNetworkImage(
imageUrl: highResCoverUrl(widget.coverUrl) ?? widget.coverUrl!,
fit: BoxFit.cover,
memCacheWidth: cacheWidth,
memCacheWidth: bgCacheWidth,
cacheManager: CoverCacheManager.instance,
placeholder: (_, _) => Container(color: colorScheme.surface),
errorWidget: (_, _, _) => Container(color: colorScheme.surface),
+8 -4
View File
@@ -409,10 +409,13 @@ class _LocalAlbumScreenState extends ConsumerState<LocalAlbumScreen>
: null;
final cacheWidth = coverCacheWidthForViewport(context);
final bgCacheWidth = !context.isMornye
? metadataBackdropCacheExtent(context)
: cacheWidth;
final Widget background = coverPath != null
? LocalOrNetworkCoverImage(
url: coverPath,
localCacheWidth: cacheWidth,
localCacheWidth: bgCacheWidth,
placeholder: (_) => Container(color: colorScheme.surface),
)
: Container(
@@ -972,6 +975,7 @@ class _LocalAlbumScreenState extends ConsumerState<LocalAlbumScreen>
) {
final allSelected =
selectedIds.length == tracks.length && tracks.isNotEmpty;
final selectedUnified = _selectedUnifiedItems(tracks);
return LibraryTrackSelectionBar(
selectedCount: selectedIds.length,
@@ -983,7 +987,7 @@ class _LocalAlbumScreenState extends ConsumerState<LocalAlbumScreen>
bottomPadding: bottomPadding,
albumDelete: true,
playbackActions: LibrarySelectionPlaybackActions(
items: _selectedUnifiedItems(tracks),
items: selectedUnified,
onClose: exitSelectionMode,
),
flacEligibleCount: _selectedFlacEligibleItems(tracks).length,
@@ -992,12 +996,12 @@ class _LocalAlbumScreenState extends ConsumerState<LocalAlbumScreen>
onConvert: () => showBatchConvertSheet(
context,
ref,
_selectedUnifiedItems(tracks),
selectedUnified,
onExitSelectionMode: exitSelectionMode,
),
onReplayGain: ({required remove}) => runBatchReplayGain(
context,
_selectedUnifiedItems(tracks),
selectedUnified,
onExitSelectionMode: exitSelectionMode,
remove: remove,
),
+5 -2
View File
@@ -317,6 +317,9 @@ class _PlaylistScreenState extends ConsumerState<PlaylistScreen>
motionUrl != null &&
motionUrl.trim().isNotEmpty &&
Uri.tryParse(motionUrl)?.hasAuthority == true;
final bgCacheWidth = !context.isMornye && !hasMotion
? metadataBackdropCacheExtent(context)
: cacheWidth;
Widget playlistPlaceholder({double? size}) {
return Container(
color: colorScheme.surfaceContainerHighest,
@@ -332,7 +335,7 @@ class _PlaylistScreenState extends ConsumerState<PlaylistScreen>
? CachedCoverImage(
imageUrl: highResCoverUrl(_coverUrl) ?? _coverUrl!,
fit: BoxFit.cover,
memCacheWidth: cacheWidth,
memCacheWidth: bgCacheWidth,
placeholder: (_, _) => Container(color: colorScheme.surface),
errorWidget: (_, _, _) => Container(color: colorScheme.surface),
)
@@ -500,7 +503,7 @@ class _PlaylistScreenState extends ConsumerState<PlaylistScreen>
final isInHistory = existingHistoryKeys.contains(historyKeys[index]);
// Material joins the rows into one connected list.
return TrackCardSegment.at(
key: ValueKey(track.id),
key: ValueKey(selectionId),
index: index,
count: _tracks.length,
child: slideSelectRow(
+61 -27
View File
@@ -655,40 +655,74 @@ class MornyeActionCapsule extends ConsumerWidget {
}
}
class _AlbumStretchArtwork extends StatelessWidget {
class _AlbumStretchArtwork extends StatefulWidget {
const _AlbumStretchArtwork({required this.child});
final Widget child;
@override
State<_AlbumStretchArtwork> createState() => _AlbumStretchArtworkState();
}
class _AlbumStretchArtworkState extends State<_AlbumStretchArtwork> {
final GlobalKey _artworkKey = GlobalKey();
ScrollPosition? _position;
double _overscroll = 0;
@override
void didChangeDependencies() {
super.didChangeDependencies();
final next = MediaQuery.disableAnimationsOf(context)
? null
: Scrollable.maybeOf(context)?.position;
if (next == _position) return;
_position?.removeListener(_onScroll);
_position = next;
_position?.addListener(_onScroll);
_overscroll = _readOverscroll();
}
double _readOverscroll() {
final position = _position;
if (position == null || !position.hasContentDimensions) return 0;
return (position.minScrollExtent - position.pixels).clamp(
0.0,
double.infinity,
);
}
void _onScroll() {
final next = _readOverscroll();
if (next != _overscroll && mounted) {
setState(() => _overscroll = next);
}
}
@override
void dispose() {
_position?.removeListener(_onScroll);
super.dispose();
}
@override
Widget build(BuildContext context) {
if (MediaQuery.disableAnimationsOf(context)) return child;
final position = Scrollable.of(context).position;
final artwork = RepaintBoundary(key: _artworkKey, child: widget.child);
if (_position == null || _overscroll <= 0) return artwork;
return LayoutBuilder(
builder: (context, constraints) => AnimatedBuilder(
animation: position,
child: RepaintBoundary(child: child),
builder: (context, artwork) {
final overscroll = position.hasContentDimensions
? (position.minScrollExtent - position.pixels).clamp(
0.0,
double.infinity,
)
: 0.0;
final height = constraints.maxHeight;
final scale = height > 0 ? 1 + overscroll / height : 1.0;
// The viewport moves the details down during a pull. Keep the image
// at the top and enlarge it without changing the scrollable layout.
return Transform.translate(
offset: Offset(0, -overscroll),
child: Transform.scale(
scale: scale,
alignment: Alignment.topCenter,
child: artwork,
),
);
},
),
builder: (context, constraints) {
final height = constraints.maxHeight;
final scale = height > 0 ? 1 + _overscroll / height : 1.0;
// The viewport moves the details down during a pull. Keep the image
// at the top and enlarge it without changing the scrollable layout.
return Transform.translate(
offset: Offset(0, -_overscroll),
child: Transform.scale(
scale: scale,
alignment: Alignment.topCenter,
child: artwork,
),
);
},
);
}
}
+17 -7
View File
@@ -68,6 +68,8 @@ class AppSliverHeader extends StatelessWidget {
/// Square slot for [titleTrailing]: a 44pt avatar in a 56pt touch target.
static const double _titleTrailingExtent = 56;
static final _titleLineHeightCache = <Object, double>{};
/// Height of the title's line, which [titleTrailing] centers on. The title
/// inherits the style [FlexibleSpaceBar] gives it under Material 3.
static double _titleLineHeight(
@@ -75,18 +77,26 @@ class AppSliverHeader extends StatelessWidget {
String text,
TextStyle style,
) {
final resolvedStyle = Theme.of(context).textTheme.titleLarge!.merge(style);
final direction = Directionality.of(context);
final scaler = MediaQuery.textScalerOf(context);
final locale = Localizations.maybeLocaleOf(context);
final key = (text, resolvedStyle, direction, scaler, locale);
final cached = _titleLineHeightCache[key];
if (cached != null) return cached;
final painter = TextPainter(
text: TextSpan(
text: text,
style: Theme.of(context).textTheme.titleLarge!.merge(style),
),
textDirection: Directionality.of(context),
textScaler: MediaQuery.textScalerOf(context),
locale: Localizations.maybeLocaleOf(context),
text: TextSpan(text: text, style: resolvedStyle),
textDirection: direction,
textScaler: scaler,
locale: locale,
maxLines: 1,
)..layout();
final height = painter.height;
painter.dispose();
if (_titleLineHeightCache.length >= 32) {
_titleLineHeightCache.remove(_titleLineHeightCache.keys.first);
}
_titleLineHeightCache[key] = height;
return height;
}