From 3765789b10fff7ee8ca917d32068cfd8e7b83d58 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Sun, 15 Nov 2026 10:37:06 -0500 Subject: [PATCH] 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?.() + }} + /> + ) +}