Compare commits

...
5 changed files with 72 additions and 53 deletions

No files matched your search

@@ -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
}
@@ -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<MenuAction["image"]> & 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)}
/>
))}
@@ -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<MediaAction, ComponentProps<typeof Ionicons>["name"]>
+4
View File
@@ -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 },
+41 -41
View File
@@ -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 && (
<SwipeAction
side={-1}
secondary
paired
remove
x={x}
height={height}
progress={commitProgress}
open={open === -1}
onPress={() => {
close()
onRemove?.()
}}
/>
)}
<SwipeAction
side={-1}
paired={hasRemove}
remove={hasRemove}
x={x}
height={height}
progress={commitProgress}
open={open === -1}
onPress={() => activate(-1)}
/>
{hasRemove && (
<SwipeAction
side={-1}
secondary
paired
x={x}
height={height}
progress={commitProgress}
open={open === -1}
onPress={close}
/>
)}
<GestureDetector gesture={gesture}>
<Animated.View
accessible
@@ -266,10 +265,7 @@ export function SongSwipeRow({
: []),
]}
onAccessibilityAction={(event) => {
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({
) : (
<SymbolView
name={
side > 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"