From ad9105c7ebe68f1e8799537342781425c3d6d6cc Mon Sep 17 00:00:00 2001 From: vv Date: Wed, 2 Dec 2026 15:56:47 +0800 Subject: [PATCH] feat: stretch playlist hero cover while pulling to refresh PullToRefresh pushes the whole list down while dragging, so a playlist page showed a blank strip in the page surface colour above the blurred hero cover. Paint the artwork instead: a single backdrop under PullToRefresh, bottom-aligned with the hero and scaled up so its top edge reaches the window top, and hide the hero's own backdrop once that layer takes over so the same cover is never drawn twice at different scales. Sizes are read during layout/draw only, so dragging does not recompose the page. --- .../java/btm/m/auraplayer/ui/LibraryPages.kt | 127 +++++++++++++++++- 1 file changed, 120 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/btm/m/auraplayer/ui/LibraryPages.kt b/app/src/main/java/btm/m/auraplayer/ui/LibraryPages.kt index 4c700b0..6da89f0 100644 --- a/app/src/main/java/btm/m/auraplayer/ui/LibraryPages.kt +++ b/app/src/main/java/btm/m/auraplayer/ui/LibraryPages.kt @@ -50,6 +50,7 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.LayoutCoordinates +import androidx.compose.ui.layout.layout import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.layout.positionInWindow import androidx.compose.ui.platform.LocalContext @@ -1101,6 +1102,75 @@ private fun BlurredPlaylistCoverBackdrop( } } +/** + * Covers the strip that PullToRefresh opens above the playlist hero while the user pulls down. + * + * It lives *under* PullToRefresh so the refresh indicator stays on top, and it paints exactly one + * copy of the artwork: the same blurred cover, bottom-aligned with the hero and scaled up so its + * top edge reaches the window top. `PlaylistHeroHeader` hides its own backdrop as soon as this + * layer is active, so the two never end up drawn together at different scales. + */ +@Composable +private fun PlaylistHeroStretchBackdrop( + coverUri: String, + bannerTheme: HomeBannerTheme, + pageTopWindow: State, + heroTopWindow: State, + heroHeightPx: State, + modifier: Modifier = Modifier, +) { + val heroHeight = heroHeightPx.value + if (heroHeight <= 0f) return + val heroHeightDp = with(LocalDensity.current) { heroHeight.toDp() } + + Box( + modifier + .fillMaxWidth() + .layout { measurable, constraints -> + val gap = (heroTopWindow.value - pageTopWindow.value).coerceAtLeast(0f) + val height = (gap + heroHeight).roundToInt() + .coerceIn(0, constraints.maxHeight) + if (height == 0) { + layout(constraints.maxWidth, 0) {} + } else { + val placeable = measurable.measure( + Constraints.fixed(constraints.maxWidth, height), + ) + layout(constraints.maxWidth, height) { placeable.place(0, 0) } + } + } + .clipToBounds(), + ) { + Box( + Modifier + .fillMaxWidth() + .height(heroHeightDp) + .graphicsLayer { + val gap = (heroTopWindow.value - pageTopWindow.value).coerceAtLeast(0f) + if (gap > 0f && size.height > 0f) { + val scale = (size.height + gap) / size.height + scaleX = scale + scaleY = scale + transformOrigin = TransformOrigin(0.5f, 1f) + translationY = gap + } + }, + ) { + ImmersiveBannerSurfaceBackdrop( + bannerTheme = bannerTheme, + backgroundStyle = HomeBackgroundStyle.COLOR, + modifier = Modifier.matchParentSize(), + ) { + BlurredPlaylistCoverBackdrop( + coverUri = coverUri, + bannerTheme = bannerTheme, + modifier = Modifier.fillMaxSize(), + ) + } + } + } +} + @Composable private fun PlaylistHeroHeader( title: String, @@ -1110,6 +1180,8 @@ private fun PlaylistHeroHeader( immersiveTopPadding: Dp, pageMargin: Dp, playEnabled: Boolean, + pageTopWindow: State, + heroTopWindow: State, onPlay: () -> Unit, onShuffle: () -> Unit, ) { @@ -1129,16 +1201,29 @@ private fun PlaylistHeroHeader( val topPad = immersiveTopPadding + 10.dp Box(Modifier.fillMaxWidth()) { - ImmersiveBannerSurfaceBackdrop( - bannerTheme = bannerTheme, - backgroundStyle = HomeBackgroundStyle.COLOR, - modifier = Modifier.matchParentSize(), + // While PullToRefresh pulls down, PlaylistHeroStretchBackdrop paints the artwork from the + // page top down to the hero's bottom edge. As soon as that layer takes over, step aside + // completely: keeping both copies on screen shows the same cover at two different scales, + // which reads as a doubled, misaligned image right at the seam. + Box( + Modifier + .matchParentSize() + .graphicsLayer { + val gap = heroTopWindow.value - pageTopWindow.value + alpha = if (gap > 0.5f) 0f else 1f + }, ) { - BlurredPlaylistCoverBackdrop( - coverUri = coverUri, + ImmersiveBannerSurfaceBackdrop( bannerTheme = bannerTheme, + backgroundStyle = HomeBackgroundStyle.COLOR, modifier = Modifier.fillMaxSize(), - ) + ) { + BlurredPlaylistCoverBackdrop( + coverUri = coverUri, + bannerTheme = bannerTheme, + modifier = Modifier.fillMaxSize(), + ) + } } Row( modifier = Modifier @@ -1440,6 +1525,12 @@ internal fun CollectionPage( val displayTracks = if (isDraggingOrSettling) orderedTracks else filteredTracks val pullToRefreshState = rememberPullToRefreshState() var isRefreshing by remember(collection.key) { mutableStateOf(false) } + // Window-space anchors for the pull-to-refresh stretch effect. Written during layout and + // read inside PlaylistHeroStretchBackdrop / the hero's graphicsLayer only, so pulling never + // recomposes this page. + val pageTopWindow = remember { mutableFloatStateOf(0f) } + val heroTopWindow = remember { mutableFloatStateOf(0f) } + val heroHeightPx = remember { mutableFloatStateOf(0f) } LaunchedEffect(isRefreshing) { if (!isRefreshing) return@LaunchedEffect @@ -1465,6 +1556,18 @@ internal fun CollectionPage( } } + Box( + Modifier + .fillMaxSize() + .onGloballyPositioned { pageTopWindow.floatValue = it.positionInWindow().y }, + ) { + PlaylistHeroStretchBackdrop( + coverUri = coverUri, + bannerTheme = resolvedTheme, + pageTopWindow = pageTopWindow, + heroTopWindow = heroTopWindow, + heroHeightPx = heroHeightPx, + ) PullToRefresh( isRefreshing = isRefreshing, onRefresh = { if (draggingKey == null) isRefreshing = true }, @@ -1494,6 +1597,12 @@ internal fun CollectionPage( userScrollEnabled = draggingKey == null, ) { item("playlist_hero") { + Box( + Modifier.onGloballyPositioned { coords -> + heroTopWindow.floatValue = coords.positionInWindow().y + heroHeightPx.floatValue = coords.size.height.toFloat() + }, + ) { PlaylistHeroHeader( title = collection.title, coverUri = coverUri, @@ -1502,9 +1611,12 @@ internal fun CollectionPage( immersiveTopPadding = activeTopPadding, pageMargin = pageMargin, playEnabled = displayTracks.isNotEmpty(), + pageTopWindow = pageTopWindow, + heroTopWindow = heroTopWindow, onPlay = { model.playCollection(displayTracks, content = if (filtering) null else cloud) }, onShuffle = { model.playCollection(displayTracks, content = if (filtering) null else cloud, shuffle = true) }, ) + } } if (displayTracks.isEmpty() && (cloud == null || !cloud.loading && !cloud.failed && !cloud.hasMore)) item { Box(Modifier.padding(horizontal = pageMargin)) { EmptyState(tr("no_songs", "没有找到歌曲")) } @@ -1778,6 +1890,7 @@ internal fun CollectionPage( } } } + } if (addToPlaylist && localPlaylist != null) PlaylistSongPicker(model, localPlaylist, onDismissAddToPlaylist) }