fix(mobile): tighten Android carousels and themed player borders

This commit is contained in:
joshuafhiggins committed 2026-10-23 19:54:43 -04:00 Verified
1 parent a447c44384
commit 90e9e74a45
3 files changed
+92 -25

No files matched your search

+31 -8
View File
@@ -3,7 +3,9 @@ import { Ionicons } from "@expo/vector-icons"
import { memo, useCallback, type ReactElement } from "react"
import {
FlatList,
Platform,
Pressable,
ScrollView,
StyleSheet,
Text,
View,
@@ -33,6 +35,7 @@ import {
export type MediaItem = BrowseAlbum | BrowseArtist | PlaylistSummary
const GRID_INITIAL_ROWS = 5
const MAX_NON_VIRTUAL_CAROUSEL_ITEMS = 10
export const AlbumCard = memo(function AlbumCard({
album,
@@ -306,14 +309,30 @@ function ContentCarouselBody({
/>
) : null}
</Pressable>
<FlatList
data={content}
keyExtractor={mediaItemKey}
renderItem={renderCarouselItem}
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={styles.carouselContent}
/>
{Platform.OS === "android" &&
content.length <= MAX_NON_VIRTUAL_CAROUSEL_ITEMS ? (
<ScrollView
horizontal
style={styles.androidCarousel}
showsHorizontalScrollIndicator={false}
contentContainerStyle={styles.carouselContent}
>
{content.map((item) => (
<View key={mediaItemKey(item)}>
<CarouselCard item={item} width={carouselCardWidth} />
</View>
))}
</ScrollView>
) : (
<FlatList
data={content}
keyExtractor={mediaItemKey}
renderItem={renderCarouselItem}
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={styles.carouselContent}
/>
)}
</View>
)
}
@@ -343,6 +362,10 @@ const styles = StyleSheet.create({
fontSize: 22,
fontWeight: "700",
},
androidCarousel: {
// Horizontal lists should measure their cards, not stretch the Home sections.
flexGrow: 0,
},
carouselContent: {
gap: spacing.md,
},
+18 -3
View File
@@ -1,4 +1,7 @@
import { useAndroidTabPalette } from "@/contexts/android-tab-theme"
import {
useAndroidTabPalette,
useAndroidTabHasArtworkPalette,
} from "@/contexts/android-tab-theme"
import { Ionicons } from "@expo/vector-icons"
import { NativeTabs } from "expo-router/native-tabs"
import { useRouter } from "expo-router"
@@ -163,12 +166,23 @@ function MiniPlayerContent({
function MiniPlayerChrome({ children }: { children: React.ReactNode }) {
const palette = useAndroidTabPalette()
const hasArtworkPalette = useAndroidTabHasArtworkPalette()
return (
<View style={[styles.androidBar, { backgroundColor: palette.background }]}>
{children}
{hasArtworkPalette ? (
<View
style={[
styles.separator,
styles.topBorder,
{ backgroundColor: palette.secondaryForeground },
]}
/>
) : null}
<View
style={[
styles.separator,
styles.bottomBorder,
{ backgroundColor: palette.secondaryForeground },
]}
@@ -246,14 +260,15 @@ const styles = StyleSheet.create({
androidBar: {
overflow: "hidden",
},
bottomBorder: {
separator: {
position: "absolute",
bottom: 0,
left: 0,
right: 0,
height: 1,
zIndex: 1,
},
topBorder: { top: 0 },
bottomBorder: { bottom: 0 },
content: {
flexDirection: "row",
alignItems: "center",
+43 -14
View File
@@ -1,8 +1,10 @@
import { useFocusEffect } from "expo-router"
import { useIsFocused } from "expo-router"
import {
createContext,
useCallback,
useId,
useContext,
useLayoutEffect,
useMemo,
useState,
type PropsWithChildren,
@@ -15,7 +17,8 @@ import { useIsDark, useThemeColors } from "@/lib/theme"
type TabTheme = {
palette: CoverPalette
selectedColor: string
setPalette: (palette: CoverPalette | null) => void
hasArtworkPalette: boolean
setPalette: (palette: CoverPalette | null, owner: string) => void
}
const AndroidTabTheme = createContext<TabTheme | null>(null)
@@ -27,14 +30,35 @@ function useDefaultPalette() {
export function AndroidTabThemeProvider({ children }: PropsWithChildren) {
const defaultPalette = useDefaultPalette()
const [palette, setPalette] = useState<CoverPalette | null>(null)
const [screen, setScreen] = useState<{
palette: CoverPalette
owner: string
} | null>(null)
const palette = screen?.palette ?? null
const setPalette = useCallback(
(palette: CoverPalette | null, owner: string) => {
setScreen((current) =>
palette ? { palette, owner } : current?.owner === owner ? null : current
)
},
[]
)
const artworkPalette =
palette &&
(palette.background !== defaultPalette.background ||
palette.foreground !== defaultPalette.foreground ||
palette.secondaryForeground !== defaultPalette.secondaryForeground ||
palette.accent !== defaultPalette.accent)
? palette
: null
const value = useMemo(
() => ({
palette: palette ?? defaultPalette,
selectedColor: palette?.foreground ?? defaultPalette.accentText,
palette: artworkPalette ?? defaultPalette,
selectedColor: artworkPalette?.foreground ?? defaultPalette.accentText,
hasArtworkPalette: artworkPalette !== null,
setPalette,
}),
[defaultPalette, palette]
[defaultPalette, artworkPalette, setPalette]
)
return (
<AndroidTabTheme.Provider value={value}>
@@ -49,20 +73,25 @@ export function useAndroidTabPalette() {
return theme?.palette ?? defaultPalette
}
export function useAndroidTabHasArtworkPalette() {
return useContext(AndroidTabTheme)?.hasArtworkPalette ?? false
}
export function useAndroidTabSelectedColor() {
const theme = useContext(AndroidTabTheme)
const defaultPalette = useDefaultPalette()
return theme?.selectedColor ?? defaultPalette.accentText
}
/** Only the focused artwork screen colors Android's shared bottom bars. */
/** Apply the focused screen's colors before paint, including late artwork palettes. */
export function useAndroidScreenPalette(palette: CoverPalette) {
const isFocused = useIsFocused()
const owner = useId()
const setPalette = useContext(AndroidTabTheme)?.setPalette
useFocusEffect(
useCallback(() => {
if (Platform.OS !== "android" || !setPalette) return
setPalette(palette)
return () => setPalette(null)
}, [palette, setPalette])
)
useLayoutEffect(() => {
if (Platform.OS !== "android" || !setPalette || !isFocused) return
setPalette(palette, owner)
return () => setPalette(null, owner)
}, [isFocused, owner, palette, setPalette])
}