From d2f940b7f7d8f331a3619dce3752277b7ca8c887 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Mon, 16 Nov 2026 20:05:03 -0500 Subject: [PATCH] fix(mobile): let playlist owners remove songs on iOS PR #85 swapped the iOS swipe-to-remove for SongSwipeRow, leaving no way to remove a single song on iOS. Enable the trailing Remove swipe action on iOS too, make it the outer full-swipe action with Download beside it, and size the trailing pair like the leading one. Add "Remove from Playlist" to the song context menu for owned playlists on both platforms. Co-Authored-By: Claude Opus 5.5 --- .../app/(app)/(tabs)/home/playlist/[id].tsx | 22 +++-- apps/mobile/components/media-context-menu.tsx | 16 ++++ apps/mobile/components/media-menu.android.tsx | 1 + apps/mobile/components/player.tsx | 4 + apps/mobile/components/song-swipe-row.tsx | 82 +++++++++---------- 5 files changed, 72 insertions(+), 53 deletions(-) diff --git a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx index e9f46f1..159885d 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]) @@ -432,6 +434,7 @@ const PlaylistSongRow = memo(function PlaylistSongRow({ playlistLabel={PLAYLIST_LABEL} palette={palette} inset + removable={removable} swipe={ Platform.OS !== "web" ? { @@ -439,12 +442,7 @@ const PlaylistSongRow = memo(function PlaylistSongRow({ backgroundColor: palette.background, onPlayNext: () => onAction(song, "play-next"), onAddToQueue: () => onAction(song, "play-last"), - onRemove: - Platform.OS === "android" && removable - ? () => { - void onRemove(song.id) - } - : undefined, + 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 3c77866..556fe20 100644 --- a/apps/mobile/components/player.tsx +++ b/apps/mobile/components/player.tsx @@ -160,6 +160,7 @@ export const SongListRow = memo(function SongListRow({ palette, inset, swipe, + removable, onPlay, onAction, }: { @@ -175,6 +176,8 @@ export const SongListRow = memo(function SongListRow({ onRemove?: () => void backgroundColor: string } + /** Shows "Remove from Playlist" in the context menu. */ + removable?: boolean onPlay: (song: BrowseSong) => void onAction: (song: BrowseSong, action: MediaAction) => void }) { @@ -202,6 +205,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 e19973e..4c212ef 100644 --- a/apps/mobile/components/song-swipe-row.tsx +++ b/apps/mobile/components/song-swipe-row.tsx @@ -31,14 +31,19 @@ import type { SwipeRowGroup } from "@/components/ios-swipe-to-remove-row" const IS_ANDROID = Platform.OS === "android" const ACTION_WIDTH = 82 -const LEADING_ACTION_WIDTH = 72 +/** Width of each action when two share a side. */ +const PAIRED_ACTION_WIDTH = 72 const SPRING = { duration: 450, dampingRatio: 1 } function impact() { void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium) } -/** A tap competes with the swipe so dragging a moving row never starts playback. */ +/** + * A tap competes with the swipe so dragging a moving row never starts playback. + * A full swipe commits the outer action: Add to Queue on the leading side, and + * Remove on the trailing side when `onRemove` is set. + */ export function SongSwipeRow({ children, style, @@ -58,7 +63,8 @@ export function SongSwipeRow({ onAddToQueue: () => void onRemove?: () => void }) { - const hasRemove = IS_ANDROID && !!onRemove + const hasRemove = !!onRemove + const trailingWidth = hasRemove ? PAIRED_ACTION_WIDTH * 2 : ACTION_WIDTH const x = useSharedValue(0) const startX = useSharedValue(0) const width = useSharedValue(0) @@ -89,9 +95,10 @@ export function SongSwipeRow({ (side: number) => { close() if (side > 0) onAddToQueue() - // Download is intentionally a placeholder. + // Without Remove, the trailing action is the Download placeholder. + else onRemove?.() }, - [close, onAddToQueue] + [close, onAddToQueue, onRemove] ) const tapRow = useCallback(() => { if (open) close() @@ -117,9 +124,7 @@ export function SongSwipeRow({ const commit = Math.abs(x.value) > Math.max( - x.value > 0 - ? LEADING_ACTION_WIDTH * 2 - : ACTION_WIDTH * (hasRemove ? 2 : 1), + x.value > 0 ? PAIRED_ACTION_WIDTH * 2 : trailingWidth, width.value * 0.55 ) if (commit !== committed.value) { @@ -141,10 +146,7 @@ export function SongSwipeRow({ ? side : 0 x.value = withSpring( - target * - (target > 0 - ? LEADING_ACTION_WIDTH * 2 - : ACTION_WIDTH * (hasRemove ? 2 : 1)), + target * (target > 0 ? PAIRED_ACTION_WIDTH * 2 : trailingWidth), { ...SPRING, velocity: event.velocityX, @@ -167,7 +169,6 @@ export function SongSwipeRow({ return Gesture.Exclusive(pan, tap) }, [ activate, - hasRemove, begin, close, commitProgress, @@ -175,6 +176,7 @@ export function SongSwipeRow({ settle, startX, tapRow, + trailingWidth, width, x, ]) @@ -227,31 +229,28 @@ export function SongSwipeRow({ onPlayNext() }} /> - {hasRemove && ( - { - close() - onRemove?.() - }} - /> - )} activate(-1)} /> + {hasRemove && ( + + )} { - if (event.nativeEvent.actionName === "remove" && hasRemove) { - close() - onRemove?.() - } + if (event.nativeEvent.actionName === "remove") activate(-1) if (event.nativeEvent.actionName === "addToQueue") activate(1) if (event.nativeEvent.actionName === "playNext") { close() @@ -337,10 +333,10 @@ function SwipeAction({ const resting = Math.max( 0, Math.min( - revealed - (side > 0 ? 10 : 20), + revealed - (paired ? 10 : 20), interpolate( revealed, - [24, side > 0 ? LEADING_ACTION_WIDTH : ACTION_WIDTH, 220], + [24, paired ? PAIRED_ACTION_WIDTH : ACTION_WIDTH, 220], [0, 62, 200] ) ) @@ -404,7 +400,9 @@ function SwipeAction({ styles.pill, { backgroundColor: remove - ? "#d32f2f" + ? IS_ANDROID + ? "#d32f2f" + : "#ff3b30" : side > 0 ? secondary ? "#6b5bff" @@ -432,11 +430,13 @@ function SwipeAction({ ) : ( 0 - ? secondary - ? "text.line.first.and.arrowtriangle.forward" - : "text.line.last.and.arrowtriangle.forward" - : "arrow.down" + remove + ? "trash" + : side > 0 + ? secondary + ? "text.line.first.and.arrowtriangle.forward" + : "text.line.last.and.arrowtriangle.forward" + : "arrow.down" } size={22} tintColor="white" -- 2.54.1