feat(mobile): add songs to queue with a full swipe

This commit is contained in:
joshuafhiggins committed 2026-11-15 16:07:49 -05:00 Verified
1 parent dce66b7697
commit bd21655b2e
4 files changed
+63 -12

No files matched your search

@@ -523,6 +523,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
group={swipeGroup}
backgroundColor={palette.background}
onPlayNext={() => void onAction(track, album, "play-next")}
onAddToQueue={() => void onAction(track, album, "play-last")}
style={styles.trackRow}
onPress={() => void onPlay(track.id as Id<"songs">, songIds)}
>
@@ -439,6 +439,7 @@ const PlaylistSongRow = memo(function PlaylistSongRow({
group: swipeGroup,
backgroundColor: palette.background,
onPlayNext: () => onAction(song, "play-next"),
onAddToQueue: () => onAction(song, "play-last"),
}
: undefined
}
+3
View File
@@ -45,6 +45,7 @@ export const SongRow = memo(function SongRow({
swipe?: {
group: SwipeRowGroup
onPlayNext: () => void
onAddToQueue: () => 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({
<SongSwipeRow
group={swipe.group}
onPlayNext={swipe.onPlayNext}
onAddToQueue={swipe.onAddToQueue}
backgroundColor={swipe.backgroundColor}
onPress={onPress}
style={rowStyle}
@@ -167,6 +169,7 @@ export const SongListRow = memo(function SongListRow({
swipe?: {
group: SwipeRowGroup
onPlayNext: () => void
onAddToQueue: () => void
backgroundColor: string
}
onPlay: (song: BrowseSong) => void
+58 -12
View File
@@ -41,6 +41,7 @@ export function SongSwipeRow({
group,
onPress,
onPlayNext,
onAddToQueue,
}: {
children: ReactNode
style?: StyleProp<ViewStyle>
@@ -48,6 +49,7 @@ export function SongSwipeRow({
group: SwipeRowGroup
onPress?: () => void
onPlayNext: () => void
onAddToQueue: () => void
}) {
const x = useSharedValue(0)
const startX = useSharedValue(0)
@@ -78,10 +80,10 @@ export function SongSwipeRow({
const activate = useCallback(
(side: number) => {
close()
if (side > 0) onPlayNext()
if (side > 0) onAddToQueue()
// Download is intentionally a placeholder.
},
[close, onPlayNext]
[close, onAddToQueue]
)
const tapRow = useCallback(() => {
if (open) close()
@@ -105,7 +107,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 * 2 : ACTION_WIDTH,
width.value * 0.55
)
if (commit !== committed.value) {
committed.value = commit
commitProgress.value = withSpring(commit ? 1 : 0, SPRING)
@@ -124,7 +130,7 @@ export function SongSwipeRow({
Math.abs(x.value) > 10 && projected * side > ACTION_WIDTH / 2
? side
: 0
x.value = withSpring(target * ACTION_WIDTH, {
x.value = withSpring(target * ACTION_WIDTH * (target > 0 ? 2 : 1), {
...SPRING,
velocity: event.velocityX,
})
@@ -190,6 +196,18 @@ export function SongSwipeRow({
open={open === 1}
onPress={() => activate(1)}
/>
<SwipeAction
side={1}
secondary
x={x}
height={height}
progress={commitProgress}
open={open === 1}
onPress={() => {
close()
onPlayNext()
}}
/>
<SwipeAction
side={-1}
x={x}
@@ -204,11 +222,16 @@ export function SongSwipeRow({
accessibilityRole="button"
onAccessibilityTap={tapRow}
accessibilityActions={[
{ name: "addToQueue", label: "Add to Queue" },
{ name: "playNext", label: "Play Next" },
{ name: "download", label: "Download" },
]}
onAccessibilityAction={(event) => {
if (event.nativeEvent.actionName === "playNext") activate(1)
if (event.nativeEvent.actionName === "addToQueue") activate(1)
if (event.nativeEvent.actionName === "playNext") {
close()
onPlayNext()
}
}}
style={[styles.row, { backgroundColor }, rowStyle]}
>
@@ -225,6 +248,7 @@ export function SongSwipeRow({
function SwipeAction({
side,
secondary = false,
x,
height,
progress,
@@ -232,17 +256,32 @@ function SwipeAction({
onPress,
}: {
side: 1 | -1
secondary?: boolean
x: SharedValue<number>
height: SharedValue<number>
progress: SharedValue<number>
open: boolean
onPress: () => void
}) {
const actionStyle = useAnimatedStyle(() => ({
width: Math.max(0, x.value * side),
}))
const pillStyle = useAnimatedStyle(() => {
const actionStyle = useAnimatedStyle(() => {
const revealed = Math.max(0, x.value * side)
const primaryWidth = (revealed * (1 + progress.value)) / 2
return {
width:
side < 0
? revealed
: secondary
? revealed - primaryWidth
: primaryWidth,
...(secondary ? { left: primaryWidth } : {}),
}
})
const pillStyle = useAnimatedStyle(() => {
const total = Math.max(0, x.value * side)
const revealed =
side < 0
? total
: (total * (secondary ? 1 - progress.value : 1 + progress.value)) / 2
const resting = Math.max(
0,
Math.min(
@@ -292,14 +331,19 @@ function SwipeAction({
>
<Pressable
accessibilityRole="button"
accessibilityLabel={side > 0 ? "Play Next" : "Download"}
accessibilityLabel={
side > 0 ? (secondary ? "Play Next" : "Add to Queue") : "Download"
}
onPress={onPress}
style={styles.actionButton}
>
<Animated.View
style={[
styles.pill,
{ backgroundColor: side > 0 ? "#6b5bff" : "#008dff" },
{
backgroundColor:
side > 0 ? (secondary ? "#6b5bff" : "#f29943") : "#008dff",
},
pillStyle,
]}
>
@@ -307,7 +351,9 @@ function SwipeAction({
<SymbolView
name={
side > 0
? "text.line.first.and.arrowtriangle.forward"
? secondary
? "text.line.first.and.arrowtriangle.forward"
: "text.line.last.and.arrowtriangle.forward"
: "arrow.down"
}
size={22}