Compare commits

...
29 changed files with 580 additions and 195 deletions

No files matched your search

+3 -2
View File
@@ -19,9 +19,10 @@ export default ({ config }: ConfigContext): ExpoConfig => {
: variant === "preview"
? " (Preview)"
: ""
// Expo writes this filename into Xcode build settings without quoting it.
const composer = {
development: "oTunes Dev",
preview: "oTunes Preview",
development: "oTunesDev",
preview: "oTunesPreview",
production: "oTunes",
}[variant]
+33 -11
View File
@@ -1,12 +1,14 @@
import Animated from "react-native-reanimated"
import { NavigationBar } from "expo-navigation-bar"
import {
AndroidTabThemeProvider,
useAndroidTabPalette,
useAndroidTabSelectedColor,
useAndroidTabBackgroundStyle,
useAndroidNativeTabColors,
} from "@/contexts/android-tab-theme"
import { DarkTheme, DefaultTheme, ThemeProvider } from "expo-router"
import { NativeTabs } from "expo-router/native-tabs"
import { DynamicColorIOS, Platform, View } from "react-native"
import { DynamicColorIOS, Platform } from "react-native"
import { useMemo } from "react"
import { AndroidMiniPlayer, TabBottomAccessory } from "@/components/mini-player"
@@ -41,10 +43,12 @@ function useRouterTheme() {
}
function useNativeTabColors() {
const selectedColor = useAndroidTabSelectedColor()
// These props initialize native tabs; the worklet owns subsequent colors.
const selectedColor = colors.dark.primary
const themeIsDark = useIsDark()
const androidPalette = useAndroidTabPalette()
const isDark = Platform.OS === "android" ? androidPalette.isDark : themeIsDark
const androidPalette = colors.dark
const artworkPalette = useAndroidTabPalette()
const isDark = Platform.OS === "android" ? artworkPalette.isDark : themeIsDark
const inactive = appleMusic.tabInactive
const iconColor =
@@ -54,14 +58,14 @@ function useNativeTabColors() {
selected: appleMusic.pink,
}
: {
default: androidPalette.secondaryForeground,
default: androidPalette.mutedForeground,
selected: selectedColor,
}
const labelColor =
Platform.OS === "ios"
? DynamicColorIOS({ dark: inactive, light: "#636366" })
: androidPalette.secondaryForeground
: androidPalette.mutedForeground
return {
isDark,
@@ -78,15 +82,19 @@ function useNativeTabColors() {
blurEffect: isDark
? "systemChromeMaterialDark"
: "systemChromeMaterialLight",
backgroundColor:
Platform.OS === "ios" ? undefined : androidPalette.background,
// Reveal the shared UI-thread background beneath the native tab bar.
backgroundColor: Platform.OS === "ios" ? undefined : "transparent",
}
}
function TabsContent() {
const homeColors = useAndroidNativeTabColors()
const libraryColors = useAndroidNativeTabColors()
const searchColors = useAndroidNativeTabColors()
const keyboardVisible = useAndroidKeyboardVisible()
const routerTheme = useRouterTheme()
const tabColors = useNativeTabColors()
const backgroundStyle = useAndroidTabBackgroundStyle()
const { currentSong, queueSongIds } = usePlaybackQueue()
const showBottomAccessory = Boolean(currentSong && queueSongIds.length > 0)
@@ -101,7 +109,12 @@ function TabsContent() {
return (
<ThemeProvider value={routerTheme}>
<View style={{ flex: 1 }}>
<Animated.View
style={[
{ flex: 1 },
Platform.OS === "android" ? backgroundStyle : undefined,
]}
>
{Platform.OS === "android" ? (
<NavigationBar style={tabColors.isDark ? "light" : "dark"} />
) : null}
@@ -127,6 +140,9 @@ function TabsContent() {
<NativeTabs.Trigger
name="home"
unstable_nativeProps={
Platform.OS === "android" ? homeColors : undefined
}
disableTransparentOnScrollEdge
contentStyle={androidContentStyle}
>
@@ -136,6 +152,9 @@ function TabsContent() {
<NativeTabs.Trigger
name="library"
unstable_nativeProps={
Platform.OS === "android" ? libraryColors : undefined
}
disableTransparentOnScrollEdge
contentStyle={androidContentStyle}
>
@@ -148,6 +167,9 @@ function TabsContent() {
<NativeTabs.Trigger
name="search"
unstable_nativeProps={
Platform.OS === "android" ? searchColors : undefined
}
disableTransparentOnScrollEdge
contentStyle={androidContentStyle}
>
@@ -156,7 +178,7 @@ function TabsContent() {
</NativeTabs.Trigger>
</NativeTabs>
{!keyboardVisible ? <AndroidMiniPlayer /> : null}
</View>
</Animated.View>
</ThemeProvider>
)
}
@@ -1,5 +1,4 @@
import { Stack } from "expo-router"
import { Platform } from "react-native"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
@@ -15,10 +14,6 @@ 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,
@@ -1,17 +1,18 @@
import { useAndroidScreenPalette } from "@/contexts/android-tab-theme"
import {
PaletteText,
PaletteIcon,
renderArtworkBackButton,
} from "@/components/palette-text"
import Animated from "react-native-reanimated"
import {
renderAndroidArtworkBackground,
useAndroidScreenPalette,
} from "@/contexts/android-tab-theme"
import { MusicEntityView } from "@/components/music-entity-view"
import { Stack, useIsFocused, useLocalSearchParams } from "expo-router"
import { StatusBar } from "expo-status-bar"
import { memo, useCallback, useEffect, useMemo } from "react"
import {
FlatList,
Platform,
Pressable,
StyleSheet,
Text,
View,
} from "react-native"
import { Ionicons } from "@expo/vector-icons"
import { Platform, Pressable, StyleSheet, View } from "react-native"
import {
CollectionDivider,
@@ -70,7 +71,8 @@ export default function AlbumScreen() {
coverUri,
album ? album.cover != null : album === null ? false : undefined
)
const { palette, onLayout } = useAndroidScreenPalette(artworkPalette)
const { palette, onLayout, backgroundStyle } =
useAndroidScreenPalette(artworkPalette)
const songIds = useMemo(
() => album?.tracks.map((track) => track.id as Id<"songs">) ?? [],
[album]
@@ -135,9 +137,24 @@ export default function AlbumScreen() {
options={{
title: "",
headerLargeTitle: false,
...(Platform.OS === "android"
? {
headerStyle: { backgroundColor: "transparent" },
headerBackground: renderAndroidArtworkBackground,
headerBackVisible: false,
headerLeft: renderArtworkBackButton,
headerTintColor: palette.foreground,
}
: {}),
}}
/>
<CollectionDetailSkeleton />
<CollectionDetailSkeleton
onLayout={onLayout}
style={backgroundStyle}
backgroundColor={
Platform.OS === "android" ? palette.background : undefined
}
/>
</>
)
}
@@ -152,9 +169,9 @@ export default function AlbumScreen() {
}}
/>
<View style={[styles.empty, { backgroundColor: colors.background }]}>
<Text style={{ color: colors.mutedForeground }}>
<PaletteText style={{ color: colors.mutedForeground }}>
Album not found.
</Text>
</PaletteText>
</View>
</>
)
@@ -175,7 +192,10 @@ export default function AlbumScreen() {
headerTintColor: palette.foreground,
...(Platform.OS === "android"
? {
headerStyle: { backgroundColor: palette.background },
headerStyle: { backgroundColor: "transparent" },
headerBackground: renderAndroidArtworkBackground,
headerBackVisible: false,
headerLeft: renderArtworkBackButton,
statusBarStyle: palette.isDark
? ("light" as const)
: ("dark" as const),
@@ -197,7 +217,8 @@ export default function AlbumScreen() {
}
>
<Pressable hitSlop={8}>
<Ionicons
<PaletteIcon
tone="foreground"
name="ellipsis-horizontal"
size={22}
color={palette.isDark ? "#fff" : "#000"}
@@ -207,12 +228,15 @@ export default function AlbumScreen() {
),
}}
/>
<FlatList
<Animated.FlatList
onLayout={onLayout}
{...longListProps}
data={listItems}
keyExtractor={albumListItemKey}
style={{ flex: 1, backgroundColor: palette.background }}
style={[
{ flex: 1, backgroundColor: palette.background },
backgroundStyle,
]}
contentContainerStyle={{ paddingBottom: contentBottomInset }}
contentInsetAdjustmentBehavior="automatic"
indicatorStyle={palette.isDark ? "white" : "black"}
@@ -224,16 +248,22 @@ export default function AlbumScreen() {
hasCover={album.cover != null}
style={styles.cover}
/>
<Text style={[styles.title, { color: palette.foreground }]}>
<PaletteText
tone="foreground"
style={[styles.title, { color: palette.foreground }]}
>
{album.title}
</Text>
</PaletteText>
<Pressable
onPress={() => push(`/artist/${album.artist.id}`)}
style={styles.artistPressable}
>
<Text style={[styles.artist, { color: palette.accentText }]}>
<PaletteText
tone="accentText"
style={[styles.artist, { color: palette.accentText }]}
>
{album.artist.name}
</Text>
</PaletteText>
</Pressable>
<View
style={{
@@ -245,18 +275,25 @@ export default function AlbumScreen() {
}}
>
{metadata ? (
<Text style={{ color: palette.secondaryForeground }}>
<PaletteText
tone="secondaryForeground"
style={{ color: palette.secondaryForeground }}
>
{metadata}
</Text>
</PaletteText>
) : null}
{hasLossless ? (
<>
{metadata ? (
<Text style={{ color: palette.secondaryForeground }}>
<PaletteText
tone="secondaryForeground"
style={{ color: palette.secondaryForeground }}
>
·
</Text>
</PaletteText>
) : null}
<AudioFormatBadge
artwork
format="lossless"
color={palette.secondaryForeground}
backgroundColor={palette.background}
@@ -266,11 +303,15 @@ export default function AlbumScreen() {
{hasAtmos ? (
<>
{metadata || hasLossless ? (
<Text style={{ color: palette.secondaryForeground }}>
<PaletteText
tone="secondaryForeground"
style={{ color: palette.secondaryForeground }}
>
·
</Text>
</PaletteText>
) : null}
<AudioFormatBadge
artwork
format="atmos"
color={palette.secondaryForeground}
backgroundColor={palette.background}
@@ -287,7 +328,8 @@ export default function AlbumScreen() {
{ backgroundColor: palette.surface },
]}
>
<Ionicons
<PaletteIcon
tone={favorited ? "accent" : "foreground"}
name={favorited ? "star" : "star-outline"}
size={24}
color={favorited ? palette.accent : palette.foreground}
@@ -313,7 +355,8 @@ export default function AlbumScreen() {
{ backgroundColor: palette.surface },
]}
>
<Ionicons
<PaletteIcon
tone="foreground"
name="shuffle"
size={24}
color={palette.foreground}
@@ -415,11 +458,12 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
style={styles.trackRow}
onPress={() => void onPlay(track.id as Id<"songs">, songIds)}
>
<Text
<PaletteText
tone="secondaryForeground"
style={[styles.trackNumber, { color: palette.secondaryForeground }]}
>
{number}
</Text>
</PaletteText>
<View
style={[
styles.trackContent,
@@ -427,24 +471,29 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
]}
>
<View style={styles.trackMeta}>
<Text
<PaletteText
tone="foreground"
style={[styles.trackTitle, { color: palette.foreground }]}
numberOfLines={1}
>
{track.title}
</Text>
</PaletteText>
{track.artists ? (
<Text
<PaletteText
tone="secondaryForeground"
style={{ color: palette.secondaryForeground }}
numberOfLines={1}
>
{track.artists.join(", ")}
</Text>
</PaletteText>
) : null}
</View>
<Text style={{ color: palette.secondaryForeground }}>
<PaletteText
tone="secondaryForeground"
style={{ color: palette.secondaryForeground }}
>
{formatDuration(track.durationSeconds)}
</Text>
</PaletteText>
</View>
</Pressable>
</MusicEntityView>
@@ -1,8 +1,17 @@
import {
PaletteText,
PaletteIcon,
renderArtworkBackButton,
} from "@/components/palette-text"
import Animated from "react-native-reanimated"
import {
PlaylistSearchBar,
usePlaylistSearch,
} from "@/components/playlist-search-bar"
import { useAndroidScreenPalette } from "@/contexts/android-tab-theme"
import {
renderAndroidArtworkBackground,
useAndroidScreenPalette,
} from "@/contexts/android-tab-theme"
import { MusicEntityView } from "@/components/music-entity-view"
import { useMutation } from "convex/react"
import { memo, useCallback, useEffect, useMemo } from "react"
@@ -14,16 +23,13 @@ import {
} from "expo-router"
import { StatusBar } from "expo-status-bar"
import {
FlatList,
Platform,
Pressable,
StyleSheet,
Text,
View,
type ListRenderItemInfo,
} from "react-native"
import ReanimatedSwipeable from "react-native-gesture-handler/ReanimatedSwipeable"
import { Ionicons } from "@expo/vector-icons"
import { CollectionDivider } from "@/components/collection-list"
import { CoverImage } from "@/components/cover-image"
@@ -85,7 +91,8 @@ export default function PlaylistScreen() {
coverUri,
playlist ? playlist.cover != null : playlist === null ? false : undefined
)
const { palette, onLayout } = useAndroidScreenPalette(artworkPalette)
const { palette, onLayout, backgroundStyle } =
useAndroidScreenPalette(artworkPalette)
useEffect(() => {
if (songs) rememberSongs(songs)
@@ -98,9 +105,24 @@ export default function PlaylistScreen() {
options={{
title: "",
headerLargeTitle: false,
...(Platform.OS === "android"
? {
headerStyle: { backgroundColor: "transparent" },
headerBackground: renderAndroidArtworkBackground,
headerBackVisible: false,
headerLeft: renderArtworkBackButton,
headerTintColor: palette.foreground,
}
: {}),
}}
/>
<CollectionDetailSkeleton />
<CollectionDetailSkeleton
onLayout={onLayout}
style={backgroundStyle}
backgroundColor={
Platform.OS === "android" ? palette.background : undefined
}
/>
</>
)
}
@@ -115,9 +137,9 @@ export default function PlaylistScreen() {
}}
/>
<View style={[styles.empty, { backgroundColor: colors.background }]}>
<Text style={{ color: colors.mutedForeground }}>
<PaletteText style={{ color: colors.mutedForeground }}>
Playlist not found.
</Text>
</PaletteText>
</View>
</>
)
@@ -125,6 +147,7 @@ export default function PlaylistScreen() {
return (
<PlaylistContent
backgroundStyle={backgroundStyle}
onLayout={onLayout}
playlist={playlist}
songs={playlist.songs}
@@ -135,6 +158,7 @@ export default function PlaylistScreen() {
}
function PlaylistContent({
backgroundStyle,
onLayout,
playlist,
songs,
@@ -142,6 +166,7 @@ function PlaylistContent({
palette,
}: {
onLayout?: () => void
backgroundStyle: ReturnType<typeof useAndroidScreenPalette>["backgroundStyle"]
playlist: BrowsePlaylistDetail
songs: BrowseSong[]
coverUri: string
@@ -247,7 +272,10 @@ function PlaylistContent({
headerTintColor: palette.foreground,
...(Platform.OS === "android"
? {
headerStyle: { backgroundColor: palette.background },
headerStyle: { backgroundColor: "transparent" },
headerBackground: renderAndroidArtworkBackground,
headerBackVisible: false,
headerLeft: renderArtworkBackButton,
statusBarStyle: palette.isDark
? ("light" as const)
: ("dark" as const),
@@ -266,7 +294,8 @@ function PlaylistContent({
onAction={handlePlaylistMenuAction}
>
<Pressable hitSlop={8}>
<Ionicons
<PaletteIcon
tone="foreground"
name="ellipsis-horizontal"
size={22}
color={palette.isDark ? "#fff" : "#000"}
@@ -322,26 +351,30 @@ function PlaylistContent({
onQueryChange={onQueryChange}
onSearchSubmit={onSearchSubmit}
/>
<FlatList
<Animated.FlatList
onLayout={onLayout}
{...longListProps}
data={filteredSongs}
keyExtractor={songKey}
renderItem={renderItem}
style={{ flex: 1, backgroundColor: palette.background }}
style={[
{ flex: 1, backgroundColor: palette.background },
backgroundStyle,
]}
indicatorStyle={palette.isDark ? "white" : "black"}
contentContainerStyle={styles.listContent}
contentInsetAdjustmentBehavior="automatic"
onScrollBeginDrag={swipeGroup.closeOpenRow}
ListEmptyComponent={
<Text
<PaletteText
tone="secondaryForeground"
style={[
styles.emptyResults,
{ color: palette.secondaryForeground },
]}
>
{songs.length ? "No songs found." : "No songs in this playlist."}
</Text>
</PaletteText>
}
ListHeaderComponent={
<PlaylistHero
@@ -435,15 +468,19 @@ const PlaylistSongRow = memo(function PlaylistSongRow({
}}
style={[styles.removeAction, { backgroundColor: colors.destructive }]}
>
<Ionicons name="trash" size={22} color={colors.primaryForeground} />
<Text
<PaletteIcon
name="trash"
size={22}
color={colors.primaryForeground}
/>
<PaletteText
style={[
styles.removeActionText,
{ color: colors.primaryForeground },
]}
>
Remove
</Text>
</PaletteText>
</Pressable>
)}
>
@@ -481,10 +518,18 @@ const PlaylistHero = memo(function PlaylistHero({
<MusicEntityView kind="playlist" id={entityId}>
<View style={styles.hero}>
<CoverImage uri={coverUri} hasCover={hasCover} style={styles.cover} />
<Text style={[styles.title, { color: palette.foreground }]}>
<PaletteText
tone="foreground"
style={[styles.title, { color: palette.foreground }]}
>
{title}
</Text>
<Text style={{ color: palette.secondaryForeground }}>{ownerName}</Text>
</PaletteText>
<PaletteText
tone="secondaryForeground"
style={{ color: palette.secondaryForeground }}
>
{ownerName}
</PaletteText>
<View style={styles.actions}>
{showSubscribe ? (
<Pressable
@@ -502,7 +547,8 @@ const PlaylistHero = memo(function PlaylistHero({
},
]}
>
<Ionicons
<PaletteIcon
tone={isSubscribed ? "foreground" : "accentForeground"}
name={isSubscribed ? "checkmark" : "add"}
size={24}
color={
@@ -528,7 +574,12 @@ const PlaylistHero = memo(function PlaylistHero({
onPress={onShuffle}
style={[styles.iconAction, { backgroundColor: palette.surface }]}
>
<Ionicons name="shuffle" size={24} color={palette.foreground} />
<PaletteIcon
tone="foreground"
name="shuffle"
size={24}
color={palette.foreground}
/>
</Pressable>
</View>
</View>
@@ -1,5 +1,4 @@
import { Stack } from "expo-router"
import { Platform } from "react-native"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
@@ -15,10 +14,6 @@ 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,5 +1,4 @@
import { Stack } from "expo-router"
import { Platform } from "react-native"
import { ProfileHeaderButton } from "@/components/profile-header-button"
import { tabStackScreenTitles, useStackScreenOptions } from "@/lib/navigation"
@@ -15,10 +14,6 @@ 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,
File renamed without changes.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

+10 -2
View File
@@ -1,4 +1,5 @@
import { StyleSheet, Text, View } from "react-native"
import { PaletteText } from "@/components/palette-text"
import { StyleSheet, View } from "react-native"
import Svg, { G, Path } from "react-native-svg"
import type { PlaybackFormat } from "@otunes/convex/playback-stream"
@@ -74,10 +75,12 @@ function LosslessMark({
/** The Dolby Atmos or Lossless label shown under the progress bar. */
export function AudioFormatBadge({
artwork = false,
format,
color,
backgroundColor,
}: {
artwork?: boolean
format: PlaybackFormat
color: string
backgroundColor: string
@@ -90,7 +93,12 @@ export function AudioFormatBadge({
) : (
<LosslessMark color={color} backgroundColor={backgroundColor} />
)}
<Text style={[styles.label, { color }]}>{label}</Text>
<PaletteText
tone={artwork ? "secondaryForeground" : undefined}
style={[styles.label, { color }]}
>
{label}
</PaletteText>
</View>
)
}
+7 -3
View File
@@ -1,5 +1,6 @@
import { PaletteText } from "@/components/palette-text"
import { memo } from "react"
import { StyleSheet, Text, View } from "react-native"
import { StyleSheet, View } from "react-native"
import { useThemeColors } from "@/lib/theme"
@@ -25,9 +26,12 @@ export const DiscHeader = memo(function DiscHeader({
}) {
const colors = useThemeColors()
return (
<Text style={[styles.discHeader, { color: color ?? colors.foreground }]}>
<PaletteText
tone={color ? "foreground" : undefined}
style={[styles.discHeader, { color: color ?? colors.foreground }]}
>
{label}
</Text>
</PaletteText>
)
})
+6
View File
@@ -2,6 +2,7 @@ import { Ionicons } from "@expo/vector-icons"
import { Image, type ImageContentFit, type ImageStyle } from "expo-image"
import { memo, useMemo } from "react"
import {
Platform,
PixelRatio,
StyleProp,
StyleSheet,
@@ -9,6 +10,8 @@ import {
type ViewStyle,
} from "react-native"
import { prefetchCoverPalette } from "@/hooks/use-cover-palette"
import { useThemeColors } from "@/lib/theme"
import {
coverImageSizes,
@@ -106,6 +109,9 @@ export const CoverImage = memo(function CoverImage({
contentFit={contentFit}
transition={150}
blurRadius={blurRadius}
onLoad={
Platform.OS === "android" ? () => prefetchCoverPalette(uri) : undefined
}
cachePolicy="memory-disk"
recyclingKey={sourceUri}
enforceEarlyResizing
@@ -59,7 +59,8 @@ export function MenuView({
outlineVariant: "#545458",
error: "#FF453A",
}}
matchContents
// Rows fill their parent width; compact action buttons keep intrinsic sizing.
matchContents={shouldOpenOnLongPress ? { vertical: true } : true}
>
<DropdownMenu
expanded={expanded}
@@ -70,7 +71,9 @@ export function MenuView({
properties={{ clippingEnabled: false }}
>
<DropdownMenu.Trigger>
<RNHostView matchContents>
<RNHostView
matchContents={shouldOpenOnLongPress ? { vertical: true } : true}
>
{shouldOpenOnLongPress ? (
<GestureDetector gesture={longPress}>
<View collapsable={false}>{children}</View>
+32 -14
View File
@@ -1,11 +1,13 @@
import { PaletteText, PaletteIcon } from "@/components/palette-text"
import Animated from "react-native-reanimated"
import {
useAndroidTabPalette,
useAndroidTabBackgroundStyle,
useAndroidTabHasArtworkPalette,
} from "@/contexts/android-tab-theme"
import { Ionicons } from "@expo/vector-icons"
import { NativeTabs } from "expo-router/native-tabs"
import { useRouter } from "expo-router"
import { Platform, Pressable, StyleSheet, Text, View } from "react-native"
import { Platform, Pressable, StyleSheet, View } from "react-native"
import { useSafeAreaInsets } from "react-native-safe-area-context"
@@ -65,7 +67,8 @@ function MiniPlayerContent({
<View
style={isAccessory ? styles.accessoryInlineMeta : styles.inlineMeta}
>
<Text
<PaletteText
tone="foreground"
style={[
isAccessory ? styles.accessoryTitle : styles.title,
{ color: colors.foreground },
@@ -73,7 +76,7 @@ function MiniPlayerContent({
numberOfLines={1}
>
{currentSong.title}
</Text>
</PaletteText>
</View>
<Pressable
style={styles.controlButton}
@@ -83,7 +86,8 @@ function MiniPlayerContent({
}}
hitSlop={6}
>
<Ionicons
<PaletteIcon
tone="foreground"
name={isPlaying ? "pause" : "play"}
size={20}
color={colors.foreground}
@@ -101,7 +105,8 @@ function MiniPlayerContent({
style={artworkStyle}
/>
<View style={isAccessory ? styles.accessoryMeta : styles.meta}>
<Text
<PaletteText
tone="foreground"
style={[
isAccessory ? styles.accessoryTitle : styles.title,
{ color: colors.foreground },
@@ -109,8 +114,9 @@ function MiniPlayerContent({
numberOfLines={1}
>
{currentSong.title}
</Text>
<Text
</PaletteText>
<PaletteText
tone="secondaryForeground"
style={[
isAccessory ? styles.accessoryArtist : styles.artist,
{ color: colors.mutedForeground },
@@ -118,7 +124,7 @@ function MiniPlayerContent({
numberOfLines={1}
>
{currentSong.artist.name}
</Text>
</PaletteText>
</View>
<View style={styles.controls}>
{Platform.OS === "android" && !isAccessory ? (
@@ -132,7 +138,12 @@ function MiniPlayerContent({
}}
hitSlop={6}
>
<Ionicons name="play-back" size={24} color={colors.foreground} />
<PaletteIcon
tone="foreground"
name="play-back"
size={24}
color={colors.foreground}
/>
</Pressable>
) : null}
<Pressable
@@ -143,7 +154,8 @@ function MiniPlayerContent({
}}
hitSlop={6}
>
<Ionicons
<PaletteIcon
tone="foreground"
name={isPlaying ? "pause" : "play"}
size={24}
color={colors.foreground}
@@ -157,7 +169,12 @@ function MiniPlayerContent({
}}
hitSlop={6}
>
<Ionicons name="play-forward" size={24} color={colors.foreground} />
<PaletteIcon
tone="foreground"
name="play-forward"
size={24}
color={colors.foreground}
/>
</Pressable>
</View>
</Pressable>
@@ -167,9 +184,10 @@ function MiniPlayerContent({
function MiniPlayerChrome({ children }: { children: React.ReactNode }) {
const palette = useAndroidTabPalette()
const hasArtworkPalette = useAndroidTabHasArtworkPalette()
const backgroundStyle = useAndroidTabBackgroundStyle()
return (
<View style={[styles.androidBar, { backgroundColor: palette.background }]}>
<Animated.View style={[styles.androidBar, backgroundStyle]}>
{children}
{hasArtworkPalette ? (
<View
@@ -187,7 +205,7 @@ function MiniPlayerChrome({ children }: { children: React.ReactNode }) {
{ backgroundColor: palette.secondaryForeground },
]}
/>
</View>
</Animated.View>
)
}
+49
View File
@@ -0,0 +1,49 @@
import { Ionicons } from "@expo/vector-icons"
import type { ComponentProps } from "react"
import { Pressable, type TextProps } from "react-native"
import { useRouter } from "expo-router"
import Animated from "react-native-reanimated"
import {
useAnimatedPaletteColor,
type PaletteColor,
} from "@/contexts/android-tab-theme"
const AnimatedIcon = Animated.createAnimatedComponent(Ionicons)
/** Keep artwork text colors on the same UI-thread animation as the background. */
export function PaletteText({
tone,
style,
...props
}: TextProps & { tone?: PaletteColor }) {
const colorStyle = useAnimatedPaletteColor(tone)
return <Animated.Text {...props} style={[style, colorStyle]} />
}
export function PaletteIcon({
tone,
style,
...props
}: ComponentProps<typeof Ionicons> & { tone?: PaletteColor }) {
const colorStyle = useAnimatedPaletteColor(tone)
return <AnimatedIcon {...props} style={[style, colorStyle]} />
}
function ArtworkBackButton() {
const router = useRouter()
return (
<Pressable
accessibilityRole="button"
accessibilityLabel="Navigate up"
hitSlop={8}
onPress={() => router.back()}
>
<PaletteIcon tone="foreground" name="arrow-back" size={24} />
</Pressable>
)
}
export function renderArtworkBackButton() {
return <ArtworkBackButton />
}
+13 -7
View File
@@ -1,3 +1,4 @@
import { PaletteText } from "@/components/palette-text"
import { MusicEntityView } from "@/components/music-entity-view"
import { collectionInset } from "@/components/collection-list"
import { CoverImage } from "@/components/cover-image"
@@ -8,7 +9,7 @@ import { formatDuration } from "@/lib/format"
import { albumCoverUrl } from "@/lib/urls"
import { miniPlayerHeight, spacing, useThemeColors } from "@/lib/theme"
import { memo, useCallback } from "react"
import { Platform, Pressable, StyleSheet, Text, View } from "react-native"
import { Platform, Pressable, StyleSheet, View } from "react-native"
import {
MediaContextMenu,
@@ -46,22 +47,27 @@ export const SongRow = memo(function SongRow({
const content = (
<>
<View style={styles.rowMeta}>
<Text
<PaletteText
tone={palette ? "foreground" : undefined}
style={[styles.rowTitle, { color: foreground }]}
numberOfLines={1}
>
{song.title}
</Text>
<Text
</PaletteText>
<PaletteText
tone={palette ? "secondaryForeground" : undefined}
style={[styles.rowSubtitle, { color: secondaryForeground }]}
numberOfLines={1}
>
{song.artist.name} · {song.album.title}
</Text>
</PaletteText>
</View>
<Text style={[styles.duration, { color: secondaryForeground }]}>
<PaletteText
tone={palette ? "secondaryForeground" : undefined}
style={[styles.duration, { color: secondaryForeground }]}
>
{formatDuration(song.durationSeconds)}
</Text>
</PaletteText>
{trailing}
</>
)
+15 -4
View File
@@ -1,4 +1,5 @@
import { useEffect, useRef, type ReactNode } from "react"
import Reanimated from "react-native-reanimated"
import { useEffect, useRef, type ReactNode, type ComponentProps } from "react"
import {
Animated,
ScrollView,
@@ -197,15 +198,25 @@ export function HomeSkeleton() {
/** Album and playlist pages: cover, title, play buttons, then tracks. */
export function CollectionDetailSkeleton({
style,
round = false,
backgroundColor,
onLayout,
}: {
style?: ComponentProps<typeof Reanimated.ScrollView>["style"]
round?: boolean
backgroundColor?: string
onLayout?: () => void
}) {
const colors = useThemeColors()
const coverSize = round ? 180 : 210
return (
<ScrollView
style={{ flex: 1, backgroundColor: colors.background }}
<Reanimated.ScrollView
onLayout={onLayout}
style={[
{ flex: 1, backgroundColor: backgroundColor ?? colors.background },
style,
]}
contentContainerStyle={{ paddingBottom: contentBottomInset }}
contentInsetAdjustmentBehavior="automatic"
scrollEnabled={false}
@@ -232,7 +243,7 @@ export function CollectionDetailSkeleton({
) : (
<SongListSkeleton rows={8} embedded />
)}
</ScrollView>
</Reanimated.ScrollView>
)
}
+15 -2
View File
@@ -1,3 +1,4 @@
import { PaletteText, PaletteIcon } from "@/components/palette-text"
import {
ActivityIndicator,
Platform,
@@ -73,8 +74,20 @@ export function Button({
<ActivityIndicator color={textColor} />
) : (
<View style={styles.buttonContent}>
{icon ? <Ionicons name={icon} size={18} color={textColor} /> : null}
<Text style={[styles.buttonText, { color: textColor }]}>{title}</Text>
{icon ? (
<PaletteIcon
tone={tint ? "accentForeground" : undefined}
name={icon}
size={18}
color={textColor}
/>
) : null}
<PaletteText
tone={tint ? "accentForeground" : undefined}
style={[styles.buttonText, { color: textColor }]}
>
{title}
</PaletteText>
</View>
)}
</Pressable>
+133 -38
View File
@@ -1,8 +1,7 @@
import {
useIsFocused,
useNavigation,
usePreventRemove,
useRoute,
useNavigation,
type NativeStackNavigationProp,
} from "expo-router"
import {
@@ -14,14 +13,29 @@ import {
useState,
type PropsWithChildren,
} from "react"
import { Platform } from "react-native"
import { Platform, StyleSheet, type HostInstance } from "react-native"
import Reanimated, {
useSharedValue,
useAnimatedStyle,
useAnimatedReaction,
useAnimatedRef,
setNativeProps,
processColor,
withTiming,
type SharedValue,
} from "react-native-reanimated"
import { themeCoverPalette, type CoverPalette } from "@/lib/cover-palette"
import { useIsDark, useThemeColors } from "@/lib/theme"
export type PaletteColor = Exclude<keyof CoverPalette, "isDark">
type PaletteColors = Pick<CoverPalette, PaletteColor> & {
selectedColor: string
}
type TabTheme = {
palette: CoverPalette
selectedColor: string
colors: SharedValue<PaletteColors>
hasArtworkPalette: boolean
setPalette: (palette: CoverPalette | null, owner: string) => void
}
@@ -39,7 +53,30 @@ export function AndroidTabThemeProvider({ children }: PropsWithChildren) {
palette: CoverPalette
owner: string
} | null>(null)
const palette = screen?.palette ?? null
const palette = screen?.palette ?? defaultPalette
const hasArtwork =
palette.background !== defaultPalette.background ||
palette.foreground !== defaultPalette.foreground ||
palette.secondaryForeground !== defaultPalette.secondaryForeground ||
palette.accent !== defaultPalette.accent
const { isDark: _defaultIsDark, ...defaultColors } = defaultPalette
const animatedColors = useSharedValue<PaletteColors>({
...defaultColors,
selectedColor: defaultPalette.accentText,
})
useLayoutEffect(() => {
if (Platform.OS !== "android") return
const { isDark: _isDark, ...colors } = palette
animatedColors.value = withTiming(
{
...colors,
selectedColor: hasArtwork
? palette.foreground
: defaultPalette.accentText,
},
{ duration: PALETTE_FADE_MS }
)
}, [animatedColors, palette, defaultPalette, hasArtwork])
const setPalette = useCallback(
(palette: CoverPalette | null, owner: string) => {
setScreen((current) =>
@@ -48,22 +85,15 @@ export function AndroidTabThemeProvider({ children }: PropsWithChildren) {
},
[]
)
const artworkPalette =
palette &&
(palette.background !== defaultPalette.background ||
palette.foreground !== defaultPalette.foreground ||
palette.secondaryForeground !== defaultPalette.secondaryForeground ||
palette.accent !== defaultPalette.accent)
? palette
: null
const artworkPalette = hasArtwork ? palette : null
const value = useMemo(
() => ({
palette: artworkPalette ?? defaultPalette,
selectedColor: artworkPalette?.foreground ?? defaultPalette.accentText,
colors: animatedColors,
hasArtworkPalette: artworkPalette !== null,
setPalette,
}),
[defaultPalette, artworkPalette, setPalette]
[defaultPalette, artworkPalette, setPalette, animatedColors]
)
return (
<AndroidTabTheme.Provider value={value}>
@@ -72,6 +102,50 @@ export function AndroidTabThemeProvider({ children }: PropsWithChildren) {
)
}
/**
* NativeTabs forwards raw screen props to its Fabric screen. Bind that host
* directly so appearance updates stay on the UI thread with the page colors.
*/
export function useAndroidNativeTabColors() {
const colors = useContext(AndroidTabTheme)?.colors
const ref = useAnimatedRef<HostInstance>()
const mounted = useSharedValue(false)
const attach = useCallback(
(host: HostInstance | null) => {
if (host) ref(host)
mounted.value = host !== null
},
[ref, mounted]
)
useAnimatedReaction(
() => ({ colors: colors?.value, mounted: mounted.value }),
({ colors: palette, mounted: ready }) => {
if (Platform.OS !== "android" || !ready || !palette) return
const normal = processColor(palette.secondaryForeground)
const selected = processColor(palette.selectedColor)
setNativeProps(ref, {
standardAppearance: {
tabBarBackgroundColor: processColor("transparent"),
tabBarItemRippleColor: selected,
tabBarItemActiveIndicatorEnabled: false,
tabBarItemTitleSmallLabelFontSize: 10,
tabBarItemTitleLargeLabelFontSize: 10,
normal: {
tabBarItemTitleFontColor: normal,
tabBarItemIconColor: normal,
},
selected: {
tabBarItemTitleFontColor: selected,
tabBarItemIconColor: selected,
},
},
})
}
)
return { ref: attach, style: { backgroundColor: "transparent" } }
}
export function useAndroidTabPalette() {
const theme = useContext(AndroidTabTheme)
const defaultPalette = useDefaultPalette()
@@ -82,39 +156,60 @@ export function useAndroidTabHasArtworkPalette() {
return useContext(AndroidTabTheme)?.hasArtworkPalette ?? false
}
export function useAndroidTabSelectedColor() {
export function useAndroidTabBackgroundStyle() {
const theme = useContext(AndroidTabTheme)
const defaultPalette = useDefaultPalette()
return theme?.selectedColor ?? defaultPalette.accentText
const fallback = useDefaultPalette().background
const colors = theme?.colors
return useAnimatedStyle(() =>
Platform.OS === "android"
? { backgroundColor: colors?.value.background ?? fallback }
: {}
)
}
/** Keep Android artwork screens and shared bars on the same displayed palette. */
/** Color tokens share the background's UI-thread timing. */
export function useAnimatedPaletteColor(tone: PaletteColor | undefined) {
const colors = useContext(AndroidTabTheme)?.colors
return useAnimatedStyle(() =>
Platform.OS === "android" && tone && colors
? { color: colors.value[tone] }
: {}
)
}
/** Native headers draw this same UI-thread background as the page and bars. */
function AndroidArtworkBackground() {
const style = useAndroidTabBackgroundStyle()
return <Reanimated.View style={[StyleSheet.absoluteFill, style]} />
}
export function renderAndroidArtworkBackground() {
return <AndroidArtworkBackground />
}
const PALETTE_FADE_MS = 400
/** The focused artwork screen selects the shared background for page and bars. */
export function useAndroidScreenPalette(palette: CoverPalette) {
const isFocused = useIsFocused()
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 [closing, setClosing] = useState(false)
const onLayout = useCallback(() => setLaidOut(true), [])
const theme = useContext(AndroidTabTheme)
const setPalette = theme?.setPalette
useLayoutEffect(() => {
if (Platform.OS !== "android") return
return navigation.addListener("transitionEnd", ({ data }) => {
setAppeared(!data.closing)
const start = navigation.addListener("transitionStart", ({ data }) => {
setClosing(data.closing)
})
return start
}, [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))
})
const defaultPalette = useDefaultPalette()
const theme = useContext(AndroidTabTheme)
const setPalette = theme?.setPalette
const target = isFocused && laidOut && !closing ? palette : defaultPalette
const backgroundStyle = useAndroidTabBackgroundStyle()
useLayoutEffect(() => {
if (
@@ -122,16 +217,16 @@ export function useAndroidScreenPalette(palette: CoverPalette) {
!setPalette ||
!isFocused ||
!laidOut ||
!appeared ||
leaving
closing
)
return
setPalette(palette, owner)
return () => setPalette(null, owner)
}, [appeared, isFocused, laidOut, leaving, owner, palette, setPalette])
}, [closing, laidOut, isFocused, owner, palette, setPalette])
return {
palette: Platform.OS === "android" && theme ? theme.palette : palette,
palette: Platform.OS === "android" ? target : palette,
backgroundStyle,
onLayout: Platform.OS === "android" ? onLayout : undefined,
}
}
+1
View File
@@ -859,6 +859,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
recorded.origin ??
(recorded.playlistId ? `playlist:${recorded.playlistId}` : undefined)
resetQueuePlayback()
store.update(playbackQueue.clearQueue)
store.update(recipe)
const firstSongId = store.getState().queue[0]
if (!firstSongId) return
+14 -2
View File
@@ -95,6 +95,13 @@ function extractSwatches(key: string) {
return request
}
/** Warm visible artwork colors before a detail page is pushed. */
export function prefetchCoverPalette(uri: string) {
const key = withCoverImageSize(uri, 64)
if (cachedSwatches(key) !== undefined) return
void extractSwatches(key)
}
/**
* Colors for a screen tinted by `uri`'s cover art. Extraction runs once per
* cover and is cached on device. Pass `hasCover` as `undefined` while it isn't
@@ -138,7 +145,10 @@ export function useCoverPalette(
// case the cover changed.
const timer =
known === undefined
? setTimeout(() => !cancelled && setWaitedKey(key), COVER_PALETTE_WAIT_MS)
? setTimeout(
() => !cancelled && setWaitedKey(key),
COVER_PALETTE_WAIT_MS
)
: null
void extractSwatches(key).then((next) => {
if (!cancelled) show(next ?? known ?? null)
@@ -151,7 +161,9 @@ export function useCoverPalette(
const palette = useMemo(() => {
const fromArt =
hasCover !== false && swatches ? deriveCoverPalette(swatches, isDark) : null
hasCover !== false && swatches
? deriveCoverPalette(swatches, isDark)
: null
return fromArt ?? themeCoverPalette(theme, isDark)
}, [hasCover, isDark, swatches, theme])
+1
View File
@@ -28,6 +28,7 @@ export function useStackScreenOptions(
headerBackButtonDisplayMode: "minimal",
...(Platform.OS === "android"
? {
animation: "slide_from_right",
headerLargeTitle: false,
headerTransparent: false,
headerStyle: { backgroundColor: theme.background },
+1 -1
View File
@@ -31,7 +31,7 @@ export function PageHeader({
<header
className={cn(
"flex shrink-0 items-center gap-2 border-b px-4 py-3",
!title && !openApp && "md:hidden"
!title && "md:hidden"
)}
>
<MobileSidebarTrigger />
+1 -1
View File
@@ -13,7 +13,7 @@ export function OpenAppButton() {
<button
type="button"
onClick={openApp}
className="ml-auto inline-flex shrink-0 items-center gap-1 text-sm font-medium hover:underline focus-visible:outline-2 focus-visible:outline-offset-4"
className="ml-auto inline-flex shrink-0 items-center gap-1 text-sm font-medium hover:underline focus-visible:outline-2 focus-visible:outline-offset-4 md:hidden"
>
Open App
<ArrowUpRight aria-hidden className="size-4" />
+7 -1
View File
@@ -388,6 +388,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
const [queueOpen, setQueueOpen] = useState(false)
const [isPlaying, setIsPlaying] = useState(false)
const [playbackStartVersion, setPlaybackStartVersion] = useState(0)
const [currentTime, setCurrentTime] = useState(0)
const [measuredDuration, setMeasuredDuration] = useState<{
songId: string
@@ -890,7 +891,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
return () => {
audio.removeEventListener("canplay", onCanPlay)
}
}, [isPlaying, currentSongId, attemptPlayback])
}, [isPlaying, currentSongId, playbackStartVersion, attemptPlayback])
useEffect(() => {
const audio = audioRef.current
@@ -1069,6 +1070,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
recorded.origin ??
(recorded.playlistId ? `playlist:${recorded.playlistId}` : undefined)
const previousSongId = store.getState().queue[0]
store.update(playbackQueue.clearQueue)
store.update(recipe)
const firstSongId = store.getState().queue[0]
if (!firstSongId) {
@@ -1078,7 +1080,11 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
if (firstSongId === previousSongId) {
seekTo(0)
}
// Repeated Play/Shuffle presses must request playback even when the
// first song and playing state have not changed.
isPlayingRef.current = true
setIsPlaying(true)
setPlaybackStartVersion((version) => version + 1)
recordPlay(
recorded.playlistId
? { playlistId: recorded.playlistId }
+19 -19
View File
@@ -76,8 +76,8 @@ export function PlayerBar() {
queueOpen && !isMobile && "right-72"
)}
>
<div className="pointer-events-auto flex w-full max-w-6xl items-center gap-2 rounded-full border border-foreground/20 bg-(--player-background) px-3 py-2 text-card-foreground shadow-lg [--player-background:var(--card)] @min-[640px]:gap-5 @min-[640px]:px-5 @min-[640px]:py-3 dark:border-white/20 dark:text-white dark:[--player-background:#303033]">
<div className="flex shrink-0 items-center gap-0 @min-[640px]:gap-1 [&_button]:size-7 @min-[640px]:[&_button]:size-10 [&_svg]:size-4 @min-[640px]:[&_svg]:size-6">
<div className="pointer-events-auto flex w-full max-w-[40rem] items-center gap-2 rounded-full border border-foreground/20 bg-(--player-background) px-3 py-2 text-card-foreground shadow-lg [--player-background:var(--card)] md:gap-3 md:py-1.5 dark:border-white/20 dark:text-white dark:[--player-background:#303033]">
<div className="flex shrink-0 items-center gap-0 md:gap-0.5 [&_button]:size-7 [&_svg]:size-4">
<Button
variant="ghost"
size="icon"
@@ -91,7 +91,7 @@ export function PlayerBar() {
)}
onClick={() => void toggleShuffle()}
>
<Shuffle className="size-4 @min-[640px]:size-6" />
<Shuffle className="size-4" />
</Button>
<Button
variant="ghost"
@@ -100,7 +100,7 @@ export function PlayerBar() {
disabled={!hasQueue}
onClick={() => void skipPrevious()}
>
<SkipBack className="size-4 fill-current @min-[640px]:size-6" />
<SkipBack className="size-4 fill-current" />
</Button>
<Button
variant="ghost"
@@ -110,9 +110,9 @@ export function PlayerBar() {
onClick={() => setIsPlaying(!isPlaying)}
>
{isPlaying ? (
<Pause className="size-5! fill-current @min-[640px]:size-8!" />
<Pause className="size-5! fill-current" />
) : (
<Play className="size-5! fill-current @min-[640px]:size-8!" />
<Play className="size-5! fill-current" />
)}
</Button>
<Button
@@ -122,7 +122,7 @@ export function PlayerBar() {
disabled={!hasQueue}
onClick={() => void skipNext()}
>
<SkipForward className="size-4 fill-current @min-[640px]:size-6" />
<SkipForward className="size-4 fill-current" />
</Button>
<Button
variant="ghost"
@@ -138,33 +138,33 @@ export function PlayerBar() {
onClick={() => void cycleRepeat()}
>
{repeatEnabled === "once" ? (
<Repeat1 className="size-4 @min-[640px]:size-6" />
<Repeat1 className="size-4" />
) : (
<Repeat className="size-4 @min-[640px]:size-6" />
<Repeat className="size-4" />
)}
</Button>
</div>
<div className="relative flex h-11 min-w-0 flex-1 items-center gap-2 pb-2 @min-[640px]:h-16 @min-[640px]:gap-3">
<div className="relative flex h-11 min-w-0 flex-1 items-center gap-2 pb-2 md:h-9 md:pb-1">
{currentSong ? (
<>
<div className="relative size-9 shrink-0 overflow-hidden rounded @min-[640px]:size-14">
<div className="relative size-9 shrink-0 overflow-hidden rounded md:size-8">
<Image
src={albumCoverUrl(currentSong.album.id)}
alt={currentSong.album.title}
fill
sizes="56px"
sizes="36px"
className="object-cover"
/>
</div>
<div className="min-w-0 flex-1">
<Link
href={`/album/${currentSong.album.id}`}
className="block truncate text-sm font-semibold hover:underline @min-[640px]:text-xl"
className="block truncate text-sm font-semibold hover:underline md:text-[13px] md:leading-4"
>
{currentSong.title}
</Link>
<p className="truncate text-xs @min-[640px]:text-lg">
<p className="truncate text-xs">
<Link
href={`/artist/${currentSong.artist.id}`}
className="hover:underline"
@@ -200,7 +200,7 @@ export function PlayerBar() {
<div className="absolute inset-x-0 -bottom-1">
<Slider
className={cn(
"h-3 flex-1 [&_[data-slot=slider-range]]:bg-current/80 [&_[data-slot=slider-thumb]]:size-2 [&_[data-slot=slider-thumb]]:border-current [&_[data-slot=slider-thumb]]:bg-current [&_[data-slot=slider-thumb]]:opacity-0 focus-within:[&_[data-slot=slider-thumb]]:opacity-100 hover:[&_[data-slot=slider-thumb]]:opacity-100 [&_[data-slot=slider-track]]:h-[3px] [&_[data-slot=slider-track]]:bg-current/30",
"h-3 flex-1 [&_[data-slot=slider-range]]:bg-current/80 [&_[data-slot=slider-thumb]]:size-2 [&_[data-slot=slider-thumb]]:border-current [&_[data-slot=slider-thumb]]:bg-current [&_[data-slot=slider-thumb]]:opacity-0 focus-within:[&_[data-slot=slider-thumb]]:opacity-100 hover:[&_[data-slot=slider-thumb]]:opacity-100 [&_[data-slot=slider-track]]:h-[3px] [&_[data-slot=slider-track]]:bg-current/30 md:[&_[data-slot=slider-track]]:h-0.5",
!hasActiveSong && "[&_[data-slot=slider-thumb]]:hidden"
)}
min={0}
@@ -222,7 +222,7 @@ export function PlayerBar() {
</div>
</div>
<div className="flex shrink-0 items-center gap-0 @min-[640px]:gap-2 [&_button]:size-7 @min-[640px]:[&_button]:size-10 [&_svg]:size-4 @min-[640px]:[&_svg]:size-6">
<div className="flex shrink-0 items-center gap-0 md:gap-1 [&_button]:size-7 [&_svg]:size-4">
<Button
variant="ghost"
size="icon"
@@ -230,7 +230,7 @@ export function PlayerBar() {
aria-label="Lyrics"
disabled
>
<MessageSquareQuote className="size-4 @min-[640px]:size-6" />
<MessageSquareQuote className="size-4" />
</Button>
<Button
variant="ghost"
@@ -240,12 +240,12 @@ export function PlayerBar() {
className={cn(queueOpen && "text-primary")}
onClick={toggleQueueOpen}
>
<ListMusic className="size-4 @min-[640px]:size-6" />
<ListMusic className="size-4" />
</Button>
<Popover>
<PopoverTrigger asChild>
<Button variant="ghost" size="icon" aria-label="Volume">
<Volume2 className="size-4 @min-[640px]:size-6" />
<Volume2 className="size-4" />
</Button>
</PopoverTrigger>
<PopoverContent side="top" align="end" className="w-40">
+55 -11
View File
@@ -6,7 +6,7 @@ import * as React from "react"
import Image from "next/image"
import { useRouter } from "next/navigation"
import { useMutation } from "convex/react"
import { Play, Share2, Shuffle, Star, Trash2 } from "lucide-react"
import { Play, SearchIcon, Share2, Shuffle, Star, Trash2 } from "lucide-react"
import { toast } from "sonner"
import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
@@ -305,6 +305,19 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
const songs = isFavorites
? playlist.songs.filter((song) => !hiddenFavoriteIds.has(song.id))
: playlistSongs
const [searchQuery, setSearchQuery] = React.useState("")
const normalizedQuery = searchQuery.trim().toLowerCase()
const filteredSongs = React.useMemo(
() =>
normalizedQuery
? songs.filter((song) =>
[song.title, song.artist.name, song.album.title].some((value) =>
value.toLowerCase().includes(normalizedQuery)
)
)
: songs,
[songs, normalizedQuery]
)
const playlistSongIds = React.useMemo(
() => songs.map((song) => song.id as Id<"songs">),
[songs]
@@ -327,7 +340,8 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
handleSelect,
handlePointerDown,
prepareContextMenu,
} = useTrackSelection(songs)
clearSelection,
} = useTrackSelection(filteredSongs)
const selectedStationArtistId = React.useMemo(
() => stationArtistId(songs, selectedIds),
@@ -335,8 +349,12 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
)
const selectionPositions = React.useMemo(
() => getSelectionRangePositions(songs.map((song) => song.id), selectedIds),
[songs, selectedIds]
() =>
getSelectionRangePositions(
filteredSongs.map((song) => song.id),
selectedIds
),
[filteredSongs, selectedIds]
)
const totalDurationSeconds = React.useMemo(
() => sumDurationSeconds(songs),
@@ -461,7 +479,13 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
}
function handleDrop(targetIndex: number) {
if (isFavorites || !isOwner || dragIndex === null || dragIndex === targetIndex) {
if (
normalizedQuery ||
isFavorites ||
!isOwner ||
dragIndex === null ||
dragIndex === targetIndex
) {
setDragIndex(null)
return
}
@@ -633,13 +657,31 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
</div>
</div>
{songs.length > 0 ? (
songs.map((song, index) => (
<div className="px-6 pb-4">
<div className="relative max-w-sm">
<SearchIcon className="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" />
<input
type="search"
aria-label="Search playlist"
placeholder="Search playlist"
value={searchQuery}
onChange={(event) => {
setSearchQuery(event.target.value)
clearSelection()
setActiveTrackId("")
setDragIndex(null)
}}
className="h-10 w-full min-w-0 rounded-full border border-input bg-input/30 pr-3 pl-9 text-sm text-foreground transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50"
/>
</div>
</div>
{filteredSongs.length > 0 ? (
filteredSongs.map((song, index) => (
<PlaylistSongRow
key={song.id}
song={song}
index={index}
isOwner={isOwner && !isFavorites}
isOwner={isOwner && !isFavorites && !normalizedQuery}
canRemove={isFavorites || isOwner}
showFavoriteInMenu={!isFavorites}
removeLabel={
@@ -679,14 +721,14 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
onMediaAction={handleMediaAction}
onRemove={() => handleRemoveSong(song.id)}
onDragStart={(event) => {
if (isFavorites || !isOwner) {
if (normalizedQuery || isFavorites || !isOwner) {
return
}
setDragIndex(index)
event.dataTransfer.effectAllowed = "move"
}}
onDragOver={(event) => {
if (isFavorites || !isOwner) {
if (normalizedQuery || isFavorites || !isOwner) {
return
}
event.preventDefault()
@@ -707,7 +749,9 @@ export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
))
) : (
<p className="px-6 py-8 text-sm text-muted-foreground">
This playlist has no songs yet.
{normalizedQuery
? "No songs found."
: "This playlist has no songs yet."}
</p>
)}
<MediaCollectionFooter