From a9c938f8577793dca6e2257ed0e249619a1c2829 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Sat, 24 Oct 2026 00:17:03 -0400 Subject: [PATCH] fix(mobile): synchronize Android artwork and bottom bar colors --- apps/mobile/app/(app)/(tabs)/home/_layout.tsx | 5 ++ .../app/(app)/(tabs)/home/album/[id].tsx | 5 +- .../app/(app)/(tabs)/home/playlist/[id].tsx | 8 ++- .../app/(app)/(tabs)/library/_layout.tsx | 5 ++ .../app/(app)/(tabs)/search/_layout.tsx | 5 ++ apps/mobile/contexts/android-tab-theme.tsx | 54 ++++++++++++++++--- 6 files changed, 71 insertions(+), 11 deletions(-) diff --git a/apps/mobile/app/(app)/(tabs)/home/_layout.tsx b/apps/mobile/app/(app)/(tabs)/home/_layout.tsx index 87b926d..195b95a 100644 --- a/apps/mobile/app/(app)/(tabs)/home/_layout.tsx +++ b/apps/mobile/app/(app)/(tabs)/home/_layout.tsx @@ -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() { ({ ...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" ? () => : undefined, diff --git a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx index 7fb9ae0..9a71030 100644 --- a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx @@ -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() { }} /> { rememberSongs(songs) @@ -148,6 +148,7 @@ export default function PlaylistScreen() { return ( void playlist: BrowsePlaylistDetail songs: BrowseSong[] allSongIds: Id<"songs">[] | undefined @@ -343,6 +346,7 @@ function PlaylistContent({ ) : null} ({ ...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" ? () => : undefined, diff --git a/apps/mobile/app/(app)/(tabs)/search/_layout.tsx b/apps/mobile/app/(app)/(tabs)/search/_layout.tsx index 288328a..dcea4b1 100644 --- a/apps/mobile/app/(app)/(tabs)/search/_layout.tsx +++ b/apps/mobile/app/(app)/(tabs)/search/_layout.tsx @@ -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() { ({ ...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" ? () => : undefined, diff --git a/apps/mobile/contexts/android-tab-theme.tsx b/apps/mobile/contexts/android-tab-theme.tsx index 4cc02ec..791de27 100644 --- a/apps/mobile/contexts/android-tab-theme.tsx +++ b/apps/mobile/contexts/android-tab-theme.tsx @@ -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>>() + 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, + } }