diff --git a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx index a32bf8c..1b7b644 100644 --- a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx @@ -488,8 +488,46 @@ const AlbumTrackRow = memo(function AlbumTrackRow({ action: MediaAction ) => Promise }) { - const Row = Platform.OS === "ios" ? SongSwipeRow : Pressable const { config } = useServerConfig() + const handlePress = () => void onPlay(track.id as Id<"songs">, songIds) + const content = ( + <> + + {number} + + + + + {track.title} + + {track.artists ? ( + + {track.artists.join(", ")} + + ) : null} + + + {formatDuration(track.durationSeconds)} + + + + ) return ( void onAction(track, album, action)} > - void onAction(track, album, "play-next")} - style={styles.trackRow} - onPress={() => void onPlay(track.id as Id<"songs">, songIds)} - > - void onAction(track, album, "play-next")} + style={styles.trackRow} + onPress={handlePress} > - {number} - - - - - {track.title} - - {track.artists ? ( - - {track.artists.join(", ")} - - ) : null} - - - {formatDuration(track.durationSeconds)} - - - + {content} + + ) : ( + + {content} + + )} ) diff --git a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx index f11a0d1..7e54329 100644 --- a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx @@ -202,12 +202,6 @@ function PlaylistContent({ [playFromSong, songIds, playlistId] ) - const handleSongMenuAction = useCallback( - (song: BrowseSong, action: MediaAction) => - void handleSongAction(song, action), - [handleSongAction] - ) - const handleRemoveSong = useCallback( async (songId: Id<"songs">) => { if (!playlistId) return false @@ -226,6 +220,14 @@ function PlaylistContent({ [playlistId, removeSongs] ) + const handleSongMenuAction = useCallback( + (song: BrowseSong, action: MediaAction) => { + if (action === "remove-from-playlist") void handleRemoveSong(song.id) + else void handleSongAction(song, action) + }, + [handleRemoveSong, handleSongAction] + ) + const handlePlay = useCallback(() => { if (playlistId) void playPlaylist(playlistId, songIds) }, [playPlaylist, playlistId, songIds]) @@ -433,12 +435,14 @@ const PlaylistSongRow = memo(function PlaylistSongRow({ playlistLabel={PLAYLIST_LABEL} palette={palette} inset + removable={removable} swipe={ Platform.OS === "ios" ? { group: swipeGroup, backgroundColor: palette.background, onPlayNext: () => onAction(song, "play-next"), + onRemove: removable ? () => void handleRemove() : undefined, } : undefined } diff --git a/apps/mobile/components/media-context-menu.tsx b/apps/mobile/components/media-context-menu.tsx index 8a63f45..7e994ac 100644 --- a/apps/mobile/components/media-context-menu.tsx +++ b/apps/mobile/components/media-context-menu.tsx @@ -32,6 +32,7 @@ export type MediaAction = | "favorite" | "go-artist" | "go-album" + | "remove-from-playlist" | "delete-playlist" export type MediaNavigation = { @@ -54,6 +55,7 @@ export type MediaMenuConfig = { playlistLabel?: string favorited?: boolean showFavorite?: boolean + showRemoveFromPlaylist?: boolean stationArtistId?: string navigation?: MediaNavigation share?: MediaShareContext @@ -76,6 +78,7 @@ const MEDIA_ACTION_ITEMS: { playlistLabel: string ) => string image: NonNullable & string + destructive?: boolean }[] = [ { action: "playlist", @@ -119,6 +122,12 @@ const MEDIA_ACTION_ITEMS: { `${favorited ? "Unfavorite" : "Favorite"}${countSuffix}`, image: "star", }, + { + action: "remove-from-playlist", + label: () => "Remove from Playlist", + image: "minus.circle", + destructive: true, + }, { action: "delete-playlist", label: () => "Delete Playlist", @@ -134,6 +143,10 @@ function isActionIncluded( return false } + if (action === "remove-from-playlist") { + return config.showRemoveFromPlaylist === true + } + if (config.includeActions) { return config.includeActions.includes(action) } @@ -190,6 +203,7 @@ export function buildMediaMenuActions( id: item.action, title: item.label(countSuffix, favorited, playlistLabel), image: item.action === "favorite" && favorited ? "star.fill" : item.image, + ...(item.destructive ? { attributes: { destructive: true } } : {}), }) } @@ -324,6 +338,7 @@ const NativeContextMenuAction: ComponentType<{ identifier: string title: string icon?: string + destructive?: boolean onSelected: () => void }> | null = Platform.OS === "ios" @@ -377,6 +392,7 @@ function NativeMediaContextMenu({ identifier={action.id ?? action.title} title={action.title} icon={typeof action.image === "string" ? action.image : undefined} + destructive={action.attributes?.destructive} onSelected={() => handleAction(action.id as MediaAction)} /> ))} diff --git a/apps/mobile/components/media-menu.android.tsx b/apps/mobile/components/media-menu.android.tsx index 137e62c..cd7ad94 100644 --- a/apps/mobile/components/media-menu.android.tsx +++ b/apps/mobile/components/media-menu.android.tsx @@ -25,6 +25,7 @@ const actionIcons = { favorite: "star-outline", "go-artist": "person-outline", "go-album": "disc-outline", + "remove-from-playlist": "remove-circle-outline", "delete-playlist": "trash-outline", } satisfies Record["name"]> diff --git a/apps/mobile/components/player.tsx b/apps/mobile/components/player.tsx index 0aaf866..24558f5 100644 --- a/apps/mobile/components/player.tsx +++ b/apps/mobile/components/player.tsx @@ -45,6 +45,7 @@ export const SongRow = memo(function SongRow({ swipe?: { group: SwipeRowGroup onPlayNext: () => void + onRemove?: () => void backgroundColor: string } /** Album/playlist layout: the divider starts at the title, not the artwork. */ @@ -111,6 +112,7 @@ export const SongRow = memo(function SongRow({ void + onRemove?: () => void backgroundColor: string } + /** Shows "Remove from Playlist" in the context menu. */ + removable?: boolean onPlay: (song: BrowseSong) => void onAction: (song: BrowseSong, action: MediaAction) => void }) { @@ -196,6 +202,7 @@ export const SongListRow = memo(function SongListRow({ stationArtistId: song.artist.id, favorited, playlistLabel, + showRemoveFromPlaylist: removable, navigation: { artist: { id: song.artist.id }, album: { id: song.album.id }, diff --git a/apps/mobile/components/song-swipe-row.tsx b/apps/mobile/components/song-swipe-row.tsx index 3e2f044..df595a2 100644 --- a/apps/mobile/components/song-swipe-row.tsx +++ b/apps/mobile/components/song-swipe-row.tsx @@ -41,6 +41,7 @@ export function SongSwipeRow({ group, onPress, onPlayNext, + onRemove, }: { children: ReactNode style?: StyleProp @@ -48,7 +49,10 @@ export function SongSwipeRow({ group: SwipeRowGroup onPress?: () => void onPlayNext: () => void + /** Adds a destructive trailing Remove action that a full swipe commits. */ + onRemove?: () => void }) { + const trailingWidth = onRemove ? ACTION_WIDTH * 2 : ACTION_WIDTH const x = useSharedValue(0) const startX = useSharedValue(0) const width = useSharedValue(0) @@ -79,9 +83,10 @@ export function SongSwipeRow({ (side: number) => { close() if (side > 0) onPlayNext() + else onRemove?.() // Download is intentionally a placeholder. }, - [close, onPlayNext] + [close, onPlayNext, onRemove] ) const tapRow = useCallback(() => { if (open) close() @@ -105,7 +110,11 @@ export function SongSwipeRow({ Math.min(width.value, startX.value + event.translationX) ) const commit = - Math.abs(x.value) > Math.max(ACTION_WIDTH, width.value * 0.55) + Math.abs(x.value) > + Math.max( + x.value > 0 ? ACTION_WIDTH : trailingWidth, + width.value * 0.55 + ) if (commit !== committed.value) { committed.value = commit commitProgress.value = withSpring(commit ? 1 : 0, SPRING) @@ -124,10 +133,13 @@ export function SongSwipeRow({ Math.abs(x.value) > 10 && projected * side > ACTION_WIDTH / 2 ? side : 0 - x.value = withSpring(target * ACTION_WIDTH, { - ...SPRING, - velocity: event.velocityX, - }) + x.value = withSpring( + target * (target < 0 ? trailingWidth : ACTION_WIDTH), + { + ...SPRING, + velocity: event.velocityX, + } + ) scheduleOnRN(settle, target) }) .onFinalize((_event, success) => { @@ -152,6 +164,7 @@ export function SongSwipeRow({ settle, startX, tapRow, + trailingWidth, width, x, ]) @@ -190,13 +203,27 @@ export function SongSwipeRow({ open={open === 1} onPress={() => activate(1)} /> + {onRemove ? ( + activate(-1)} + /> + ) : null} activate(-1)} + onPress={onRemove ? close : () => activate(-1)} /> { if (event.nativeEvent.actionName === "playNext") activate(1) + if (event.nativeEvent.actionName === "remove") activate(-1) }} style={[styles.row, { backgroundColor }, rowStyle]} > @@ -223,8 +254,15 @@ export function SongSwipeRow({ ) } +/** + * Paired actions split the revealed width: the edge action grows to fill it as + * a full swipe commits, while the inner `secondary` action shrinks away. + */ function SwipeAction({ side, + paired = false, + secondary = false, + remove = false, x, height, progress, @@ -232,17 +270,36 @@ function SwipeAction({ onPress, }: { side: 1 | -1 + paired?: boolean + secondary?: boolean + remove?: boolean x: SharedValue height: SharedValue progress: SharedValue open: boolean onPress: () => void }) { - const actionStyle = useAnimatedStyle(() => ({ - width: Math.max(0, x.value * side), - })) + const revealedWidth = () => { + "worklet" + const total = Math.max(0, x.value * side) + if (!paired) return total + const edge = (total * (1 + progress.value)) / 2 + return secondary ? total - edge : edge + } + const actionStyle = useAnimatedStyle(() => { + const total = Math.max(0, x.value * side) + const own = revealedWidth() + return { + width: own, + ...(secondary + ? side > 0 + ? { left: total - own } + : { right: total - own } + : {}), + } + }) const pillStyle = useAnimatedStyle(() => { - const revealed = Math.max(0, x.value * side) + const revealed = revealedWidth() const resting = Math.max( 0, Math.min( @@ -271,7 +328,7 @@ function SwipeAction({ transform: [ { scale: interpolate( - x.value * side, + revealedWidth(), [24, 64], [0, 1], Extrapolation.CLAMP @@ -292,23 +349,33 @@ function SwipeAction({ > 0 ? "Play Next" : "Download"} + accessibilityLabel={ + remove ? "Remove from Playlist" : side > 0 ? "Play Next" : "Download" + } onPress={onPress} style={styles.actionButton} > 0 ? "#6b5bff" : "#008dff" }, + { + backgroundColor: remove + ? "#ff3b30" + : side > 0 + ? "#6b5bff" + : "#008dff", + }, pillStyle, ]} > 0 - ? "text.line.first.and.arrowtriangle.forward" - : "arrow.down" + remove + ? "trash" + : side > 0 + ? "text.line.first.and.arrowtriangle.forward" + : "arrow.down" } size={22} tintColor="white"