feat(mobile): add flat song swipe actions on Android

This commit is contained in:
joshuafhiggins committed 2026-11-15 17:29:33 -05:00 Verified
1 parent d941e745c9
commit 6d554cd30c
4 files changed
+121 -37

No files matched your search

@@ -488,7 +488,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
action: MediaAction
) => Promise<void>
}) {
const Row = Platform.OS === "ios" ? SongSwipeRow : Pressable
const Row = Platform.OS !== "web" ? SongSwipeRow : Pressable
const { config } = useServerConfig()
return (
<MediaContextMenu
@@ -434,12 +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
}
@@ -448,7 +454,7 @@ const PlaylistSongRow = memo(function PlaylistSongRow({
/>
)
if (Platform.OS === "ios" || !removable) {
if (Platform.OS !== "web" || !removable) {
return row
}
+4 -1
View File
@@ -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" ? (
<SongSwipeRow
group={swipe.group}
onPlayNext={swipe.onPlayNext}
onAddToQueue={swipe.onAddToQueue}
onRemove={swipe.onRemove}
backgroundColor={swipe.backgroundColor}
onPress={onPress}
style={rowStyle}
@@ -170,6 +172,7 @@ export const SongListRow = memo(function SongListRow({
group: SwipeRowGroup
onPlayNext: () => void
onAddToQueue: () => void
onRemove?: () => void
backgroundColor: string
}
onPlay: (song: BrowseSong) => void
+108 -33
View File
@@ -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<ViewStyle>
@@ -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 && (
<SwipeAction
side={-1}
secondary
paired
remove
x={x}
height={height}
progress={commitProgress}
open={open === -1}
onPress={() => {
close()
onRemove?.()
}}
/>
)}
<SwipeAction
side={-1}
paired={hasRemove}
x={x}
height={height}
progress={commitProgress}
@@ -229,8 +261,15 @@ export function SongSwipeRow({
{ name: "addToQueue", label: "Add to Queue" },
{ name: "playNext", label: "Play Next" },
{ name: "download", label: "Download" },
...(hasRemove
? [{ name: "remove", label: "Remove from Playlist" }]
: []),
]}
onAccessibilityAction={(event) => {
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<number>
height: SharedValue<number>
progress: SharedValue<number>
@@ -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({
<Pressable
accessibilityRole="button"
accessibilityLabel={
side > 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,
]}
>
<Animated.View style={iconStyle}>
<SymbolView
name={
side > 0
? secondary
? "text.line.first.and.arrowtriangle.forward"
: "text.line.last.and.arrowtriangle.forward"
: "arrow.down"
}
size={22}
tintColor="white"
/>
{IS_ANDROID ? (
<Ionicons
name={
remove
? "trash-outline"
: side < 0
? "arrow-down"
: secondary
? "play-forward"
: "list"
}
size={22}
color="white"
/>
) : (
<SymbolView
name={
side > 0
? secondary
? "text.line.first.and.arrowtriangle.forward"
: "text.line.last.and.arrowtriangle.forward"
: "arrow.down"
}
size={22}
tintColor="white"
/>
)}
</Animated.View>
</Animated.View>
</Pressable>