diff --git a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx index a32bf8c..512fccd 100644 --- a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx @@ -488,7 +488,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({ action: MediaAction ) => Promise }) { - const Row = Platform.OS === "ios" ? SongSwipeRow : Pressable + const Row = Platform.OS !== "web" ? SongSwipeRow : Pressable const { config } = useServerConfig() return ( 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)} > diff --git a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx index f11a0d1..34037bd 100644 --- a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx @@ -434,11 +434,18 @@ const PlaylistSongRow = memo(function PlaylistSongRow({ palette={palette} inset swipe={ - Platform.OS === "ios" + Platform.OS !== "web" ? { group: swipeGroup, backgroundColor: palette.background, onPlayNext: () => onAction(song, "play-next"), + onAddToQueue: () => onAction(song, "play-last"), + onRemove: + Platform.OS === "android" && removable + ? () => { + void onRemove(song.id) + } + : undefined, } : undefined } @@ -447,7 +454,7 @@ const PlaylistSongRow = memo(function PlaylistSongRow({ /> ) - if (Platform.OS === "ios" || !removable) { + if (Platform.OS !== "web" || !removable) { return row } diff --git a/apps/mobile/components/player.tsx b/apps/mobile/components/player.tsx index 0aaf866..3c77866 100644 --- a/apps/mobile/components/player.tsx +++ b/apps/mobile/components/player.tsx @@ -45,6 +45,8 @@ export const SongRow = memo(function SongRow({ swipe?: { group: SwipeRowGroup onPlayNext: () => void + onAddToQueue: () => void + onRemove?: () => void backgroundColor: string } /** Album/playlist layout: the divider starts at the title, not the artwork. */ @@ -107,10 +109,12 @@ export const SongRow = memo(function SongRow({ ? styles.insetRow : [styles.row, { borderBottomColor: divider }] const row = - swipe && Platform.OS === "ios" ? ( + swipe && Platform.OS !== "web" ? ( void + onAddToQueue: () => void + onRemove?: () => void backgroundColor: string } onPlay: (song: BrowseSong) => void diff --git a/apps/mobile/components/song-swipe-row.tsx b/apps/mobile/components/song-swipe-row.tsx index 3e2f044..e19973e 100644 --- a/apps/mobile/components/song-swipe-row.tsx +++ b/apps/mobile/components/song-swipe-row.tsx @@ -1,3 +1,4 @@ +import { Ionicons } from "@expo/vector-icons" import * as Haptics from "expo-haptics" import { SymbolView } from "expo-symbols" import { @@ -8,6 +9,7 @@ import { type ReactNode, } from "react" import { + Platform, Pressable, StyleSheet, type StyleProp, @@ -26,7 +28,10 @@ import Animated, { import { scheduleOnRN } from "react-native-worklets" 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 const SPRING = { duration: 450, dampingRatio: 1 } function impact() { @@ -41,6 +46,8 @@ export function SongSwipeRow({ group, onPress, onPlayNext, + onAddToQueue, + onRemove, }: { children: ReactNode style?: StyleProp @@ -48,7 +55,10 @@ export function SongSwipeRow({ group: SwipeRowGroup onPress?: () => void onPlayNext: () => void + onAddToQueue: () => void + onRemove?: () => void }) { + const hasRemove = IS_ANDROID && !!onRemove const x = useSharedValue(0) const startX = useSharedValue(0) const width = useSharedValue(0) @@ -78,10 +88,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 +115,13 @@ 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 + ? LEADING_ACTION_WIDTH * 2 + : ACTION_WIDTH * (hasRemove ? 2 : 1), + width.value * 0.55 + ) if (commit !== committed.value) { committed.value = commit commitProgress.value = withSpring(commit ? 1 : 0, SPRING) @@ -124,10 +140,16 @@ 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 + ? LEADING_ACTION_WIDTH * 2 + : ACTION_WIDTH * (hasRemove ? 2 : 1)), + { + ...SPRING, + velocity: event.velocityX, + } + ) scheduleOnRN(settle, target) }) .onFinalize((_event, success) => { @@ -145,6 +167,7 @@ export function SongSwipeRow({ return Gesture.Exclusive(pan, tap) }, [ activate, + hasRemove, begin, close, commitProgress, @@ -158,12 +181,14 @@ export function SongSwipeRow({ const rowStyle = useAnimatedStyle(() => ({ transform: [{ translateX: x.value }], - borderRadius: interpolate( - Math.abs(x.value), - [0, 40], - [0, height.value / 2], - Extrapolation.CLAMP - ), + borderRadius: IS_ANDROID + ? 0 + : interpolate( + Math.abs(x.value), + [0, 40], + [0, height.value / 2], + Extrapolation.CLAMP + ), })) const fillStyle = useAnimatedStyle(() => ({ opacity: interpolate( @@ -190,8 +215,37 @@ export function SongSwipeRow({ open={open === 1} onPress={() => activate(1)} /> + { + close() + onPlayNext() + }} + /> + {hasRemove && ( + { + close() + onRemove?.() + }} + /> + )} { - if (event.nativeEvent.actionName === "playNext") activate(1) + if (event.nativeEvent.actionName === "remove" && hasRemove) { + close() + onRemove?.() + } + if (event.nativeEvent.actionName === "addToQueue") activate(1) + if (event.nativeEvent.actionName === "playNext") { + close() + onPlayNext() + } }} style={[styles.row, { backgroundColor }, rowStyle]} > @@ -225,6 +291,9 @@ export function SongSwipeRow({ function SwipeAction({ side, + secondary = false, + paired = side > 0, + remove = false, x, height, progress, @@ -232,22 +301,48 @@ function SwipeAction({ onPress, }: { side: 1 | -1 + secondary?: boolean + paired?: boolean + remove?: boolean x: SharedValue height: SharedValue progress: SharedValue 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: !paired + ? revealed + : secondary + ? revealed - primaryWidth + : primaryWidth, + ...(secondary + ? side > 0 + ? { left: primaryWidth } + : { right: primaryWidth } + : {}), + } + }) + const pillStyle = useAnimatedStyle(() => { + const total = Math.max(0, x.value * side) + const revealed = !paired + ? total + : (total * (secondary ? 1 - progress.value : 1 + progress.value)) / 2 + if (IS_ANDROID) { + return { width: revealed, height: height.value, borderRadius: 0 } + } const resting = Math.max( 0, Math.min( - revealed - 20, - interpolate(revealed, [24, ACTION_WIDTH, 220], [0, 62, 200]) + revealed - (side > 0 ? 10 : 20), + interpolate( + revealed, + [24, side > 0 ? LEADING_ACTION_WIDTH : ACTION_WIDTH, 220], + [0, 62, 200] + ) ) ) const pillWidth = @@ -292,27 +387,61 @@ function SwipeAction({ > 0 ? "Play Next" : "Download"} + accessibilityLabel={ + remove + ? "Remove from Playlist" + : side > 0 + ? secondary + ? "Play Next" + : "Add to Queue" + : "Download" + } onPress={onPress} style={styles.actionButton} > 0 ? "#6b5bff" : "#008dff" }, + { + backgroundColor: remove + ? "#d32f2f" + : side > 0 + ? secondary + ? "#6b5bff" + : "#f29943" + : "#008dff", + }, pillStyle, ]} > - 0 - ? "text.line.first.and.arrowtriangle.forward" - : "arrow.down" - } - size={22} - tintColor="white" - /> + {IS_ANDROID ? ( + + ) : ( + 0 + ? secondary + ? "text.line.first.and.arrowtriangle.forward" + : "text.line.last.and.arrowtriangle.forward" + : "arrow.down" + } + size={22} + tintColor="white" + /> + )}