From 3765789b10fff7ee8ca917d32068cfd8e7b83d58 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Sun, 15 Nov 2026 10:37:06 -0500 Subject: [PATCH 1/4] fix(mobile): prevent back swipes from playing songs --- .../app/(app)/(tabs)/home/album/[id].tsx | 5 +- apps/mobile/components/player.tsx | 7 +-- apps/mobile/components/song-pressable.tsx | 52 +++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 apps/mobile/components/song-pressable.tsx diff --git a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx index d4ba20d..0798612 100644 --- a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx @@ -1,3 +1,4 @@ +import { SongPressable } from "@/components/song-pressable" import { CollectionHero, useCollectionHeroLayout, @@ -494,7 +495,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({ onAction={(action) => void onAction(track, album, action)} > - void onPlay(track.id as Id<"songs">, songIds)} > @@ -535,7 +536,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({ {formatDuration(track.durationSeconds)} - + ) diff --git a/apps/mobile/components/player.tsx b/apps/mobile/components/player.tsx index 887aa61..07c731a 100644 --- a/apps/mobile/components/player.tsx +++ b/apps/mobile/components/player.tsx @@ -1,3 +1,4 @@ +import { SongPressable } from "@/components/song-pressable" import { PaletteText } from "@/components/palette-text" import { MusicEntityView } from "@/components/music-entity-view" import { collectionInset } from "@/components/collection-list" @@ -14,7 +15,7 @@ import { useThemeColors, } from "@/lib/theme" import { memo, useCallback } from "react" -import { Platform, Pressable, StyleSheet, View } from "react-native" +import { Platform, StyleSheet, View } from "react-native" import { MediaContextMenu, @@ -80,7 +81,7 @@ export const SongRow = memo(function SongRow({ ) const row = ( - + ) if (!contextMenu) { diff --git a/apps/mobile/components/song-pressable.tsx b/apps/mobile/components/song-pressable.tsx new file mode 100644 index 0000000..b509d29 --- /dev/null +++ b/apps/mobile/components/song-pressable.tsx @@ -0,0 +1,52 @@ +import { useRef } from "react" +import { + Pressable, + type GestureResponderEvent, + type PressableProps, +} from "react-native" + +const TAP_DISTANCE = 10 + +type SongPressableProps = Omit & { + onPress?: () => void +} + +/** Cancel playback after dragging, even when navigation moves the row with the finger. */ +export function SongPressable({ onPress, ...props }: SongPressableProps) { + const touch = useRef<{ x: number; y: number; cancelled: boolean } | null>( + null + ) + + function checkMovement(event: GestureResponderEvent) { + const start = touch.current + if (!start) return + const { pageX, pageY } = event.nativeEvent + if (Math.hypot(pageX - start.x, pageY - start.y) > TAP_DISTANCE) { + start.cancelled = true + } + } + + return ( + { + const { pageX, pageY } = event.nativeEvent + touch.current = { x: pageX, y: pageY, cancelled: false } + props.onTouchStart?.(event) + }} + onTouchMove={(event) => { + checkMovement(event) + props.onTouchMove?.(event) + }} + onTouchCancel={(event) => { + if (touch.current) touch.current.cancelled = true + props.onTouchCancel?.(event) + }} + onPress={(event) => { + checkMovement(event) + if (!touch.current?.cancelled) onPress?.() + }} + /> + ) +} -- 2.54.1 From eae52548f11610ffb45233a0dd9825e14c87ab96 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Sun, 15 Nov 2026 10:46:03 -0500 Subject: [PATCH 2/4] fix(mobile): preserve song context menus during press handling --- apps/mobile/components/song-pressable.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/mobile/components/song-pressable.tsx b/apps/mobile/components/song-pressable.tsx index b509d29..ed05305 100644 --- a/apps/mobile/components/song-pressable.tsx +++ b/apps/mobile/components/song-pressable.tsx @@ -7,6 +7,8 @@ import { const TAP_DISTANCE = 10 +function consumeLongPress() {} + type SongPressableProps = Omit & { onPress?: () => void } @@ -30,18 +32,16 @@ export function SongPressable({ onPress, ...props }: SongPressableProps) { { + // Let UIKit present the context menu without playing on release. + onLongPress={props.onLongPress ?? consumeLongPress} + onPressIn={(event) => { const { pageX, pageY } = event.nativeEvent touch.current = { x: pageX, y: pageY, cancelled: false } - props.onTouchStart?.(event) + props.onPressIn?.(event) }} - onTouchMove={(event) => { + onPressMove={(event) => { checkMovement(event) - props.onTouchMove?.(event) - }} - onTouchCancel={(event) => { - if (touch.current) touch.current.cancelled = true - props.onTouchCancel?.(event) + props.onPressMove?.(event) }} onPress={(event) => { checkMovement(event) -- 2.54.1 From 6aaf5a13b1fe1ab2ee5b08042bc91b5cace5ae17 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Sun, 15 Nov 2026 10:48:43 -0500 Subject: [PATCH 3/4] Revert "fix(mobile): preserve song context menus during press handling" This reverts commit eae52548f11610ffb45233a0dd9825e14c87ab96. --- apps/mobile/components/song-pressable.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/mobile/components/song-pressable.tsx b/apps/mobile/components/song-pressable.tsx index ed05305..b509d29 100644 --- a/apps/mobile/components/song-pressable.tsx +++ b/apps/mobile/components/song-pressable.tsx @@ -7,8 +7,6 @@ import { const TAP_DISTANCE = 10 -function consumeLongPress() {} - type SongPressableProps = Omit & { onPress?: () => void } @@ -32,16 +30,18 @@ export function SongPressable({ onPress, ...props }: SongPressableProps) { { + onTouchStart={(event) => { const { pageX, pageY } = event.nativeEvent touch.current = { x: pageX, y: pageY, cancelled: false } - props.onPressIn?.(event) + props.onTouchStart?.(event) }} - onPressMove={(event) => { + onTouchMove={(event) => { checkMovement(event) - props.onPressMove?.(event) + props.onTouchMove?.(event) + }} + onTouchCancel={(event) => { + if (touch.current) touch.current.cancelled = true + props.onTouchCancel?.(event) }} onPress={(event) => { checkMovement(event) -- 2.54.1 From cf473bc786a311f685e2a66e8ffc5a708ed947b0 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Sun, 15 Nov 2026 14:21:24 -0500 Subject: [PATCH 4/4] feat(mobile): add song swipe actions to albums and playlists --- .../app/(app)/(tabs)/home/album/[id].tsx | 20 +- .../app/(app)/(tabs)/home/playlist/[id].tsx | 25 +- apps/mobile/components/player.tsx | 55 ++- apps/mobile/components/song-pressable.tsx | 52 --- apps/mobile/components/song-swipe-row.tsx | 332 ++++++++++++++++++ 5 files changed, 401 insertions(+), 83 deletions(-) delete mode 100644 apps/mobile/components/song-pressable.tsx create mode 100644 apps/mobile/components/song-swipe-row.tsx diff --git a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx index 0798612..343d139 100644 --- a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx @@ -1,4 +1,8 @@ -import { SongPressable } from "@/components/song-pressable" +import { SongSwipeRow } from "@/components/song-swipe-row" +import { + useSwipeRowGroup, + type SwipeRowGroup, +} from "@/components/ios-swipe-to-remove-row" import { CollectionHero, useCollectionHeroLayout, @@ -69,6 +73,7 @@ export default function AlbumScreen() { handleAlbumTrackAction, isAlbumFavorite: isAlbumFav, } = useMediaMenuActions() + const swipeGroup = useSwipeRowGroup() const isFocused = useIsFocused() const coverUri = config && typeof id === "string" ? albumCoverUrl(config.serverUrl, id) : "" @@ -113,6 +118,7 @@ export default function AlbumScreen() { } return album ? ( [] @@ -478,6 +488,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({ action: MediaAction ) => Promise }) { + const Row = Platform.OS === "ios" ? SongSwipeRow : Pressable return ( void onAction(track, album, action)} > - void onAction(track, album, "play-next")} style={styles.trackRow} onPress={() => void onPlay(track.id as Id<"songs">, songIds)} > @@ -536,7 +550,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({ {formatDuration(track.durationSeconds)} - + ) diff --git a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx index 8cbe59c..f11a0d1 100644 --- a/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx +++ b/apps/mobile/app/(app)/(tabs)/home/playlist/[id].tsx @@ -39,7 +39,6 @@ import ReanimatedSwipeable from "react-native-gesture-handler/ReanimatedSwipeabl import { CollectionDivider } from "@/components/collection-list" import { CoverImage } from "@/components/cover-image" import { - SwipeToRemoveRow, useSwipeRowGroup, type SwipeRowGroup, } from "@/components/ios-swipe-to-remove-row" @@ -434,28 +433,24 @@ const PlaylistSongRow = memo(function PlaylistSongRow({ playlistLabel={PLAYLIST_LABEL} palette={palette} inset + swipe={ + Platform.OS === "ios" + ? { + group: swipeGroup, + backgroundColor: palette.background, + onPlayNext: () => onAction(song, "play-next"), + } + : undefined + } onPlay={onPlay} onAction={onAction} /> ) - if (!removable) { + if (Platform.OS === "ios" || !removable) { return row } - if (Platform.OS === "ios") { - return ( - - {row} - - ) - } - return ( void @@ -40,6 +42,11 @@ export const SongRow = memo(function SongRow({ } trailing?: React.ReactNode palette?: Pick + swipe?: { + group: SwipeRowGroup + onPlayNext: () => void + backgroundColor: string + } /** Album/playlist layout: the divider starts at the title, not the artwork. */ inset?: boolean }) { @@ -80,16 +87,8 @@ export const SongRow = memo(function SongRow({ ) - const row = ( - + const rowContent = ( + <> + ) + const rowStyle = inset + ? styles.insetRow + : [styles.row, { borderBottomColor: divider }] + const row = + swipe && Platform.OS === "ios" ? ( + + {rowContent} + + ) : ( + + {rowContent} + + ) if (!contextMenu) { return ( @@ -133,6 +155,7 @@ export const SongListRow = memo(function SongListRow({ playlistLabel, palette, inset, + swipe, onPlay, onAction, }: { @@ -141,6 +164,11 @@ export const SongListRow = memo(function SongListRow({ playlistLabel?: string palette?: Pick inset?: boolean + swipe?: { + group: SwipeRowGroup + onPlayNext: () => void + backgroundColor: string + } onPlay: (song: BrowseSong) => void onAction: (song: BrowseSong, action: MediaAction) => void }) { @@ -151,6 +179,7 @@ export const SongListRow = memo(function SongListRow({ song={song} palette={palette} inset={inset} + swipe={swipe} onPress={handlePress} contextMenu={{ stationArtistId: song.artist.id, diff --git a/apps/mobile/components/song-pressable.tsx b/apps/mobile/components/song-pressable.tsx deleted file mode 100644 index b509d29..0000000 --- a/apps/mobile/components/song-pressable.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { useRef } from "react" -import { - Pressable, - type GestureResponderEvent, - type PressableProps, -} from "react-native" - -const TAP_DISTANCE = 10 - -type SongPressableProps = Omit & { - onPress?: () => void -} - -/** Cancel playback after dragging, even when navigation moves the row with the finger. */ -export function SongPressable({ onPress, ...props }: SongPressableProps) { - const touch = useRef<{ x: number; y: number; cancelled: boolean } | null>( - null - ) - - function checkMovement(event: GestureResponderEvent) { - const start = touch.current - if (!start) return - const { pageX, pageY } = event.nativeEvent - if (Math.hypot(pageX - start.x, pageY - start.y) > TAP_DISTANCE) { - start.cancelled = true - } - } - - return ( - { - const { pageX, pageY } = event.nativeEvent - touch.current = { x: pageX, y: pageY, cancelled: false } - props.onTouchStart?.(event) - }} - onTouchMove={(event) => { - checkMovement(event) - props.onTouchMove?.(event) - }} - onTouchCancel={(event) => { - if (touch.current) touch.current.cancelled = true - props.onTouchCancel?.(event) - }} - onPress={(event) => { - checkMovement(event) - if (!touch.current?.cancelled) onPress?.() - }} - /> - ) -} diff --git a/apps/mobile/components/song-swipe-row.tsx b/apps/mobile/components/song-swipe-row.tsx new file mode 100644 index 0000000..3e2f044 --- /dev/null +++ b/apps/mobile/components/song-swipe-row.tsx @@ -0,0 +1,332 @@ +import * as Haptics from "expo-haptics" +import { SymbolView } from "expo-symbols" +import { + useCallback, + useEffect, + useMemo, + useState, + type ReactNode, +} from "react" +import { + Pressable, + StyleSheet, + type StyleProp, + type ViewStyle, +} from "react-native" +import { Gesture, GestureDetector } from "react-native-gesture-handler" +import Animated, { + type SharedValue, + cancelAnimation, + Extrapolation, + interpolate, + useAnimatedStyle, + useSharedValue, + withSpring, +} from "react-native-reanimated" +import { scheduleOnRN } from "react-native-worklets" +import type { SwipeRowGroup } from "@/components/ios-swipe-to-remove-row" + +const ACTION_WIDTH = 82 +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. */ +export function SongSwipeRow({ + children, + style, + backgroundColor, + group, + onPress, + onPlayNext, +}: { + children: ReactNode + style?: StyleProp + backgroundColor: string + group: SwipeRowGroup + onPress?: () => void + onPlayNext: () => void +}) { + const x = useSharedValue(0) + const startX = useSharedValue(0) + const width = useSharedValue(0) + const height = useSharedValue(0) + const committed = useSharedValue(false) + const commitProgress = useSharedValue(0) + const [open, setOpen] = useState<-1 | 0 | 1>(0) + + const close = useCallback(() => { + x.value = withSpring(0, SPRING) + committed.value = false + commitProgress.value = withSpring(0, SPRING) + setOpen(0) + group.clear(close) + }, [commitProgress, committed, group, x]) + + useEffect(() => () => group.clear(close), [close, group]) + + const begin = useCallback(() => group.setOpen(close), [close, group]) + const settle = useCallback( + (side: -1 | 0 | 1) => { + setOpen(side) + if (!side) group.clear(close) + }, + [close, group] + ) + const activate = useCallback( + (side: number) => { + close() + if (side > 0) onPlayNext() + // Download is intentionally a placeholder. + }, + [close, onPlayNext] + ) + const tapRow = useCallback(() => { + if (open) close() + else onPress?.() + }, [close, onPress, open]) + + const gesture = useMemo(() => { + const pan = Gesture.Pan() + // Leave the screen's leading edge available for native back navigation. + .hitSlop({ left: -24 }) + .activeOffsetX([-10, 10]) + .failOffsetY([-10, 10]) + .onStart(() => { + cancelAnimation(x) + startX.value = x.value + scheduleOnRN(begin) + }) + .onUpdate((event) => { + x.value = Math.max( + -width.value, + Math.min(width.value, startX.value + event.translationX) + ) + const commit = + Math.abs(x.value) > Math.max(ACTION_WIDTH, width.value * 0.55) + if (commit !== committed.value) { + committed.value = commit + commitProgress.value = withSpring(commit ? 1 : 0, SPRING) + scheduleOnRN(impact) + } + }) + .onEnd((event) => { + const side = x.value > 0 ? 1 : -1 + if (committed.value) { + x.value = withSpring(0, SPRING) + scheduleOnRN(activate, side) + return + } + const projected = x.value + event.velocityX * 0.12 + const target = + Math.abs(x.value) > 10 && projected * side > ACTION_WIDTH / 2 + ? side + : 0 + x.value = withSpring(target * ACTION_WIDTH, { + ...SPRING, + velocity: event.velocityX, + }) + scheduleOnRN(settle, target) + }) + .onFinalize((_event, success) => { + if (!success) { + x.value = withSpring(0, SPRING) + scheduleOnRN(close) + } + }) + const tap = Gesture.Tap() + .maxDistance(10) + .maxDuration(500) + .onEnd((_event, success) => { + if (success) scheduleOnRN(tapRow) + }) + return Gesture.Exclusive(pan, tap) + }, [ + activate, + begin, + close, + commitProgress, + committed, + settle, + startX, + tapRow, + width, + x, + ]) + + const rowStyle = useAnimatedStyle(() => ({ + transform: [{ translateX: x.value }], + borderRadius: interpolate( + Math.abs(x.value), + [0, 40], + [0, height.value / 2], + Extrapolation.CLAMP + ), + })) + const fillStyle = useAnimatedStyle(() => ({ + opacity: interpolate( + Math.abs(x.value), + [0, 40], + [0, 1], + Extrapolation.CLAMP + ), + })) + + return ( + { + width.value = event.nativeEvent.layout.width + height.value = event.nativeEvent.layout.height + }} + > + activate(1)} + /> + activate(-1)} + /> + + { + if (event.nativeEvent.actionName === "playNext") activate(1) + }} + style={[styles.row, { backgroundColor }, rowStyle]} + > + + {children} + + + + ) +} + +function SwipeAction({ + side, + x, + height, + progress, + open, + onPress, +}: { + side: 1 | -1 + x: SharedValue + height: SharedValue + progress: SharedValue + open: boolean + onPress: () => void +}) { + const actionStyle = useAnimatedStyle(() => ({ + width: Math.max(0, x.value * side), + })) + const pillStyle = useAnimatedStyle(() => { + const revealed = Math.max(0, x.value * side) + const resting = Math.max( + 0, + Math.min( + revealed - 20, + interpolate(revealed, [24, ACTION_WIDTH, 220], [0, 62, 200]) + ) + ) + const pillWidth = + resting + (Math.max(0, revealed - 12) - resting) * progress.value + const restingHeight = interpolate( + pillWidth, + [0, 24, 62, 140, 200], + [0, 0.3, 0.77, 0.82, 0.86].map((ratio) => ratio * height.value), + Extrapolation.CLAMP + ) + const pillHeight = + restingHeight + + (Math.max(0, height.value - 12) - restingHeight) * progress.value + return { + width: pillWidth, + height: pillHeight, + borderRadius: pillHeight / 2, + } + }) + const iconStyle = useAnimatedStyle(() => ({ + transform: [ + { + scale: interpolate( + x.value * side, + [24, 64], + [0, 1], + Extrapolation.CLAMP + ), + }, + ], + })) + return ( + 0 ? styles.leading : styles.trailing, + actionStyle, + ]} + > + 0 ? "Play Next" : "Download"} + onPress={onPress} + style={styles.actionButton} + > + 0 ? "#6b5bff" : "#008dff" }, + pillStyle, + ]} + > + + 0 + ? "text.line.first.and.arrowtriangle.forward" + : "arrow.down" + } + size={22} + tintColor="white" + /> + + + + + ) +} + +const styles = StyleSheet.create({ + container: { overflow: "hidden" }, + row: { overflow: "hidden" }, + fill: { backgroundColor: "rgba(128,128,128,0.16)" }, + action: { position: "absolute", top: 0, bottom: 0 }, + leading: { left: 0 }, + trailing: { right: 0 }, + actionButton: { flex: 1, alignItems: "center", justifyContent: "center" }, + pill: { alignItems: "center", justifyContent: "center", overflow: "hidden" }, +}) -- 2.54.1