fix(mobile): synchronize Android artwork and bottom bar colors

This commit is contained in:
joshuafhiggins committed 2026-10-24 00:17:03 -04:00 Verified
1 parent 90e9e74a45
commit a9c938f857
6 files changed
+71 -11

No files matched your search

@@ -1,4 +1,5 @@
import { Stack } from "expo-router"
import { Platform } from "react-native"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
@@ -14,6 +15,10 @@ export default function HomeLayout() {
<Stack
screenOptions={({ route }) => ({
...baseOptions,
...(Platform.OS === "android" &&
(route.name === "album/[id]" || route.name === "playlist/[id]")
? { animation: "none" as const }
: {}),
title: tabStackScreenTitles[route.name] ?? "Home",
headerRight:
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
@@ -65,11 +65,11 @@ export default function AlbumScreen() {
const isFocused = useIsFocused()
const coverUri =
config && typeof id === "string" ? albumCoverUrl(config.serverUrl, id) : ""
const { palette, settled } = useCoverPalette(
const { palette: artworkPalette, settled } = useCoverPalette(
coverUri,
album ? album.cover != null : album === null ? false : undefined
)
useAndroidScreenPalette(palette)
const { palette, onLayout } = useAndroidScreenPalette(artworkPalette)
const songIds = useMemo(
() => album?.tracks.map((track) => track.id as Id<"songs">) ?? [],
[album]
@@ -191,6 +191,7 @@ export default function AlbumScreen() {
}}
/>
<FlatList
onLayout={onLayout}
{...longListProps}
data={listItems}
keyExtractor={albumListItemKey}
@@ -99,11 +99,11 @@ export default function PlaylistScreen() {
config && playlistId
? playlistCoverUrl(config.serverUrl, playlist?.id ?? playlistId)
: ""
const { palette, settled } = useCoverPalette(
const { palette: artworkPalette, settled } = useCoverPalette(
coverUri,
playlist ? playlist.cover != null : playlist === null ? false : undefined
)
useAndroidScreenPalette(palette)
const { palette, onLayout } = useAndroidScreenPalette(artworkPalette)
useEffect(() => {
rememberSongs(songs)
@@ -148,6 +148,7 @@ export default function PlaylistScreen() {
return (
<PlaylistContent
onLayout={onLayout}
playlist={playlist}
songs={songs}
allSongIds={allSongIds}
@@ -161,6 +162,7 @@ export default function PlaylistScreen() {
}
function PlaylistContent({
onLayout,
playlist,
songs,
allSongIds,
@@ -168,6 +170,7 @@ function PlaylistContent({
palette,
onEndReached,
}: {
onLayout?: () => void
playlist: BrowsePlaylistDetail
songs: BrowseSong[]
allSongIds: Id<"songs">[] | undefined
@@ -343,6 +346,7 @@ function PlaylistContent({
) : null}
<Stack.Screen options={screenOptions} />
<FlatList
onLayout={onLayout}
{...longListProps}
data={songs}
keyExtractor={songKey}
@@ -1,4 +1,5 @@
import { Stack } from "expo-router"
import { Platform } from "react-native"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
@@ -14,6 +15,10 @@ export default function LibraryLayout() {
<Stack
screenOptions={({ route }) => ({
...baseOptions,
...(Platform.OS === "android" &&
(route.name === "album/[id]" || route.name === "playlist/[id]")
? { animation: "none" as const }
: {}),
title: tabStackScreenTitles[route.name] ?? "Library",
headerRight:
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
@@ -1,4 +1,5 @@
import { Stack } from "expo-router"
import { Platform } from "react-native"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
@@ -14,6 +15,10 @@ export default function SearchLayout() {
<Stack
screenOptions={({ route }) => ({
...baseOptions,
...(Platform.OS === "android" &&
(route.name === "album/[id]" || route.name === "playlist/[id]")
? { animation: "none" as const }
: {}),
title: tabStackScreenTitles[route.name] ?? "Search",
headerRight:
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
+47 -7
View File
@@ -1,8 +1,13 @@
import { useIsFocused } from "expo-router"
import {
useIsFocused,
useNavigation,
usePreventRemove,
useRoute,
type NativeStackNavigationProp,
} from "expo-router"
import {
createContext,
useCallback,
useId,
useContext,
useLayoutEffect,
useMemo,
@@ -83,15 +88,50 @@ export function useAndroidTabSelectedColor() {
return theme?.selectedColor ?? defaultPalette.accentText
}
/** Apply the focused screen's colors before paint, including late artwork palettes. */
/** Keep Android artwork screens and shared bars on the same displayed palette. */
export function useAndroidScreenPalette(palette: CoverPalette) {
const isFocused = useIsFocused()
const owner = useId()
const setPalette = useContext(AndroidTabTheme)?.setPalette
const owner = useRoute().key
const navigation =
useNavigation<NativeStackNavigationProp<Record<string, undefined>>>()
const [appeared, setAppeared] = useState(false)
const [leaving, setLeaving] = useState(false)
const [laidOut, setLaidOut] = useState(false)
const onLayout = useCallback(() => setLaidOut(true), [])
const theme = useContext(AndroidTabTheme)
const setPalette = theme?.setPalette
useLayoutEffect(() => {
if (Platform.OS !== "android" || !setPalette || !isFocused) return
if (Platform.OS !== "android") return
return navigation.addListener("transitionEnd", ({ data }) => {
setAppeared(!data.closing)
})
}, [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))
})
useLayoutEffect(() => {
if (
Platform.OS !== "android" ||
!setPalette ||
!isFocused ||
!laidOut ||
!appeared ||
leaving
)
return
setPalette(palette, owner)
return () => setPalette(null, owner)
}, [isFocused, owner, palette, setPalette])
}, [appeared, isFocused, laidOut, leaving, owner, palette, setPalette])
return {
palette: Platform.OS === "android" && theme ? theme.palette : palette,
onLayout: Platform.OS === "android" ? onLayout : undefined,
}
}