{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "swipe-row",
  "type": "registry:item",
  "title": "Swipe Row",
  "description": "A list row with actions behind it; swipe far enough and the edge action takes over the row and runs.",
  "categories": [
    "interaction"
  ],
  "dependencies": [
    "react-native-gesture-handler",
    "react-native-reanimated",
    "react-native-worklets"
  ],
  "registryDependencies": [
    "https://kinetik-ui.dev/r/kinetik-tokens.json",
    "https://kinetik-ui.dev/r/kinetik-motion.json",
    "https://kinetik-ui.dev/r/kinetik-haptics.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/swipe-row.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/swipe-row.tsx",
      "content": "import { useState, type ReactNode } from 'react';\nimport {\n  Pressable,\n  StyleSheet,\n  Text,\n  type AccessibilityActionEvent,\n  type StyleProp,\n  type ViewStyle,\n} from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n  useAnimatedStyle,\n  useSharedValue,\n  withSpring,\n  withTiming,\n  type SharedValue,\n} from 'react-native-reanimated';\nimport { scheduleOnRN } from 'react-native-worklets';\n\nimport { useHaptic } from '../../lib/kinetik/hooks/use-haptic';\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { durations, easings, spring } from '../../lib/kinetik/motion/motion';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport type { Palette } from '../../lib/kinetik/tokens/tokens';\n\nexport type SwipeActionTone = 'danger' | 'azure' | 'neutral' | 'success' | 'warning';\n\nexport type SwipeAction = {\n  key: string;\n  label: string;\n  /** Drawn above the label; receives the colour to use. */\n  icon?: (color: string) => ReactNode;\n  /** Defaults to `neutral`. */\n  tone?: SwipeActionTone;\n  /** Slide the row away and fold it shut before `onPress` runs, e.g. for Delete or Archive. */\n  dismiss?: boolean;\n  onPress: () => void;\n};\n\nexport type SwipeRowProps = {\n  /** The row's content. */\n  children: ReactNode;\n  /** Names the row for screen readers; its actions are offered as custom actions. */\n  accessibilityLabel: string;\n  /** Revealed by swiping right. */\n  leading?: SwipeAction;\n  /** Revealed by swiping left, edge-most first. The first one runs on a full swipe. */\n  trailing?: readonly SwipeAction[];\n  /** Width of each action button. Defaults to 76. */\n  actionWidth?: number;\n  /** A long swipe runs the edge-most action. Defaults to true. */\n  fullSwipe?: boolean;\n  /** A tick when a full swipe arms. Defaults to true. */\n  haptics?: boolean;\n  testID?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\n/** Share of the row's width past which a swipe runs the edge action. */\nconst FULL = 0.62;\n\nfunction toneColors(tone: SwipeActionTone, c: Palette) {\n  switch (tone) {\n    case 'danger':\n      return { bg: c.danger, fg: c.background };\n    case 'azure':\n      return { bg: c.azure, fg: c.onAzure };\n    case 'success':\n      return { bg: c.success, fg: c.background };\n    case 'warning':\n      return { bg: c.warning, fg: c.background };\n    default:\n      return { bg: c.surfaceRaised, fg: c.text };\n  }\n}\n\n/**\n * A list row with actions behind it. Swipe to reveal them; they share the\n * space you open up. Swipe far enough and the edge action takes over the\n * whole row with a tick, and letting go runs it, sliding the row away if\n * it removes it.\n */\nexport function SwipeRow({\n  children,\n  accessibilityLabel,\n  leading,\n  trailing = [],\n  actionWidth = 76,\n  fullSwipe = true,\n  haptics = true,\n  testID,\n  style,\n}: SwipeRowProps) {\n  const { colors } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const [width, setWidth] = useState(0);\n  const [height, setHeight] = useState(0);\n  const [open, setOpen] = useState<'leading' | 'trailing' | null>(null);\n\n  const x = useSharedValue(0);\n  const start = useSharedValue(0);\n  const armed = useSharedValue(0);\n  const armedAnim = useSharedValue(0);\n  const fold = useSharedValue(1);\n\n  const trailingW = trailing.length * actionWidth;\n  const leadingW = leading ? actionWidth : 0;\n\n  const close = () => {\n    x.set(withSpring(0, spring('smooth', reduced)));\n    setOpen(null);\n  };\n\n  const run = (action: SwipeAction, side: 'leading' | 'trailing') => {\n    setOpen(null);\n    if (!action.dismiss) {\n      x.set(withSpring(0, spring('smooth', reduced)));\n      armedAnim.set(withSpring(0, spring('smooth', reduced)));\n      action.onPress();\n      return;\n    }\n    if (reduced) {\n      action.onPress();\n      return;\n    }\n    // Slide off, then fold the row shut, then hand over to the list.\n    const away = side === 'trailing' ? -width : width;\n    x.set(withTiming(away, { duration: durations.base, easing: easings.exit }));\n    fold.set(\n      withTiming(0, { duration: durations.base, easing: easings.standard }, (finished) => {\n        if (finished) scheduleOnRN(action.onPress);\n      }),\n    );\n  };\n\n  const arm = (on: boolean) => {\n    if (on) haptic('tick');\n  };\n\n  const settle = (vx: number) => {\n    'worklet';\n    const pos = x.get();\n    const w = width;\n    if (fullSwipe && w > 0 && armed.get() === 1) {\n      // Marked as run, so the edge action keeps the whole row while it plays out.\n      armed.set(2);\n      const side = pos < 0 ? 'trailing' : 'leading';\n      const action = side === 'trailing' ? trailing[0] : leading;\n      if (action) {\n        scheduleOnRN(run, action, side);\n        return;\n      }\n    }\n    // Open if dragged past half the actions or flung that way; otherwise close.\n    if (pos < 0 && trailingW > 0 && (pos < -trailingW / 2 || vx < -600) && vx < 400) {\n      x.set(withSpring(-trailingW, spring('smooth', reduced)));\n      scheduleOnRN(setOpen, 'trailing');\n    } else if (pos > 0 && leadingW > 0 && (pos > leadingW / 2 || vx > 600) && vx > -400) {\n      x.set(withSpring(leadingW, spring('smooth', reduced)));\n      scheduleOnRN(setOpen, 'leading');\n    } else {\n      x.set(withSpring(0, spring('smooth', reduced)));\n      scheduleOnRN(setOpen, null);\n    }\n  };\n\n  const pan = Gesture.Pan()\n    .withTestId('swipe-row')\n    .activeOffsetX([-12, 12])\n    .failOffsetY([-10, 10])\n    .onBegin(() => start.set(x.get()))\n    .onUpdate((e) => {\n      let next = start.get() + e.translationX;\n      // No actions on a side: resist instead of opening.\n      if (next > 0 && !leading) next = Math.min(24, next * 0.15);\n      if (next < 0 && trailing.length === 0) next = Math.max(-24, next * 0.15);\n      x.set(next);\n      if (!fullSwipe || width === 0) return;\n      const on = Math.abs(next) > width * FULL ? 1 : 0;\n      if (on !== armed.get()) {\n        armed.set(on);\n        // The edge action grows over the others on a spring rather than jumping.\n        armedAnim.set(withSpring(on, spring('snappy', reduced)));\n        scheduleOnRN(arm, on === 1);\n      }\n    })\n    .onEnd((e) => settle(e.velocityX))\n    .onFinalize(() => {\n      if (armed.get() !== 2) armedAnim.set(withSpring(0, spring('snappy', reduced)));\n      armed.set(0);\n    });\n\n  const front = useAnimatedStyle(() => ({ transform: [{ translateX: x.get() }] }));\n  const shell = useAnimatedStyle(() => ({\n    height: height > 0 && fold.get() < 1 ? height * fold.get() : undefined,\n    opacity: fold.get() < 1 ? fold.get() : 1,\n  }));\n  const trailingBox = useAnimatedStyle(() => ({ width: Math.max(0, -x.get()) }));\n  const leadingBox = useAnimatedStyle(() => ({ width: Math.max(0, x.get()) }));\n\n  const onAccessibilityAction = (e: AccessibilityActionEvent) => {\n    const name = e.nativeEvent.actionName;\n    if (leading && name === leading.key) return run(leading, 'leading');\n    const action = trailing.find((a) => a.key === name);\n    if (action) run(action, 'trailing');\n  };\n\n  return (\n    <Animated.View\n      testID={testID}\n      style={[styles.shell, shell, style]}\n      onLayout={(e) => {\n        setWidth(e.nativeEvent.layout.width);\n        if (fold.get() === 1) setHeight(e.nativeEvent.layout.height);\n      }}\n    >\n      {trailing.length > 0 ? (\n        <Animated.View style={[styles.actions, styles.right, trailingBox]}>\n          {[...trailing].reverse().map((action, i, list) => (\n            <ActionButton\n              key={action.key}\n              action={action}\n              edge={i === list.length - 1}\n              count={list.length}\n              x={x}\n              armed={armedAnim}\n              colors={colors}\n              visible={open === 'trailing'}\n              onPress={() => run(action, 'trailing')}\n            />\n          ))}\n        </Animated.View>\n      ) : null}\n      {leading ? (\n        <Animated.View style={[styles.actions, styles.left, leadingBox]}>\n          <ActionButton\n            action={leading}\n            edge\n            count={1}\n            x={x}\n            armed={armedAnim}\n            colors={colors}\n            visible={open === 'leading'}\n            onPress={() => run(leading, 'leading')}\n          />\n        </Animated.View>\n      ) : null}\n\n      <GestureDetector gesture={pan}>\n        <Animated.View\n          collapsable={false}\n          accessible\n          accessibilityLabel={accessibilityLabel}\n          accessibilityActions={[\n            ...(leading ? [{ name: leading.key, label: leading.label }] : []),\n            ...trailing.map((a) => ({ name: a.key, label: a.label })),\n          ]}\n          onAccessibilityAction={onAccessibilityAction}\n          style={[{ backgroundColor: colors.surface }, front]}\n        >\n          {children}\n          {open ? (\n            <Pressable\n              onPress={close}\n              accessibilityRole=\"button\"\n              accessibilityLabel=\"Close actions\"\n              style={StyleSheet.absoluteFill}\n            />\n          ) : null}\n        </Animated.View>\n      </GestureDetector>\n    </Animated.View>\n  );\n}\n\ntype ActionButtonProps = {\n  action: SwipeAction;\n  /** The edge-most action, which takes over on a full swipe. */\n  edge: boolean;\n  count: number;\n  x: SharedValue<number>;\n  armed: SharedValue<number>;\n  colors: Palette;\n  visible: boolean;\n  onPress: () => void;\n};\n\nfunction ActionButton({\n  action,\n  edge,\n  count,\n  x,\n  armed,\n  colors,\n  visible,\n  onPress,\n}: ActionButtonProps) {\n  const { font } = useKinetikTheme();\n  const { bg, fg } = toneColors(action.tone ?? 'neutral', colors);\n\n  const style = useAnimatedStyle(() => {\n    const revealed = Math.abs(x.get());\n    const share = revealed / count;\n    const a = armed.get();\n    return { width: edge ? share + (revealed - share) * a : share * (1 - a) };\n  });\n  const content = useAnimatedStyle(() => ({\n    opacity: Math.min(1, Math.max(0, (Math.abs(x.get()) / count - 28) / 30)),\n  }));\n\n  return (\n    <Animated.View style={[styles.action, { backgroundColor: bg }, style]}>\n      <Pressable\n        onPress={onPress}\n        disabled={!visible}\n        accessibilityElementsHidden\n        importantForAccessibility=\"no-hide-descendants\"\n        style={styles.actionPress}\n      >\n        <Animated.View style={[styles.actionContent, content]}>\n          {action.icon ? action.icon(fg) : null}\n          <Text\n            numberOfLines={1}\n            style={{ color: fg, fontSize: font.size.xs, fontWeight: font.weight.semibold }}\n          >\n            {action.label}\n          </Text>\n        </Animated.View>\n      </Pressable>\n    </Animated.View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  shell: { overflow: 'hidden' },\n  actions: { position: 'absolute', top: 0, bottom: 0, flexDirection: 'row' },\n  right: { right: 0, justifyContent: 'flex-end' },\n  left: { left: 0 },\n  action: { overflow: 'hidden' },\n  actionPress: { flex: 1, justifyContent: 'center' },\n  actionContent: { alignItems: 'center', gap: 4, minWidth: 64, alignSelf: 'center' },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "interaction",
    "web": "live",
    "perf": {
      "budget": "The row and its actions move on the UI thread from three shared values; a dismissed row folds its height once. Nothing runs at rest.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-13",
          "build": "release",
          "frameMs": 18,
          "p90Ms": 25,
          "baselineMs": 20,
          "jankyPercent": 2.06,
          "atRest": "idle",
          "memoryMb": 154
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The row still follows the finger, but opens, closes and dismisses without springs or the slide-away.",
      "screenReader": "The row is one element named by accessibilityLabel, with every action offered as a custom action.",
      "touchTarget": "Action buttons are 76 pt wide and as tall as the row."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { SwipeRow } from '@/components/kinetik/swipe-row';\n\n<SwipeRow\n  accessibilityLabel={`${mail.from}, ${mail.subject}`}\n  leading={{ key: 'pin', label: 'Pin', tone: 'azure', onPress: pin }}\n  trailing={[\n    { key: 'delete', label: 'Delete', tone: 'danger', dismiss: true, onPress: remove },\n    { key: 'flag', label: 'Flag', onPress: flag },\n  ]}\n>\n  <MailRow mail={mail} />\n</SwipeRow>;\n```\n\n`trailing` lists actions from the edge inwards. The first one is the edge action: it runs on a full swipe. Actions with `dismiss` slide the row away and fold it shut before `onPress` runs, so remove the item from your list in `onPress`.\n\n## When to use\n\n- Quick actions on rows people process one by one: mail, notifications, tasks, saved items.\n- Lists where the same actions are also available elsewhere, for example in the item's detail screen.\n\n## When not to use\n\n- The only way to reach an action. Swipes are hard to discover.\n- Rows inside a horizontal scroller or carousel, where the swipe would fight the scroll.\n\n## Notes\n\n- A short swipe opens the actions; a fling opens them too. Tap the row to close them.\n- Past 62% of the row's width the edge action grows over the others with a tick; let go there to run it. Turn this off with `fullSwipe={false}`.\n- Swiping towards a side with no actions resists and springs back.\n- Every action is a custom accessibility action on the row, so screen reader users never need to swipe.\n"
  },
  "docs": "Prefer `npx kinetik-ui add swipe-row`: it installs dependencies with expo install, so versions match your Expo SDK."
}
