feat(mobile): fast fade page transitions on Android

Replace the 400ms slide with a 100ms fade through black, set via app-level
overrides of react-native-screens' fade anim resources.

Clear cached artwork palettes when the artwork color setting changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
joshuafhigginsandClaude Opus 5.5 committed 2026-11-16 21:40:47 -05:00 Verified
1 parent c8216147a6
commit 26ea081db3
7 files changed
+72 -3

No files matched your search

+1
View File
@@ -54,6 +54,7 @@
"expo-status-bar",
"expo-app-intents",
"./plugins/with-android-colors",
"./plugins/with-android-fast-fade",
[
"expo-navigation-bar",
{
@@ -27,6 +27,7 @@ import {
} from "@/lib/artwork-color-preference"
import { initialsFromName } from "@/lib/format"
import { useCachedQuery } from "@/hooks/use-cached-query"
import { clearCoverPaletteCache } from "@/hooks/use-cover-palette"
import { changeServer, signOut } from "@/lib/session"
import { radius, spacing, useThemeColors } from "@/lib/theme"
import { showError } from "@/lib/toast"
@@ -186,6 +187,7 @@ function AppearanceSection() {
setSaving(true)
try {
await setArtworkColorsEnabled(checked)
clearCoverPaletteCache()
} catch {
showError("Could not save artwork colors preference.")
} finally {
+15 -1
View File
@@ -3,7 +3,11 @@ import {
artworkColorsEnabled,
useArtworkColorsEnabled,
} from "@/lib/artwork-color-preference"
import { prefetchLegacyCoverPalette, useLegacyCoverPalette } from "@/hooks/use-legacy-cover-palette"
import {
clearLegacyCoverPaletteCache,
prefetchLegacyCoverPalette,
useLegacyCoverPalette,
} from "@/hooks/use-legacy-cover-palette"
import { extractCoverSwatches } from "@/lib/artwork-colors"
import {
@@ -55,6 +59,16 @@ function extractSwatches(key: string) {
return request
}
/**
* Forget every extracted palette, in memory and on device, so covers are
* re-extracted. Both algorithms share the `palette:` cache prefix.
*/
export function clearCoverPaletteCache() {
swatchesByKey.clear()
pending.clear()
clearLegacyCoverPaletteCache()
}
/** Warm visible artwork colors before a detail page is pushed. */
export function prefetchCoverPalette(uri: string) {
if (!artworkColorsEnabled()) {
@@ -6,7 +6,7 @@ import {
type CoverPalette,
} from "@/lib/cover-palette"
import { deriveCoverPalette, type LegacyCoverSwatches as CoverSwatches } from "@/lib/legacy-cover-palette"
import { readCache, writeCache } from "@/lib/persistent-cache"
import { clearCachePrefix, readCache, writeCache } from "@/lib/persistent-cache"
import { useIsDark, useThemeColors } from "@/lib/theme"
import { withCoverImageSize } from "@/lib/urls"
@@ -99,6 +99,13 @@ function extractSwatches(key: string) {
}
/** Warm visible artwork colors before a detail page is pushed. */
/** Forget extracted legacy swatches, in memory and on device. */
export function clearLegacyCoverPaletteCache() {
swatchesByKey.clear()
pending.clear()
clearCachePrefix("palette")
}
export function prefetchLegacyCoverPalette(uri: string) {
const key = withCoverImageSize(uri, 64)
if (cachedSwatches(key) !== undefined) return
+1 -1
View File
@@ -28,7 +28,7 @@ export function useStackScreenOptions(
headerBackButtonDisplayMode: "minimal",
...(Platform.OS === "android"
? {
animation: "slide_from_right",
animation: "fade",
headerLargeTitle: false,
headerTransparent: false,
headerStyle: { backgroundColor: theme.background },
@@ -0,0 +1,36 @@
const fs = require("fs")
const path = require("path")
const { withDangerousMod } = require("expo/config-plugins")
// Overrides react-native-screens' 150ms crossfade for `animation: "fade"`.
// App resources win over library resources with the same name, so the stack
// fades through black in 100ms: the old page out, then the new page in.
const anims = {
"rns_fade_out.xml": `<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="50" />
`,
"rns_fade_in.xml": `<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:startOffset="50"
android:duration="50" />
`,
}
module.exports = (config) =>
withDangerousMod(config, [
"android",
(config) => {
const dir = path.join(
config.modRequest.platformProjectRoot,
"app/src/main/res/anim"
)
fs.mkdirSync(dir, { recursive: true })
for (const [name, xml] of Object.entries(anims)) {
fs.writeFileSync(path.join(dir, name), `<?xml version="1.0" encoding="utf-8"?>\n${xml}`)
}
return config
},
])
@@ -198,6 +198,15 @@ export async function clearPersistentCache() {
}
}
/** Deletes every entry whose key starts with `<prefix>:`. */
export function clearCachePrefix(prefix: string) {
for (const key of [...memory.keys()]) {
if (entryPrefix(key) !== prefix) continue
removeFromMemory(key)
scheduleWrite(key, null)
}
}
export function subscribeCache(key: string, listener: () => void) {
let keyListeners = listeners.get(key)
if (!keyListeners) {