diff --git a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx
index c1de515..509b9b9 100644
--- a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx
@@ -135,9 +135,20 @@ export default function AlbumScreen() {
options={{
title: "",
headerLargeTitle: false,
+ ...(Platform.OS === "android"
+ ? {
+ headerStyle: { backgroundColor: palette.background },
+ headerTintColor: palette.foreground,
+ }
+ : {}),
}}
/>
-
+
>
)
}
diff --git a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx
index c5214fc..a6268f2 100644
--- a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx
+++ b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx
@@ -98,9 +98,20 @@ export default function PlaylistScreen() {
options={{
title: "",
headerLargeTitle: false,
+ ...(Platform.OS === "android"
+ ? {
+ headerStyle: { backgroundColor: palette.background },
+ headerTintColor: palette.foreground,
+ }
+ : {}),
}}
/>
-
+
>
)
}
diff --git a/apps/mobile/components/cover-image.tsx b/apps/mobile/components/cover-image.tsx
index d686057..7303894 100644
--- a/apps/mobile/components/cover-image.tsx
+++ b/apps/mobile/components/cover-image.tsx
@@ -2,6 +2,7 @@ import { Ionicons } from "@expo/vector-icons"
import { Image, type ImageContentFit, type ImageStyle } from "expo-image"
import { memo, useMemo } from "react"
import {
+ Platform,
PixelRatio,
StyleProp,
StyleSheet,
@@ -9,6 +10,8 @@ import {
type ViewStyle,
} from "react-native"
+import { prefetchCoverPalette } from "@/hooks/use-cover-palette"
+
import { useThemeColors } from "@/lib/theme"
import {
coverImageSizes,
@@ -106,6 +109,9 @@ export const CoverImage = memo(function CoverImage({
contentFit={contentFit}
transition={150}
blurRadius={blurRadius}
+ onLoad={
+ Platform.OS === "android" ? () => prefetchCoverPalette(uri) : undefined
+ }
cachePolicy="memory-disk"
recyclingKey={sourceUri}
enforceEarlyResizing
diff --git a/apps/mobile/components/skeletons.tsx b/apps/mobile/components/skeletons.tsx
index 6f32141..af12d8f 100644
--- a/apps/mobile/components/skeletons.tsx
+++ b/apps/mobile/components/skeletons.tsx
@@ -198,14 +198,19 @@ export function HomeSkeleton() {
/** Album and playlist pages: cover, title, play buttons, then tracks. */
export function CollectionDetailSkeleton({
round = false,
+ backgroundColor,
+ onLayout,
}: {
round?: boolean
+ backgroundColor?: string
+ onLayout?: () => void
}) {
const colors = useThemeColors()
const coverSize = round ? 180 : 210
return (
(null)
- const palette = screen?.palette ?? null
+ const palette = useFadingPalette(
+ screen?.palette ?? defaultPalette,
+ defaultPalette
+ )
const setPalette = useCallback(
(palette: CoverPalette | null, owner: string) => {
setScreen((current) =>
@@ -88,33 +92,80 @@ export function useAndroidTabSelectedColor() {
return theme?.selectedColor ?? defaultPalette.accentText
}
-/** Keep Android artwork screens and shared bars on the same displayed palette. */
+// Match the default Android medium animation time used by slide_from_right.
+// Continue from displayed colors when artwork arrives late or focus changes.
+const PALETTE_FADE_MS = 400
+
+function useFadingPalette(target: CoverPalette, initial: CoverPalette) {
+ const [displayed, setDisplayed] = useState(initial)
+ const current = useRef(initial)
+ const reducedMotion = useReducedMotion()
+
+ useLayoutEffect(() => {
+ if (Platform.OS !== "android") return
+ if (reducedMotion || current.current === target) {
+ current.current = target
+ setDisplayed(target)
+ return
+ }
+ const from = current.current
+ const progress = new Animated.Value(0)
+ const listener = progress.addListener(({ value }) => {
+ const color = (key: Exclude) =>
+ interpolateColor(value, [0, 1], [from[key], target[key]], "RGB")
+ const next: CoverPalette = {
+ background: color("background"),
+ foreground: color("foreground"),
+ secondaryForeground: color("secondaryForeground"),
+ accent: color("accent"),
+ accentForeground: color("accentForeground"),
+ accentText: color("accentText"),
+ surface: color("surface"),
+ divider: color("divider"),
+ isDark: value < 0.5 ? from.isDark : target.isDark,
+ }
+ current.current = value === 1 ? target : next
+ setDisplayed(current.current)
+ })
+ const animation = Animated.timing(progress, {
+ toValue: 1,
+ duration: PALETTE_FADE_MS,
+ easing: Easing.out(Easing.cubic),
+ useNativeDriver: false,
+ })
+ animation.start()
+ return () => {
+ animation.stop()
+ progress.removeListener(listener)
+ }
+ }, [target, reducedMotion])
+
+ return Platform.OS === "android" ? displayed : target
+}
+
+/** Fade each page independently; shared bars follow the focused page. */
export function useAndroidScreenPalette(palette: CoverPalette) {
const isFocused = useIsFocused()
const owner = useRoute().key
const navigation =
useNavigation>>()
- const [appeared, setAppeared] = useState(false)
- const [leaving, setLeaving] = useState(false)
const [laidOut, setLaidOut] = useState(false)
+ const [closing, setClosing] = useState(false)
const onLayout = useCallback(() => setLaidOut(true), [])
- const theme = useContext(AndroidTabTheme)
- const setPalette = theme?.setPalette
-
useLayoutEffect(() => {
if (Platform.OS !== "android") return
- return navigation.addListener("transitionEnd", ({ data }) => {
- setAppeared(!data.closing)
+ const start = navigation.addListener("transitionStart", ({ data }) => {
+ setClosing(data.closing)
})
+ return start
}, [navigation])
-
- usePreventRemove(Platform.OS === "android" && !leaving, ({ repeat }) => {
- setLeaving(true)
- setPalette?.(null, owner)
- // Let the page and bars paint their shared destination colors before the
- // native stack removes the page. React blur happens too early for this.
- requestAnimationFrame(() => requestAnimationFrame(repeat))
- })
+ const defaultPalette = useDefaultPalette()
+ const theme = useContext(AndroidTabTheme)
+ const setPalette = theme?.setPalette
+ const displayed = useFadingPalette(
+ isFocused && laidOut && !closing ? palette : defaultPalette,
+ defaultPalette
+ )
useLayoutEffect(() => {
if (
@@ -122,16 +173,15 @@ export function useAndroidScreenPalette(palette: CoverPalette) {
!setPalette ||
!isFocused ||
!laidOut ||
- !appeared ||
- leaving
+ closing
)
return
setPalette(palette, owner)
return () => setPalette(null, owner)
- }, [appeared, isFocused, laidOut, leaving, owner, palette, setPalette])
+ }, [closing, laidOut, isFocused, owner, palette, setPalette])
return {
- palette: Platform.OS === "android" && theme ? theme.palette : palette,
+ palette: displayed,
onLayout: Platform.OS === "android" ? onLayout : undefined,
}
}
diff --git a/apps/mobile/hooks/use-cover-palette.ts b/apps/mobile/hooks/use-cover-palette.ts
index 4fd199b..2c9d889 100644
--- a/apps/mobile/hooks/use-cover-palette.ts
+++ b/apps/mobile/hooks/use-cover-palette.ts
@@ -95,6 +95,13 @@ function extractSwatches(key: string) {
return request
}
+/** Warm visible artwork colors before a detail page is pushed. */
+export function prefetchCoverPalette(uri: string) {
+ const key = withCoverImageSize(uri, 64)
+ if (cachedSwatches(key) !== undefined) return
+ void extractSwatches(key)
+}
+
/**
* Colors for a screen tinted by `uri`'s cover art. Extraction runs once per
* cover and is cached on device. Pass `hasCover` as `undefined` while it isn't
@@ -138,7 +145,10 @@ export function useCoverPalette(
// case the cover changed.
const timer =
known === undefined
- ? setTimeout(() => !cancelled && setWaitedKey(key), COVER_PALETTE_WAIT_MS)
+ ? setTimeout(
+ () => !cancelled && setWaitedKey(key),
+ COVER_PALETTE_WAIT_MS
+ )
: null
void extractSwatches(key).then((next) => {
if (!cancelled) show(next ?? known ?? null)
@@ -151,7 +161,9 @@ export function useCoverPalette(
const palette = useMemo(() => {
const fromArt =
- hasCover !== false && swatches ? deriveCoverPalette(swatches, isDark) : null
+ hasCover !== false && swatches
+ ? deriveCoverPalette(swatches, isDark)
+ : null
return fromArt ?? themeCoverPalette(theme, isDark)
}, [hasCover, isDark, swatches, theme])