From 6d554cd30c909a90adf0ea9b4846a23153d4c1fb Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Sun, 15 Nov 2026 17:29:33 -0500 Subject: [PATCH] feat(mobile): add flat song swipe actions on Android --- .../app/(app)/(tabs)/home/album/[id].tsx | 2 +- .../app/(app)/(tabs)/home/playlist/[id].tsx | 10 +- apps/mobile/components/player.tsx | 5 +- apps/mobile/components/song-swipe-row.tsx | 141 ++++++++++++++---- 4 files changed, 121 insertions(+), 37 deletions(-) diff --git a/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx b/apps/mobile/app/(app)/(tabs)/home/album/[id].tsx index cbba238..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 ( onAction(song, "play-next"), onAddToQueue: () => onAction(song, "play-last"), + onRemove: + Platform.OS === "android" && removable + ? () => { + void onRemove(song.id) + } + : undefined, } : undefined } @@ -448,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 4690ab9..3c77866 100644 --- a/apps/mobile/components/player.tsx +++ b/apps/mobile/components/player.tsx @@ -46,6 +46,7 @@ export const SongRow = memo(function SongRow({ group: SwipeRowGroup onPlayNext: () => void onAddToQueue: () => void + onRemove?: () => void backgroundColor: string } /** Album/playlist layout: the divider starts at the title, not the artwork. */ @@ -108,11 +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 7ac903b..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,6 +28,8 @@ 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 } @@ -43,6 +47,7 @@ export function SongSwipeRow({ onPress, onPlayNext, onAddToQueue, + onRemove, }: { children: ReactNode style?: StyleProp @@ -51,7 +56,9 @@ export function SongSwipeRow({ 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) @@ -110,7 +117,9 @@ export function SongSwipeRow({ const commit = Math.abs(x.value) > Math.max( - x.value > 0 ? LEADING_ACTION_WIDTH * 2 : ACTION_WIDTH, + x.value > 0 + ? LEADING_ACTION_WIDTH * 2 + : ACTION_WIDTH * (hasRemove ? 2 : 1), width.value * 0.55 ) if (commit !== committed.value) { @@ -132,7 +141,10 @@ export function SongSwipeRow({ ? side : 0 x.value = withSpring( - target * (target > 0 ? LEADING_ACTION_WIDTH * 2 : ACTION_WIDTH), + target * + (target > 0 + ? LEADING_ACTION_WIDTH * 2 + : ACTION_WIDTH * (hasRemove ? 2 : 1)), { ...SPRING, velocity: event.velocityX, @@ -155,6 +167,7 @@ export function SongSwipeRow({ return Gesture.Exclusive(pan, tap) }, [ activate, + hasRemove, begin, close, commitProgress, @@ -168,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( @@ -212,8 +227,25 @@ export function SongSwipeRow({ onPlayNext() }} /> + {hasRemove && ( + { + close() + onRemove?.() + }} + /> + )} { + if (event.nativeEvent.actionName === "remove" && hasRemove) { + close() + onRemove?.() + } if (event.nativeEvent.actionName === "addToQueue") activate(1) if (event.nativeEvent.actionName === "playNext") { close() @@ -253,6 +292,8 @@ export function SongSwipeRow({ function SwipeAction({ side, secondary = false, + paired = side > 0, + remove = false, x, height, progress, @@ -261,6 +302,8 @@ function SwipeAction({ }: { side: 1 | -1 secondary?: boolean + paired?: boolean + remove?: boolean x: SharedValue height: SharedValue progress: SharedValue @@ -271,21 +314,26 @@ function SwipeAction({ 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 } : {}), + 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 = - side < 0 - ? total - : (total * (secondary ? 1 - progress.value : 1 + progress.value)) / 2 + 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( @@ -340,7 +388,13 @@ function SwipeAction({ 0 ? (secondary ? "Play Next" : "Add to Queue") : "Download" + remove + ? "Remove from Playlist" + : side > 0 + ? secondary + ? "Play Next" + : "Add to Queue" + : "Download" } onPress={onPress} style={styles.actionButton} @@ -349,24 +403,45 @@ function SwipeAction({ style={[ styles.pill, { - backgroundColor: - side > 0 ? (secondary ? "#6b5bff" : "#f29943") : "#008dff", + backgroundColor: remove + ? "#d32f2f" + : side > 0 + ? secondary + ? "#6b5bff" + : "#f29943" + : "#008dff", }, pillStyle, ]} > - 0 - ? secondary - ? "text.line.first.and.arrowtriangle.forward" - : "text.line.last.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" + /> + )}