Compare commits
5
Commits
No files matched your search
@@ -16,17 +16,18 @@ export default function HomeLayout() {
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Home",
|
||||
headerRight: route.name === "settings" ? undefined : () => <ProfileHeaderButton />,
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "settings"
|
||||
? undefined
|
||||
: () => [
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
],
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -4,6 +4,11 @@ import { memo, useCallback, useEffect, useMemo } from "react"
|
||||
import { FlatList, Pressable, StyleSheet, Text, View } from "react-native"
|
||||
import { Ionicons } from "@expo/vector-icons"
|
||||
|
||||
import {
|
||||
CollectionDivider,
|
||||
collectionInset,
|
||||
DiscHeader,
|
||||
} from "@/components/collection-list"
|
||||
import { CoverImage } from "@/components/cover-image"
|
||||
|
||||
import {
|
||||
@@ -66,21 +71,34 @@ export default function AlbumScreen() {
|
||||
}
|
||||
}, [album])
|
||||
|
||||
const renderTrack = useCallback(
|
||||
({ item, index }: { item: BrowseAlbumTrack; index: number }) =>
|
||||
album ? (
|
||||
const listItems = useMemo(() => albumListItems(album?.tracks ?? []), [album])
|
||||
|
||||
const renderItem = useCallback(
|
||||
({ item }: { item: AlbumListItem }) => {
|
||||
if (item.type === "disc") {
|
||||
return <DiscHeader label={item.label} color={palette.foreground} />
|
||||
}
|
||||
return album ? (
|
||||
<AlbumTrackRow
|
||||
track={item}
|
||||
index={index}
|
||||
track={item.track}
|
||||
number={item.number}
|
||||
album={album}
|
||||
songIds={songIds}
|
||||
palette={palette}
|
||||
favorited={isSongFavorite(item.id)}
|
||||
favorited={isSongFavorite(item.track.id)}
|
||||
onPlay={playFromSong}
|
||||
onAction={handleAlbumTrackAction}
|
||||
/>
|
||||
) : null,
|
||||
[album, handleAlbumTrackAction, isSongFavorite, palette, playFromSong, songIds]
|
||||
) : null
|
||||
},
|
||||
[
|
||||
album,
|
||||
handleAlbumTrackAction,
|
||||
isSongFavorite,
|
||||
palette,
|
||||
playFromSong,
|
||||
songIds,
|
||||
]
|
||||
)
|
||||
|
||||
if (album === undefined || !config || !settled) {
|
||||
@@ -154,79 +172,129 @@ export default function AlbumScreen() {
|
||||
/>
|
||||
<FlatList
|
||||
{...longListProps}
|
||||
data={album.tracks}
|
||||
keyExtractor={(track) => track.id}
|
||||
data={listItems}
|
||||
keyExtractor={albumListItemKey}
|
||||
style={{ flex: 1, backgroundColor: palette.background }}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
indicatorStyle={palette.isDark ? "white" : "black"}
|
||||
ListHeaderComponent={
|
||||
<View style={styles.hero}>
|
||||
<CoverImage
|
||||
uri={coverUri}
|
||||
hasCover={album.cover != null}
|
||||
style={styles.cover}
|
||||
/>
|
||||
<Text style={[styles.title, { color: palette.foreground }]}>
|
||||
{album.title}
|
||||
</Text>
|
||||
<Pressable onPress={() => push(`/artist/${album.artist.id}`)}>
|
||||
<Text style={[styles.artist, { color: palette.accentText }]}>
|
||||
{album.artist.name}
|
||||
</Text>
|
||||
</Pressable>
|
||||
{metadata ? (
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
{metadata}
|
||||
</Text>
|
||||
) : null}
|
||||
<View style={styles.actions}>
|
||||
<Pressable
|
||||
onPress={() => void toggleAlbumFavorite(album.id)}
|
||||
hitSlop={8}
|
||||
style={[styles.iconAction, { backgroundColor: palette.surface }]}
|
||||
>
|
||||
<Ionicons
|
||||
name={favorited ? "star" : "star-outline"}
|
||||
size={24}
|
||||
color={favorited ? palette.accent : palette.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
<Button
|
||||
title="Play"
|
||||
icon="play"
|
||||
onPress={() => void playAlbum(album.id, songIds)}
|
||||
style={styles.playButton}
|
||||
tint={{
|
||||
background: palette.accent,
|
||||
foreground: palette.accentForeground,
|
||||
}}
|
||||
<View>
|
||||
<View style={styles.hero}>
|
||||
<CoverImage
|
||||
uri={coverUri}
|
||||
hasCover={album.cover != null}
|
||||
style={styles.cover}
|
||||
/>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Shuffle"
|
||||
hitSlop={8}
|
||||
onPress={() => void playAlbumShuffled(album.id, songIds)}
|
||||
style={[styles.iconAction, { backgroundColor: palette.surface }]}
|
||||
>
|
||||
<Ionicons
|
||||
name="shuffle"
|
||||
size={24}
|
||||
color={palette.foreground}
|
||||
/>
|
||||
<Text style={[styles.title, { color: palette.foreground }]}>
|
||||
{album.title}
|
||||
</Text>
|
||||
<Pressable onPress={() => push(`/artist/${album.artist.id}`)}>
|
||||
<Text style={[styles.artist, { color: palette.accentText }]}>
|
||||
{album.artist.name}
|
||||
</Text>
|
||||
</Pressable>
|
||||
{metadata ? (
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
{metadata}
|
||||
</Text>
|
||||
) : null}
|
||||
<View style={styles.actions}>
|
||||
<Pressable
|
||||
onPress={() => void toggleAlbumFavorite(album.id)}
|
||||
hitSlop={8}
|
||||
style={[
|
||||
styles.iconAction,
|
||||
{ backgroundColor: palette.surface },
|
||||
]}
|
||||
>
|
||||
<Ionicons
|
||||
name={favorited ? "star" : "star-outline"}
|
||||
size={24}
|
||||
color={favorited ? palette.accent : palette.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
<Button
|
||||
title="Play"
|
||||
icon="play"
|
||||
onPress={() => void playAlbum(album.id, songIds)}
|
||||
style={styles.playButton}
|
||||
tint={{
|
||||
background: palette.accent,
|
||||
foreground: palette.accentForeground,
|
||||
}}
|
||||
/>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Shuffle"
|
||||
hitSlop={8}
|
||||
onPress={() => void playAlbumShuffled(album.id, songIds)}
|
||||
style={[
|
||||
styles.iconAction,
|
||||
{ backgroundColor: palette.surface },
|
||||
]}
|
||||
>
|
||||
<Ionicons
|
||||
name="shuffle"
|
||||
size={24}
|
||||
color={palette.foreground}
|
||||
/>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
<CollectionDivider color={palette.divider} />
|
||||
</View>
|
||||
}
|
||||
renderItem={renderTrack}
|
||||
renderItem={renderItem}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
type AlbumListItem =
|
||||
| { type: "disc"; key: string; label: string }
|
||||
| { type: "track"; track: BrowseAlbumTrack; number: number }
|
||||
|
||||
/**
|
||||
* Tracks arrive sorted by disc then track number. Disc headers are only
|
||||
* inserted when the album spans more than one disc.
|
||||
*/
|
||||
function albumListItems(tracks: BrowseAlbumTrack[]): AlbumListItem[] {
|
||||
const multiDisc = new Set(tracks.map((track) => track.diskNumber)).size > 1
|
||||
const items: AlbumListItem[] = []
|
||||
let currentDisc: number | null | undefined
|
||||
let positionInDisc = 0
|
||||
|
||||
for (const track of tracks) {
|
||||
if (track.diskNumber !== currentDisc) {
|
||||
currentDisc = track.diskNumber
|
||||
positionInDisc = 0
|
||||
if (multiDisc) {
|
||||
items.push({
|
||||
type: "disc",
|
||||
key: `disc-${currentDisc ?? "unknown"}`,
|
||||
label: currentDisc == null ? "Other" : `Disc ${currentDisc}`,
|
||||
})
|
||||
}
|
||||
}
|
||||
positionInDisc += 1
|
||||
items.push({
|
||||
type: "track",
|
||||
track,
|
||||
number: track.track || positionInDisc,
|
||||
})
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
function albumListItemKey(item: AlbumListItem) {
|
||||
return item.type === "disc" ? item.key : item.track.id
|
||||
}
|
||||
|
||||
const AlbumTrackRow = memo(function AlbumTrackRow({
|
||||
track,
|
||||
index,
|
||||
number,
|
||||
album,
|
||||
songIds,
|
||||
palette,
|
||||
@@ -235,7 +303,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
|
||||
onAction,
|
||||
}: {
|
||||
track: BrowseAlbumTrack
|
||||
index: number
|
||||
number: number
|
||||
album: BrowseAlbumDetail
|
||||
songIds: Id<"songs">[]
|
||||
palette: CoverPalette
|
||||
@@ -262,33 +330,37 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
|
||||
onAction={(action) => void onAction(track, album, action)}
|
||||
>
|
||||
<Pressable
|
||||
style={[styles.trackRow, { borderBottomColor: palette.divider }]}
|
||||
style={styles.trackRow}
|
||||
onPress={() => void onPlay(track.id as Id<"songs">, songIds)}
|
||||
>
|
||||
<Text
|
||||
style={[styles.trackNumber, { color: palette.secondaryForeground }]}
|
||||
>
|
||||
{track.track || index + 1}
|
||||
{number}
|
||||
</Text>
|
||||
<View style={styles.trackMeta}>
|
||||
<Text
|
||||
style={[styles.trackTitle, { color: palette.foreground }]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{track.title}
|
||||
</Text>
|
||||
{track.artists ? (
|
||||
<View
|
||||
style={[styles.trackContent, { borderBottomColor: palette.divider }]}
|
||||
>
|
||||
<View style={styles.trackMeta}>
|
||||
<Text
|
||||
style={{ color: palette.secondaryForeground }}
|
||||
style={[styles.trackTitle, { color: palette.foreground }]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{track.artists.join(", ")}
|
||||
{track.title}
|
||||
</Text>
|
||||
) : null}
|
||||
{track.artists ? (
|
||||
<Text
|
||||
style={{ color: palette.secondaryForeground }}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{track.artists.join(", ")}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
{formatDuration(track.durationSeconds)}
|
||||
</Text>
|
||||
</View>
|
||||
<Text style={{ color: palette.secondaryForeground }}>
|
||||
{formatDuration(track.durationSeconds)}
|
||||
</Text>
|
||||
</Pressable>
|
||||
</MediaContextMenu>
|
||||
)
|
||||
@@ -326,13 +398,22 @@ const styles = StyleSheet.create({
|
||||
trackRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.sm,
|
||||
paddingLeft: collectionInset,
|
||||
},
|
||||
trackNumber: { width: 24, fontSize: 16, textAlign: "center" },
|
||||
trackContent: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
alignSelf: "stretch",
|
||||
gap: spacing.md,
|
||||
minHeight: 60,
|
||||
paddingHorizontal: spacing.lg,
|
||||
minHeight: 52,
|
||||
paddingVertical: 12,
|
||||
marginRight: collectionInset,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
trackNumber: { width: 24, textAlign: "center" },
|
||||
trackMeta: { flex: 1, minWidth: 0 },
|
||||
trackTitle: { fontSize: 16, fontWeight: "500" },
|
||||
})
|
||||
@@ -1,9 +1,15 @@
|
||||
import { useMutation } from "convex/react"
|
||||
import { memo, useCallback, useEffect, useMemo } from "react"
|
||||
import { Stack, useIsFocused, useLocalSearchParams, useRouter } from "expo-router"
|
||||
import {
|
||||
Stack,
|
||||
useIsFocused,
|
||||
useLocalSearchParams,
|
||||
useRouter,
|
||||
} from "expo-router"
|
||||
import { StatusBar } from "expo-status-bar"
|
||||
import {
|
||||
FlatList,
|
||||
Platform,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
@@ -13,7 +19,13 @@ import {
|
||||
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"
|
||||
import {
|
||||
SwipeToRemoveRow,
|
||||
useSwipeRowGroup,
|
||||
type SwipeRowGroup,
|
||||
} from "@/components/ios-swipe-to-remove-row"
|
||||
|
||||
import {
|
||||
MediaActionMenu,
|
||||
@@ -176,6 +188,7 @@ function PlaylistContent({
|
||||
const canEdit = playlist.isOwner && playlistId !== null
|
||||
const loadedSongIds = useMemo(() => songs.map((song) => song.id), [songs])
|
||||
const songIds = allSongIds ?? loadedSongIds
|
||||
const swipeGroup = useSwipeRowGroup()
|
||||
|
||||
const handlePlaySong = useCallback(
|
||||
(song: BrowseSong) => void playFromSong(song.id, songIds),
|
||||
@@ -190,16 +203,18 @@ function PlaylistContent({
|
||||
|
||||
const handleRemoveSong = useCallback(
|
||||
async (songId: Id<"songs">) => {
|
||||
if (!playlistId) return
|
||||
if (!playlistId) return false
|
||||
try {
|
||||
await removeSongs({ playlistId, songIds: [songId] })
|
||||
showSuccess("Removed from playlist")
|
||||
return true
|
||||
} catch (error) {
|
||||
showError(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: "Failed to remove from playlist"
|
||||
)
|
||||
return false
|
||||
}
|
||||
},
|
||||
[playlistId, removeSongs]
|
||||
@@ -295,6 +310,7 @@ function PlaylistContent({
|
||||
favorited={isSongFavorite(song.id)}
|
||||
removable={canEdit}
|
||||
palette={palette}
|
||||
swipeGroup={swipeGroup}
|
||||
onPlay={handlePlaySong}
|
||||
onAction={handleSongMenuAction}
|
||||
onRemove={handleRemoveSong}
|
||||
@@ -307,6 +323,7 @@ function PlaylistContent({
|
||||
handleSongMenuAction,
|
||||
isSongFavorite,
|
||||
palette,
|
||||
swipeGroup,
|
||||
]
|
||||
)
|
||||
|
||||
@@ -327,6 +344,7 @@ function PlaylistContent({
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
onEndReached={onEndReached}
|
||||
onEndReachedThreshold={0.5}
|
||||
onScrollBeginDrag={swipeGroup.closeOpenRow}
|
||||
ListHeaderComponent={
|
||||
<PlaylistHero
|
||||
coverUri={coverUri}
|
||||
@@ -355,6 +373,7 @@ const PlaylistSongRow = memo(function PlaylistSongRow({
|
||||
favorited,
|
||||
removable,
|
||||
palette,
|
||||
swipeGroup,
|
||||
onPlay,
|
||||
onAction,
|
||||
onRemove,
|
||||
@@ -363,17 +382,20 @@ const PlaylistSongRow = memo(function PlaylistSongRow({
|
||||
favorited: boolean
|
||||
removable: boolean
|
||||
palette: CoverPalette
|
||||
swipeGroup: SwipeRowGroup
|
||||
onPlay: (song: BrowseSong) => void
|
||||
onAction: (song: BrowseSong, action: MediaAction) => void
|
||||
onRemove: (songId: Id<"songs">) => void
|
||||
onRemove: (songId: Id<"songs">) => Promise<boolean>
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
const handleRemove = useCallback(() => onRemove(song.id), [onRemove, song.id])
|
||||
const row = (
|
||||
<SongListRow
|
||||
song={song}
|
||||
favorited={favorited}
|
||||
playlistLabel={PLAYLIST_LABEL}
|
||||
palette={palette}
|
||||
inset
|
||||
onPlay={onPlay}
|
||||
onAction={onAction}
|
||||
/>
|
||||
@@ -383,6 +405,19 @@ const PlaylistSongRow = memo(function PlaylistSongRow({
|
||||
return row
|
||||
}
|
||||
|
||||
if (Platform.OS === "ios") {
|
||||
return (
|
||||
<SwipeToRemoveRow
|
||||
group={swipeGroup}
|
||||
backgroundColor={palette.background}
|
||||
actionAccessibilityLabel={`Remove ${song.title} from playlist`}
|
||||
onRemove={handleRemove}
|
||||
>
|
||||
{row}
|
||||
</SwipeToRemoveRow>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<ReanimatedSwipeable
|
||||
friction={2}
|
||||
@@ -397,7 +432,7 @@ const PlaylistSongRow = memo(function PlaylistSongRow({
|
||||
accessibilityLabel={`Remove ${song.title} from playlist`}
|
||||
onPress={() => {
|
||||
swipeable.close()
|
||||
onRemove(song.id)
|
||||
void handleRemove()
|
||||
}}
|
||||
style={[styles.removeAction, { backgroundColor: colors.destructive }]}
|
||||
>
|
||||
@@ -442,54 +477,61 @@ const PlaylistHero = memo(function PlaylistHero({
|
||||
onShuffle: () => void
|
||||
}) {
|
||||
return (
|
||||
<View style={styles.hero}>
|
||||
<CoverImage uri={coverUri} hasCover={hasCover} style={styles.cover} />
|
||||
<Text style={[styles.title, { color: palette.foreground }]}>{title}</Text>
|
||||
<Text style={{ color: palette.secondaryForeground }}>{ownerName}</Text>
|
||||
<View style={styles.actions}>
|
||||
{showSubscribe ? (
|
||||
<View>
|
||||
<View style={styles.hero}>
|
||||
<CoverImage uri={coverUri} hasCover={hasCover} style={styles.cover} />
|
||||
<Text style={[styles.title, { color: palette.foreground }]}>
|
||||
{title}
|
||||
</Text>
|
||||
<Text style={{ color: palette.secondaryForeground }}>{ownerName}</Text>
|
||||
<View style={styles.actions}>
|
||||
{showSubscribe ? (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={isSubscribed ? "Subscribed" : "Subscribe"}
|
||||
accessibilityState={{ selected: isSubscribed }}
|
||||
hitSlop={8}
|
||||
onPress={onSubscribeToggle}
|
||||
style={[
|
||||
styles.iconAction,
|
||||
{
|
||||
backgroundColor: isSubscribed
|
||||
? palette.surface
|
||||
: palette.accent,
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Ionicons
|
||||
name={isSubscribed ? "checkmark" : "add"}
|
||||
size={24}
|
||||
color={
|
||||
isSubscribed ? palette.foreground : palette.accentForeground
|
||||
}
|
||||
/>
|
||||
</Pressable>
|
||||
) : null}
|
||||
<Button
|
||||
title="Play"
|
||||
icon="play"
|
||||
onPress={onPlay}
|
||||
style={styles.playButton}
|
||||
tint={{
|
||||
background: palette.accent,
|
||||
foreground: palette.accentForeground,
|
||||
}}
|
||||
/>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={isSubscribed ? "Subscribed" : "Subscribe"}
|
||||
accessibilityState={{ selected: isSubscribed }}
|
||||
accessibilityLabel="Shuffle"
|
||||
hitSlop={8}
|
||||
onPress={onSubscribeToggle}
|
||||
style={[
|
||||
styles.iconAction,
|
||||
{
|
||||
backgroundColor: isSubscribed ? palette.surface : palette.accent,
|
||||
},
|
||||
]}
|
||||
onPress={onShuffle}
|
||||
style={[styles.iconAction, { backgroundColor: palette.surface }]}
|
||||
>
|
||||
<Ionicons
|
||||
name={isSubscribed ? "checkmark" : "add"}
|
||||
size={24}
|
||||
color={
|
||||
isSubscribed ? palette.foreground : palette.accentForeground
|
||||
}
|
||||
/>
|
||||
<Ionicons name="shuffle" size={24} color={palette.foreground} />
|
||||
</Pressable>
|
||||
) : null}
|
||||
<Button
|
||||
title="Play"
|
||||
icon="play"
|
||||
onPress={onPlay}
|
||||
style={styles.playButton}
|
||||
tint={{
|
||||
background: palette.accent,
|
||||
foreground: palette.accentForeground,
|
||||
}}
|
||||
/>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Shuffle"
|
||||
hitSlop={8}
|
||||
onPress={onShuffle}
|
||||
style={[styles.iconAction, { backgroundColor: palette.surface }]}
|
||||
>
|
||||
<Ionicons name="shuffle" size={24} color={palette.foreground} />
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
<CollectionDivider color={palette.divider} />
|
||||
</View>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type ListRenderItemInfo,
|
||||
} from "react-native"
|
||||
|
||||
import { CollectionDivider } from "@/components/collection-list"
|
||||
import { CollectionDetailSkeleton } from "@/components/skeletons"
|
||||
import { Button } from "@/components/ui/primitives"
|
||||
import { contentBottomInset, SongListRow } from "@/components/player"
|
||||
@@ -79,6 +80,7 @@ export default function FavoritesScreen() {
|
||||
song={song}
|
||||
favorited={isSongFavorite(song.id)}
|
||||
playlistLabel="Add to Another Playlist"
|
||||
inset
|
||||
onPlay={handlePlaySong}
|
||||
onAction={handleSongMenuAction}
|
||||
/>
|
||||
@@ -155,34 +157,39 @@ const FavoritesHero = memo(function FavoritesHero({
|
||||
const colors = useThemeColors()
|
||||
|
||||
return (
|
||||
<View style={styles.hero}>
|
||||
<View
|
||||
style={[
|
||||
styles.cover,
|
||||
styles.coverPlaceholder,
|
||||
{ backgroundColor: colors.coverPlaceholder },
|
||||
]}
|
||||
>
|
||||
<Ionicons name="star" size={120} color={colors.primary} />
|
||||
</View>
|
||||
<Text style={[styles.title, { color: colors.foreground }]}>{title}</Text>
|
||||
<View style={styles.actions}>
|
||||
<Button
|
||||
title="Play"
|
||||
icon="play"
|
||||
onPress={onPlay}
|
||||
style={styles.playButton}
|
||||
/>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Shuffle"
|
||||
hitSlop={8}
|
||||
onPress={onShuffle}
|
||||
style={[styles.iconAction, { backgroundColor: colors.muted }]}
|
||||
<View>
|
||||
<View style={styles.hero}>
|
||||
<View
|
||||
style={[
|
||||
styles.cover,
|
||||
styles.coverPlaceholder,
|
||||
{ backgroundColor: colors.coverPlaceholder },
|
||||
]}
|
||||
>
|
||||
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
||||
</Pressable>
|
||||
<Ionicons name="star" size={120} color={colors.primary} />
|
||||
</View>
|
||||
<Text style={[styles.title, { color: colors.foreground }]}>
|
||||
{title}
|
||||
</Text>
|
||||
<View style={styles.actions}>
|
||||
<Button
|
||||
title="Play"
|
||||
icon="play"
|
||||
onPress={onPlay}
|
||||
style={styles.playButton}
|
||||
/>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel="Shuffle"
|
||||
hitSlop={8}
|
||||
onPress={onShuffle}
|
||||
style={[styles.iconAction, { backgroundColor: colors.muted }]}
|
||||
>
|
||||
<Ionicons name="shuffle" size={24} color={colors.foreground} />
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
<CollectionDivider />
|
||||
</View>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -476,77 +476,82 @@ function UsersSection({
|
||||
title="People"
|
||||
subtitle="Manage who can access this server."
|
||||
>
|
||||
{users.map((user, index) => (
|
||||
<View key={user._id}>
|
||||
{index > 0 ? (
|
||||
<View
|
||||
style={[styles.divider, { backgroundColor: colors.border }]}
|
||||
/>
|
||||
) : null}
|
||||
<View style={styles.userRow}>
|
||||
<ProfileAvatar user={user} size={44} />
|
||||
<View style={styles.userCopy}>
|
||||
<View style={styles.userNameRow}>
|
||||
<View style={styles.userList}>
|
||||
{users.map((user, index) => (
|
||||
<View
|
||||
key={user._id}
|
||||
style={[
|
||||
styles.userBlock,
|
||||
index > 0
|
||||
? [styles.userBlockSpaced, { borderTopColor: colors.border }]
|
||||
: null,
|
||||
]}
|
||||
>
|
||||
<View style={styles.userRow}>
|
||||
<ProfileAvatar user={user} size={44} />
|
||||
<View style={styles.userCopy}>
|
||||
<View style={styles.userNameRow}>
|
||||
<Text
|
||||
style={[styles.userName, { color: colors.foreground }]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{user.name}
|
||||
</Text>
|
||||
{user.isAdmin ? (
|
||||
<View
|
||||
style={[styles.badge, { backgroundColor: colors.muted }]}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
styles.badgeText,
|
||||
{ color: colors.mutedForeground },
|
||||
]}
|
||||
>
|
||||
Admin
|
||||
</Text>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
<Text
|
||||
style={[styles.userName, { color: colors.foreground }]}
|
||||
style={{ color: colors.mutedForeground }}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{user.name}
|
||||
{user.email}
|
||||
</Text>
|
||||
{user.isAdmin ? (
|
||||
<View
|
||||
style={[styles.badge, { backgroundColor: colors.muted }]}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
styles.badgeText,
|
||||
{ color: colors.mutedForeground },
|
||||
]}
|
||||
>
|
||||
Admin
|
||||
</Text>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
<Text
|
||||
style={{ color: colors.mutedForeground }}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{user.email}
|
||||
</Text>
|
||||
</View>
|
||||
{user._id !== currentUserId ? (
|
||||
<View style={styles.userActions}>
|
||||
<Button
|
||||
title={user.isAdmin ? "Remove Admin" : "Make Admin"}
|
||||
variant="secondary"
|
||||
onPress={() =>
|
||||
void setAdmin({
|
||||
userId: user._id,
|
||||
isAdmin: !user.isAdmin,
|
||||
}).then(
|
||||
() => showSuccess("Updated permissions"),
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
style={styles.userActionButton}
|
||||
/>
|
||||
<Button
|
||||
title="Delete"
|
||||
variant="destructive"
|
||||
onPress={() =>
|
||||
void deleteUserMutation({ userId: user._id }).then(
|
||||
() => showSuccess("User deleted"),
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
style={styles.userActionButton}
|
||||
/>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
{user._id !== currentUserId ? (
|
||||
<View style={styles.userActions}>
|
||||
<Button
|
||||
title={user.isAdmin ? "Remove Admin" : "Make Admin"}
|
||||
variant="secondary"
|
||||
onPress={() =>
|
||||
void setAdmin({
|
||||
userId: user._id,
|
||||
isAdmin: !user.isAdmin,
|
||||
}).then(
|
||||
() => showSuccess("Updated permissions"),
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
style={styles.userActionButton}
|
||||
/>
|
||||
<Button
|
||||
title="Delete"
|
||||
variant="destructive"
|
||||
onPress={() =>
|
||||
void deleteUserMutation({ userId: user._id }).then(
|
||||
() => showSuccess("User deleted"),
|
||||
(error: Error) => showError(error.message)
|
||||
)
|
||||
}
|
||||
style={styles.userActionButton}
|
||||
/>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
))}
|
||||
))}
|
||||
</View>
|
||||
</SettingsCard>
|
||||
</>
|
||||
)
|
||||
@@ -833,6 +838,16 @@ const styles = StyleSheet.create({
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
},
|
||||
userList: {
|
||||
gap: spacing.lg,
|
||||
},
|
||||
userBlock: {
|
||||
gap: spacing.md,
|
||||
},
|
||||
userBlockSpaced: {
|
||||
paddingTop: spacing.lg,
|
||||
borderTopWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
userRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
@@ -855,7 +870,6 @@ const styles = StyleSheet.create({
|
||||
userActions: {
|
||||
flexDirection: "row",
|
||||
gap: spacing.sm,
|
||||
marginTop: spacing.md,
|
||||
},
|
||||
userActionButton: {
|
||||
flex: 1,
|
||||
|
||||
@@ -16,17 +16,18 @@ export default function LibraryLayout() {
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Library",
|
||||
headerRight: route.name === "settings" ? undefined : () => <ProfileHeaderButton />,
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "settings"
|
||||
? undefined
|
||||
: () => [
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
],
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -16,17 +16,18 @@ export default function SearchLayout() {
|
||||
screenOptions={({ route }) => ({
|
||||
...baseOptions,
|
||||
title: tabStackScreenTitles[route.name] ?? "Search",
|
||||
headerRight: route.name === "settings" ? undefined : () => <ProfileHeaderButton />,
|
||||
headerRight:
|
||||
route.name === "index" ? () => <ProfileHeaderButton /> : undefined,
|
||||
unstable_headerRightItems:
|
||||
route.name === "settings"
|
||||
? undefined
|
||||
: () => [
|
||||
route.name === "index"
|
||||
? () => [
|
||||
{
|
||||
type: "custom",
|
||||
element: <ProfileHeaderButton />,
|
||||
hidesSharedBackground: true,
|
||||
},
|
||||
],
|
||||
]
|
||||
: undefined,
|
||||
})}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { memo } from "react"
|
||||
import { StyleSheet, Text, View } from "react-native"
|
||||
|
||||
import { useThemeColors } from "@/lib/theme"
|
||||
|
||||
/** Horizontal inset for rows and dividers in album and playlist track lists. */
|
||||
export const collectionInset = 20
|
||||
|
||||
/** Separates a collection's header from its track list. */
|
||||
export function CollectionDivider({ color }: { color?: string }) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<View
|
||||
style={[styles.divider, { backgroundColor: color ?? colors.border }]}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export const DiscHeader = memo(function DiscHeader({
|
||||
label,
|
||||
color,
|
||||
}: {
|
||||
label: string
|
||||
color?: string
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<Text style={[styles.discHeader, { color: color ?? colors.foreground }]}>
|
||||
{label}
|
||||
</Text>
|
||||
)
|
||||
})
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
divider: {
|
||||
height: StyleSheet.hairlineWidth,
|
||||
marginHorizontal: collectionInset,
|
||||
},
|
||||
discHeader: {
|
||||
fontSize: 17,
|
||||
fontWeight: "700",
|
||||
paddingHorizontal: collectionInset,
|
||||
paddingTop: 24,
|
||||
paddingBottom: 8,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,359 @@
|
||||
import * as Haptics from "expo-haptics"
|
||||
import { SymbolView } from "expo-symbols"
|
||||
import { useCallback, useMemo, useState, type ReactNode } from "react"
|
||||
import {
|
||||
PlatformColor,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
type LayoutChangeEvent,
|
||||
} from "react-native"
|
||||
import { Gesture, GestureDetector } from "react-native-gesture-handler"
|
||||
import Animated, {
|
||||
cancelAnimation,
|
||||
Extrapolation,
|
||||
interpolate,
|
||||
useAnimatedStyle,
|
||||
useSharedValue,
|
||||
withSpring,
|
||||
withTiming,
|
||||
} from "react-native-reanimated"
|
||||
import { scheduleOnRN } from "react-native-worklets"
|
||||
|
||||
const ACTION_WIDTH = 82
|
||||
const CARD_ROUNDING_REVEAL = 40
|
||||
const PILL_MIN_MARGIN = 10
|
||||
const PILL_COMMITTED_MARGIN = 6
|
||||
const PILL_WIDTH_INPUT = [24, ACTION_WIDTH, 220]
|
||||
const PILL_WIDTH_OUTPUT = [0, 62, 200]
|
||||
const PILL_HEIGHT_INPUT = [0, 24, 62, 140, 200]
|
||||
const PILL_HEIGHT_RATIO = [0, 0.3, 0.77, 0.82, 0.86]
|
||||
const ICON_FULL_SIZE_REVEAL = 64
|
||||
const FULL_SWIPE_RATIO = 0.55
|
||||
const FLING_VELOCITY = 400
|
||||
const SETTLE_SPRING = { duration: 450, dampingRatio: 1 }
|
||||
const LABEL_SPRING = { duration: 300, dampingRatio: 0.85 }
|
||||
const SLIDE_OUT = { duration: 200 }
|
||||
const COLLAPSE = { duration: 250 }
|
||||
|
||||
/**
|
||||
* Keeps at most one row open, like a `UITableView`: opening a row closes the
|
||||
* previous one, and `closeOpenRow` closes whichever is open (call it when the
|
||||
* list starts scrolling).
|
||||
*/
|
||||
export type SwipeRowGroup = {
|
||||
setOpen: (close: () => void) => void
|
||||
clear: (close: () => void) => void
|
||||
closeOpenRow: () => void
|
||||
}
|
||||
|
||||
export function useSwipeRowGroup(): SwipeRowGroup {
|
||||
const [group] = useState<SwipeRowGroup>(() => {
|
||||
let openRowClose: (() => void) | null = null
|
||||
return {
|
||||
setOpen(close) {
|
||||
if (openRowClose && openRowClose !== close) openRowClose()
|
||||
openRowClose = close
|
||||
},
|
||||
clear(close) {
|
||||
if (openRowClose === close) openRowClose = null
|
||||
},
|
||||
closeOpenRow() {
|
||||
openRowClose?.()
|
||||
openRowClose = null
|
||||
},
|
||||
}
|
||||
})
|
||||
return group
|
||||
}
|
||||
|
||||
type SwipeToRemoveRowProps = {
|
||||
group: SwipeRowGroup
|
||||
backgroundColor: string
|
||||
actionAccessibilityLabel: string
|
||||
/** Resolves `false` if the removal failed, which restores the row. */
|
||||
onRemove: () => Promise<boolean>
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
/**
|
||||
* The iOS 26 trailing swipe-to-delete row: the row lifts into a rounded card
|
||||
* and a red pill grows in the revealed space. Release past half the pill to
|
||||
* leave it open, or drag past the full-swipe point (haptic, the pill fills the
|
||||
* space) to remove on release.
|
||||
*/
|
||||
export function SwipeToRemoveRow(props: SwipeToRemoveRowProps) {
|
||||
const [generation, setGeneration] = useState(0)
|
||||
const restore = useCallback(() => setGeneration((value) => value + 1), [])
|
||||
|
||||
return <SwipeRowBody key={generation} {...props} onRestore={restore} />
|
||||
}
|
||||
|
||||
function SwipeRowBody({
|
||||
group,
|
||||
backgroundColor,
|
||||
actionAccessibilityLabel,
|
||||
onRemove,
|
||||
onRestore,
|
||||
children,
|
||||
}: SwipeToRemoveRowProps & { onRestore: () => void }) {
|
||||
const width = useSharedValue(0)
|
||||
const height = useSharedValue(0)
|
||||
const translateX = useSharedValue(0)
|
||||
const startX = useSharedValue(0)
|
||||
const committed = useSharedValue(false)
|
||||
const commitProgress = useSharedValue(0)
|
||||
const collapse = useSharedValue(0)
|
||||
const removing = useSharedValue(false)
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
|
||||
const close = useCallback(() => {
|
||||
if (removing.value) return
|
||||
translateX.value = withSpring(0, SETTLE_SPRING)
|
||||
setIsOpen(false)
|
||||
}, [removing, translateX])
|
||||
|
||||
const handleSwipeStart = useCallback(() => group.setOpen(close), [close, group])
|
||||
|
||||
const handleSettle = useCallback(
|
||||
(open: boolean) => {
|
||||
setIsOpen(open)
|
||||
if (!open) group.clear(close)
|
||||
},
|
||||
[close, group]
|
||||
)
|
||||
|
||||
const handleRemove = useCallback(async () => {
|
||||
group.clear(close)
|
||||
if (!(await onRemove())) onRestore()
|
||||
}, [close, group, onRemove, onRestore])
|
||||
|
||||
const animateRemoval = useCallback(() => {
|
||||
"worklet"
|
||||
removing.value = true
|
||||
commitProgress.value = withSpring(1, LABEL_SPRING)
|
||||
translateX.value = withTiming(-width.value, SLIDE_OUT, (slid) => {
|
||||
if (!slid) return
|
||||
collapse.value = withTiming(1, COLLAPSE, (collapsed) => {
|
||||
if (collapsed) scheduleOnRN(handleRemove)
|
||||
})
|
||||
})
|
||||
}, [collapse, commitProgress, handleRemove, removing, translateX, width])
|
||||
|
||||
const pan = useMemo(() => {
|
||||
const gesture = Gesture.Pan()
|
||||
.failOffsetY([-10, 10])
|
||||
.onStart(() => {
|
||||
if (removing.value) return
|
||||
cancelAnimation(translateX)
|
||||
startX.value = translateX.value
|
||||
scheduleOnRN(handleSwipeStart)
|
||||
})
|
||||
.onUpdate((event) => {
|
||||
if (removing.value) return
|
||||
const rowWidth = width.value
|
||||
const x = Math.max(
|
||||
-rowWidth,
|
||||
Math.min(0, startX.value + event.translationX)
|
||||
)
|
||||
translateX.value = x
|
||||
|
||||
const shouldCommit = -x > rowWidth * FULL_SWIPE_RATIO
|
||||
if (shouldCommit !== committed.value) {
|
||||
committed.value = shouldCommit
|
||||
commitProgress.value = withSpring(shouldCommit ? 1 : 0, LABEL_SPRING)
|
||||
scheduleOnRN(impact)
|
||||
}
|
||||
})
|
||||
.onEnd((event) => {
|
||||
if (removing.value) return
|
||||
if (committed.value) {
|
||||
animateRemoval()
|
||||
return
|
||||
}
|
||||
|
||||
const velocity = event.velocityX
|
||||
const open =
|
||||
velocity < -FLING_VELOCITY ||
|
||||
(velocity <= FLING_VELOCITY && translateX.value < -ACTION_WIDTH / 2)
|
||||
translateX.value = withSpring(open ? -ACTION_WIDTH : 0, {
|
||||
...SETTLE_SPRING,
|
||||
velocity,
|
||||
})
|
||||
scheduleOnRN(handleSettle, open)
|
||||
})
|
||||
|
||||
return isOpen
|
||||
? gesture.activeOffsetX([-10, 10])
|
||||
: gesture.activeOffsetX(-10).failOffsetX(10)
|
||||
}, [
|
||||
animateRemoval,
|
||||
commitProgress,
|
||||
committed,
|
||||
handleSettle,
|
||||
handleSwipeStart,
|
||||
isOpen,
|
||||
removing,
|
||||
startX,
|
||||
translateX,
|
||||
width,
|
||||
])
|
||||
|
||||
const handleLayout = useCallback(
|
||||
(event: LayoutChangeEvent) => {
|
||||
if (removing.value) return
|
||||
width.value = event.nativeEvent.layout.width
|
||||
height.value = event.nativeEvent.layout.height
|
||||
},
|
||||
[height, removing, width]
|
||||
)
|
||||
|
||||
const containerStyle = useAnimatedStyle(() =>
|
||||
collapse.value > 0 ? { height: height.value * (1 - collapse.value) } : {}
|
||||
)
|
||||
|
||||
const contentStyle = useAnimatedStyle(() => ({
|
||||
borderRadius: interpolate(
|
||||
-translateX.value,
|
||||
[0, CARD_ROUNDING_REVEAL],
|
||||
[0, height.value / 2],
|
||||
Extrapolation.CLAMP
|
||||
),
|
||||
transform: [{ translateX: translateX.value }],
|
||||
}))
|
||||
|
||||
const cardFillStyle = useAnimatedStyle(() => ({
|
||||
opacity: interpolate(
|
||||
-translateX.value,
|
||||
[0, CARD_ROUNDING_REVEAL],
|
||||
[0, 1],
|
||||
Extrapolation.CLAMP
|
||||
),
|
||||
}))
|
||||
|
||||
const actionStyle = useAnimatedStyle(() => ({
|
||||
width: -translateX.value,
|
||||
}))
|
||||
|
||||
// The pill grows out of a dot centered in the revealed space; past the
|
||||
// full-swipe point it stretches to fill that space.
|
||||
const pillStyle = useAnimatedStyle(() => {
|
||||
const revealed = -translateX.value
|
||||
const rowHeight = height.value
|
||||
const resting = Math.min(
|
||||
revealed - PILL_MIN_MARGIN * 2,
|
||||
interpolate(
|
||||
revealed,
|
||||
PILL_WIDTH_INPUT,
|
||||
PILL_WIDTH_OUTPUT,
|
||||
Extrapolation.EXTEND
|
||||
)
|
||||
)
|
||||
const pillWidth = Math.max(
|
||||
0,
|
||||
resting +
|
||||
(revealed - PILL_COMMITTED_MARGIN * 2 - resting) *
|
||||
commitProgress.value
|
||||
)
|
||||
const restingHeight = interpolate(
|
||||
pillWidth,
|
||||
PILL_HEIGHT_INPUT,
|
||||
PILL_HEIGHT_RATIO.map((ratio) => ratio * rowHeight),
|
||||
Extrapolation.CLAMP
|
||||
)
|
||||
const pillHeight =
|
||||
restingHeight +
|
||||
(rowHeight - PILL_COMMITTED_MARGIN * 2 - restingHeight) *
|
||||
commitProgress.value
|
||||
return {
|
||||
width: pillWidth,
|
||||
height: pillHeight,
|
||||
borderRadius: pillHeight / 2,
|
||||
opacity: 1 - collapse.value,
|
||||
}
|
||||
})
|
||||
|
||||
const iconStyle = useAnimatedStyle(() => ({
|
||||
transform: [
|
||||
{
|
||||
scale: interpolate(
|
||||
-translateX.value,
|
||||
[PILL_WIDTH_INPUT[0], ICON_FULL_SIZE_REVEAL],
|
||||
[0, 1],
|
||||
Extrapolation.CLAMP
|
||||
),
|
||||
},
|
||||
],
|
||||
}))
|
||||
|
||||
return (
|
||||
<Animated.View
|
||||
onLayout={handleLayout}
|
||||
style={[styles.container, containerStyle]}
|
||||
>
|
||||
<Animated.View style={[styles.action, actionStyle]}>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={actionAccessibilityLabel}
|
||||
onPress={() => animateRemoval()}
|
||||
style={styles.actionButton}
|
||||
>
|
||||
<Animated.View style={[styles.pill, pillStyle]}>
|
||||
<Animated.View style={iconStyle}>
|
||||
<SymbolView
|
||||
name="minus.circle.fill"
|
||||
size={20}
|
||||
tintColor="white"
|
||||
/>
|
||||
</Animated.View>
|
||||
</Animated.View>
|
||||
</Pressable>
|
||||
</Animated.View>
|
||||
<GestureDetector gesture={pan}>
|
||||
<Animated.View style={[styles.card, { backgroundColor }, contentStyle]}>
|
||||
<Animated.View
|
||||
pointerEvents="none"
|
||||
style={[styles.cardFill, cardFillStyle]}
|
||||
/>
|
||||
{children}
|
||||
{isOpen ? (
|
||||
<Pressable
|
||||
accessible={false}
|
||||
onPress={close}
|
||||
style={StyleSheet.absoluteFill}
|
||||
/>
|
||||
) : null}
|
||||
</Animated.View>
|
||||
</GestureDetector>
|
||||
</Animated.View>
|
||||
)
|
||||
}
|
||||
|
||||
function impact() {
|
||||
void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { overflow: "hidden" },
|
||||
card: { overflow: "hidden" },
|
||||
cardFill: {
|
||||
...StyleSheet.absoluteFill,
|
||||
backgroundColor: PlatformColor("tertiarySystemFill"),
|
||||
},
|
||||
action: {
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
},
|
||||
actionButton: {
|
||||
flex: 1,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
pill: {
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
overflow: "hidden",
|
||||
backgroundColor: PlatformColor("systemRed"),
|
||||
},
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import { collectionInset } from "@/components/collection-list"
|
||||
import { CoverImage } from "@/components/cover-image"
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
@@ -20,6 +21,7 @@ export const SongRow = memo(function SongRow({
|
||||
contextMenu,
|
||||
trailing,
|
||||
palette,
|
||||
inset = false,
|
||||
}: {
|
||||
song: BrowseSong
|
||||
onPress?: () => void
|
||||
@@ -28,6 +30,8 @@ export const SongRow = memo(function SongRow({
|
||||
}
|
||||
trailing?: React.ReactNode
|
||||
palette?: Pick<CoverPalette, "foreground" | "secondaryForeground" | "divider">
|
||||
/** Album/playlist layout: the divider starts at the title, not the artwork. */
|
||||
inset?: boolean
|
||||
}) {
|
||||
const { config } = useServerConfig()
|
||||
const colors = useThemeColors()
|
||||
@@ -36,20 +40,10 @@ export const SongRow = memo(function SongRow({
|
||||
const foreground = palette?.foreground ?? colors.foreground
|
||||
const secondaryForeground =
|
||||
palette?.secondaryForeground ?? colors.mutedForeground
|
||||
const divider = palette?.divider ?? colors.border
|
||||
|
||||
const row = (
|
||||
<Pressable
|
||||
style={[
|
||||
styles.row,
|
||||
{ borderBottomColor: palette?.divider ?? colors.border },
|
||||
]}
|
||||
onPress={onPress}
|
||||
>
|
||||
<CoverImage
|
||||
uri={albumCoverUrl(config.serverUrl, song.album.id)}
|
||||
hasCover={song.album.cover != null}
|
||||
style={styles.rowArtwork}
|
||||
/>
|
||||
const content = (
|
||||
<>
|
||||
<View style={styles.rowMeta}>
|
||||
<Text style={[styles.rowTitle, { color: foreground }]} numberOfLines={1}>
|
||||
{song.title}
|
||||
@@ -62,6 +56,28 @@ export const SongRow = memo(function SongRow({
|
||||
{formatDuration(song.durationSeconds)}
|
||||
</Text>
|
||||
{trailing}
|
||||
</>
|
||||
)
|
||||
|
||||
const row = (
|
||||
<Pressable
|
||||
style={
|
||||
inset ? styles.insetRow : [styles.row, { borderBottomColor: divider }]
|
||||
}
|
||||
onPress={onPress}
|
||||
>
|
||||
<CoverImage
|
||||
uri={albumCoverUrl(config.serverUrl, song.album.id)}
|
||||
hasCover={song.album.cover != null}
|
||||
style={styles.rowArtwork}
|
||||
/>
|
||||
{inset ? (
|
||||
<View style={[styles.insetContent, { borderBottomColor: divider }]}>
|
||||
{content}
|
||||
</View>
|
||||
) : (
|
||||
content
|
||||
)}
|
||||
</Pressable>
|
||||
)
|
||||
|
||||
@@ -86,6 +102,7 @@ export const SongListRow = memo(function SongListRow({
|
||||
favorited,
|
||||
playlistLabel,
|
||||
palette,
|
||||
inset,
|
||||
onPlay,
|
||||
onAction,
|
||||
}: {
|
||||
@@ -93,6 +110,7 @@ export const SongListRow = memo(function SongListRow({
|
||||
favorited: boolean
|
||||
playlistLabel?: string
|
||||
palette?: Pick<CoverPalette, "foreground" | "secondaryForeground" | "divider">
|
||||
inset?: boolean
|
||||
onPlay: (song: BrowseSong) => void
|
||||
onAction: (song: BrowseSong, action: MediaAction) => void
|
||||
}) {
|
||||
@@ -102,6 +120,7 @@ export const SongListRow = memo(function SongListRow({
|
||||
<SongRow
|
||||
song={song}
|
||||
palette={palette}
|
||||
inset={inset}
|
||||
onPress={handlePress}
|
||||
contextMenu={{
|
||||
favorited,
|
||||
@@ -134,6 +153,24 @@ const styles = StyleSheet.create({
|
||||
paddingHorizontal: spacing.lg,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
insetRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.md,
|
||||
paddingLeft: collectionInset,
|
||||
},
|
||||
insetContent: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
alignSelf: "stretch",
|
||||
gap: spacing.md,
|
||||
minHeight: 64,
|
||||
paddingVertical: 10,
|
||||
marginRight: collectionInset,
|
||||
borderBottomWidth: StyleSheet.hairlineWidth,
|
||||
},
|
||||
rowArtwork: {
|
||||
width: 44,
|
||||
height: 44,
|
||||
|
||||
Reference in new issue
Block a user