feat: attempt at better album/playlist backgrounds

This commit is contained in:
joshuafhiggins authored and Joshua Higgins committed 2026-08-02 04:14:01 +00:00
1 parent fc2f2d43cb
commit 72bf639672
7 files changed
+717 -210

No files matched your search

+3 -1
View File
@@ -31,7 +31,9 @@
"enableBackgroundPlayback": true
}
],
"expo-sharing"
"expo-sharing",
"expo-font",
"expo-asset"
],
"experiments": {
"typedRoutes": true
@@ -14,6 +14,7 @@ import { contentBottomInset } from "@/components/player"
import { useFavorites } from "@/contexts/favorites"
import { usePlayback } from "@/contexts/playback"
import { useServerConfig } from "@/contexts/server-config"
import { useCoverBackgroundColor } from "@/hooks/use-cover-background-color"
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
import { api } from "@otunes/convex/_generated/api"
import type { Id } from "@otunes/convex/_generated/dataModel"
@@ -36,6 +37,8 @@ export default function AlbumScreen() {
const { isAlbumFavorite, toggleAlbumFavorite, isSongFavorite } = useFavorites()
const { handleAlbumDetailAction, handleAlbumTrackAction, isAlbumFavorite: isAlbumFav } =
useMediaMenuActions()
const coverUri = config && album ? albumCoverUrl(config.serverUrl, album.id) : ""
const backgroundColor = useCoverBackgroundColor(coverUri, album?.cover != null, colors.background)
if (album === undefined || !config) {
return (
@@ -95,13 +98,13 @@ export default function AlbumScreen() {
}}
/>
<ScrollView
style={{ flex: 1, backgroundColor: colors.background }}
style={{ flex: 1, backgroundColor }}
contentContainerStyle={{ paddingBottom: contentBottomInset }}
contentInsetAdjustmentBehavior="automatic"
>
<View style={styles.hero}>
<CoverImage
uri={albumCoverUrl(config.serverUrl, album.id)}
uri={coverUri}
hasCover={album.cover != null}
style={styles.cover}
/>
@@ -192,11 +195,12 @@ const styles = StyleSheet.create({
flexDirection: "row",
alignItems: "center",
gap: spacing.md,
minHeight: 60,
paddingHorizontal: spacing.lg,
paddingVertical: spacing.sm,
paddingVertical: 12,
borderBottomWidth: StyleSheet.hairlineWidth,
},
trackNumber: { width: 24, textAlign: "center" },
trackMeta: { flex: 1, minWidth: 0 },
trackTitle: { fontSize: 15, fontWeight: "500" },
trackTitle: { fontSize: 16, fontWeight: "500" },
})
@@ -11,6 +11,7 @@ import { contentBottomInset, SongRow } from "@/components/player"
import { useFavorites } from "@/contexts/favorites"
import { usePlayback } from "@/contexts/playback"
import { useServerConfig } from "@/contexts/server-config"
import { useCoverBackgroundColor } from "@/hooks/use-cover-background-color"
import { useMediaMenuActions } from "@/hooks/use-media-menu-actions"
import { api } from "@otunes/convex/_generated/api"
import type { Id } from "@otunes/convex/_generated/dataModel"
@@ -34,6 +35,8 @@ export default function PlaylistScreen() {
const unsubscribe = useMutation(api.playlists.unsubscribeFromPlaylist)
const deletePlaylist = useMutation(api.playlists.deletePlaylist)
const removeSongs = useMutation(api.playlists.removeSongsFromPlaylist)
const coverUri = config && playlist ? playlistCoverUrl(config.serverUrl, playlist.id ?? "favorites") : ""
const backgroundColor = useCoverBackgroundColor(coverUri, playlist?.cover != null, colors.background)
if (playlist === undefined || !config) {
return (
@@ -121,13 +124,13 @@ export default function PlaylistScreen() {
}}
/>
<ScrollView
style={{ flex: 1, backgroundColor: colors.background }}
style={{ flex: 1, backgroundColor }}
contentContainerStyle={{ paddingBottom: contentBottomInset }}
contentInsetAdjustmentBehavior="automatic"
>
<View style={styles.hero}>
<CoverImage
uri={playlistCoverUrl(config.serverUrl, playlist.id ?? "favorites")}
uri={coverUri}
hasCover={playlist.cover != null}
style={styles.cover}
/>
+6 -5
View File
@@ -76,8 +76,9 @@ const styles = StyleSheet.create({
row: {
flexDirection: "row",
alignItems: "center",
gap: spacing.sm,
paddingVertical: spacing.sm,
gap: spacing.md,
minHeight: 64,
paddingVertical: 10,
paddingHorizontal: spacing.lg,
borderBottomWidth: StyleSheet.hairlineWidth,
},
@@ -91,12 +92,12 @@ const styles = StyleSheet.create({
minWidth: 0,
},
rowTitle: {
fontSize: 15,
fontSize: 16,
fontWeight: "500",
},
rowSubtitle: {
fontSize: 13,
marginTop: 2,
fontSize: 14,
marginTop: 3,
},
duration: {
fontSize: 12,
@@ -0,0 +1,55 @@
import { useEffect, useState } from "react"
import { getColors, type ImageColorsResult } from "react-native-image-colors"
function prominentColor(result: ImageColorsResult): string {
switch (result.platform) {
case "ios":
return result.primary || result.background
case "android":
return result.vibrant || result.dominant || result.average
case "web":
return result.vibrant || result.dominant
}
}
export function useCoverBackgroundColor(
uri: string,
hasCover: boolean,
fallback: string,
) {
const [backgroundColor, setBackgroundColor] = useState(fallback)
useEffect(() => {
let cancelled = false
if (!hasCover) {
setBackgroundColor(fallback)
return
}
setBackgroundColor(fallback)
void getColors(uri, {
fallback,
cache: true,
key: uri,
quality: "low",
pixelSpacing: 8,
})
.then((result) => {
if (!cancelled) {
setBackgroundColor(prominentColor(result))
}
})
.catch(() => {
if (!cancelled) {
setBackgroundColor(fallback)
}
})
return () => {
cancelled = true
}
}, [fallback, hasCover, uri])
return backgroundColor
}
+8 -4
View File
@@ -13,22 +13,24 @@
},
"dependencies": {
"@convex-dev/auth": "^0.0.93",
"@expo/ui": "~56.0.17",
"@expo/ui": "~56.0.18",
"@expo/vector-icons": "^15.0.2",
"@otunes/convex": "workspace:*",
"@react-native-async-storage/async-storage": "2.2.0",
"@react-native-community/slider": "5.2.0",
"convex": "^1.40.0",
"expo": "~56.0.11",
"expo": "~56.0.12",
"expo-asset": "~56.0.17",
"expo-audio": "^56.0.12",
"expo-blur": "~56.0.3",
"expo-constants": "~56.0.18",
"expo-dev-client": "~56.0.20",
"expo-font": "~56.0.7",
"expo-haptics": "~56.0.3",
"expo-image": "~56.0.11",
"expo-image-picker": "~56.0.17",
"expo-image-picker": "~56.0.18",
"expo-linking": "~56.0.14",
"expo-router": "~56.2.10",
"expo-router": "~56.2.11",
"expo-secure-store": "~56.0.4",
"expo-sharing": "~56.0.18",
"expo-status-bar": "~56.0.4",
@@ -36,10 +38,12 @@
"react": "19.2.3",
"react-native": "0.85.3",
"react-native-gesture-handler": "~2.31.1",
"react-native-image-colors": "^2.6.0",
"react-native-reanimated": "4.3.1",
"react-native-safe-area-context": "~5.7.0",
"react-native-screens": "4.25.2",
"react-native-svg": "15.15.4",
"react-native-worklets": "0.8.3",
"sonner-native": "^0.26.2"
},
"devDependencies": {
+632 -194
View File
File diff suppressed because it is too large. Load diff