# Reorder List

A list whose rows are dragged by a handle to change their order, with haptics and move up and down actions.

Reorder List is an open-source interaction from suiss/ui for React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.

Source: https://ui.suiss.app/docs/interactions/reorder-list

**React Native, SwiftUI, Jetpack Compose**

![Preview](https://ui.suiss.app/previews/interactions-reorder-list--default.light.webp)

```tsx
import * as React from "react"
import { View } from "react-native"
import { ReorderList, ReorderListHandle, ReorderListItem } from "@/components/interactions/reorder-list"
import { ItemGroup } from "@/components/ui/item"
import { Text } from "@/components/ui/text"

const tasks: Record<string, { title: string; detail?: string }> = {
  inbox: { title: "Inbox", detail: "12 messages" },
  today: { title: "Today" },
  upcoming: { title: "Upcoming", detail: "Next 7 days" },
  someday: { title: "Someday" },
  archive: {
    title: "Archive",
    detail: "Everything you finished, kept for later reference",
  },
}

const initialOrder = Object.keys(tasks)

function renderRows(value: string[]) {
  return value.map((key) => {
    const task = tasks[key]
    return (
      <ReorderListItem key={key} value={key} className="ps-4">
        <View className="min-w-0 flex-1 py-3">
          <Text numberOfLines={1}>{task.title}</Text>
          {task.detail ? (
            <Text className="text-sm text-muted-foreground">{task.detail}</Text>
          ) : null}
        </View>
        <ReorderListHandle accessibilityLabel={`Reorder ${task.title}`} />
      </ReorderListItem>
    )
  })
}

function ReorderDemo({ inset = false }: { inset?: boolean }) {
  const [value, setValue] = React.useState(initialOrder)
  return (
    <View className="gap-3">
      {inset ? (
        <ItemGroup variant="inset">
          <ReorderList value={value} onValueChange={setValue}>
            {renderRows(value)}
          </ReorderList>
        </ItemGroup>
      ) : (
        <ReorderList value={value} onValueChange={setValue}>
          {renderRows(value)}
        </ReorderList>
      )}
      <Text role="status" className="text-sm text-muted-foreground">
        {value.map((key) => tasks[key].title).join(", ")}
      </Text>
    </View>
  )
}

export function ReorderListExample() {
  return (
    <ReorderDemo />
  )
}
```

```swift
import EsuissUI
import SwiftUI

struct ReorderListTask {
  let title: String
  var detail: String?
}

let reorderListTasks: [String: ReorderListTask] = [
  "inbox": ReorderListTask(title: "Inbox", detail: "12 messages"),
  "today": ReorderListTask(title: "Today"),
  "upcoming": ReorderListTask(title: "Upcoming", detail: "Next 7 days"),
  "someday": ReorderListTask(title: "Someday"),
  "archive": ReorderListTask(title: "Archive", detail: "Everything you finished, kept for later reference"),
]

let reorderListOrder = ["inbox", "today", "upcoming", "someday", "archive"]

struct ReorderListDemo: View {
  var inset = false

  @State private var value = reorderListOrder

  var body: some View {
    VStack(alignment: .leading, spacing: 12) {
      list
      Text(verbatim: value.compactMap { reorderListTasks[$0]?.title }.joined(separator: ", "))
        .textStyle(.sm)
        .foregroundStyle(EsuissColor.mutedForeground)
        .accessibilityAddTraits(.updatesFrequently)
    }
  }

  @ViewBuilder
  var list: some View {
    if inset {
      ItemGroup(.inset) {
        rows
      }
    } else {
      rows
    }
  }

  var rows: some View {
    ReorderList($value) { key in
      if let task = reorderListTasks[key] {
        VStack(alignment: .leading, spacing: 0) {
          Text(verbatim: task.title)
            .textStyle(.base)
            .foregroundStyle(EsuissColor.foreground)
            .lineLimit(1)
          if let detail = task.detail {
            Text(verbatim: detail)
              .textStyle(.sm)
              .foregroundStyle(EsuissColor.mutedForeground)
          }
        }
        .padding(.vertical, 12)
      }
    }
  }
}
```

```kotlin
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.LiveRegionMode
import androidx.compose.ui.semantics.liveRegion
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.ItemGroup
import com.esuiss.ui.components.ItemGroupVariant
import com.esuiss.ui.components.Text
import com.esuiss.ui.interactions.ReorderList
import com.esuiss.ui.interactions.ReorderListHandle
import com.esuiss.ui.interactions.ReorderListItem
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography

@Composable
fun ReorderListExample() {
    ReorderListDemo(inset = false)
}

class ReorderListTask(val title: String, val detail: String? = null)

val reorderListTasks = linkedMapOf(
    "inbox" to ReorderListTask("Inbox", "12 messages"),
    "today" to ReorderListTask("Today"),
    "upcoming" to ReorderListTask("Upcoming", "Next 7 days"),
    "someday" to ReorderListTask("Someday"),
    "archive" to ReorderListTask("Archive", "Everything you finished, kept for later reference"),
)

val reorderListInitial = reorderListTasks.keys.toList()

@Composable
fun ReorderListDemo(inset: Boolean) {
    val colors = EsuissTheme.colors
    var value by rememberSaveable { mutableStateOf(reorderListInitial) }
    Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
        val list = @Composable {
            ReorderList(
                value = value,
                onValueChange = { value = it },
            ) { key ->
                val task = reorderListTasks.getValue(key)
                ReorderListItem {
                    Column(Modifier.weight(1f).padding(vertical = 12.dp)) {
                        Text(task.title, maxLines = 1, overflow = TextOverflow.Ellipsis)
                        if (task.detail != null) {
                            Text(task.detail, style = Typography.sm.copy(color = colors.mutedForeground))
                        }
                    }
                    ReorderListHandle(contentDescription = "Reorder ${task.title}")
                }
            }
        }
        if (inset) ItemGroup(variant = ItemGroupVariant.Inset) { list() } else list()
        Text(
            value.joinToString(", ") { reorderListTasks.getValue(it).title },
            modifier = Modifier.semantics { liveRegion = LiveRegionMode.Polite },
            style = Typography.sm.copy(color = colors.mutedForeground),
        )
    }
}
```

`ReorderList` renders its `ReorderListItem`s in the order given by `value`. Dragging a row's `ReorderListHandle` lifts the row: a raised surface with a shadow fades in behind it and, outside an inset group, the row grows slightly. It follows the finger while the other rows spring out of the way.

On release the row springs into its new slot and `onValueChange` receives the new order. Rows can have different heights. Use it for ordering favorites, playlists or priorities.

## Installation

**React Native**

```bash title="Terminal"
npx shadcn@latest add @esuiss-rn/reorder-list
```

See [Installation](https://ui.suiss.app/docs/installation) for the `components.json` setup. Or use the suiss/ui CLI:

```bash title="Terminal"
npx @esuiss/ui@latest add reorder-list
```

**SwiftUI**

```bash title="Terminal"
npx @esuiss/ui@latest add reorder-list --platform swift
```

**Jetpack Compose**

```bash title="Terminal"
npx @esuiss/ui@latest add reorder-list --platform kotlin
```

The CLI also adds what it builds on: [Icon](https://ui.suiss.app/docs/components/icon), [Item](https://ui.suiss.app/docs/components/item). On React Native it also adds the animated view `components/ui/animated-view.tsx`.

### Manual

**React Native**

**Uniwind**

1. Install the dependencies:

```bash title="Terminal"
npx expo install cn phosphor-react-native react-native-gesture-handler react-native-reanimated react-native-svg react-native-worklets
```

2. Add the pieces it builds on: [Icon](https://ui.suiss.app/docs/components/icon), [Item](https://ui.suiss.app/docs/components/item), and the primitives `components/primitives/haptics.tsx`, and the animated view `components/ui/animated-view.tsx` from the next step.

3. Copy the animated view into `components/ui/animated-view.tsx`:

- `uniwind/components/ui/animated-view.tsx`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/uniwind/components/ui/animated-view.tsx)

4. Copy the source into `components/interactions/reorder-list.tsx`:

```tsx title="uniwind/components/interactions/reorder-list.tsx"
import { cn } from "cn"
import { DotsSixVerticalIcon } from "phosphor-react-native"
import * as React from "react"
import { View, type ViewProps } from "react-native"
import { Gesture, GestureDetector } from "react-native-gesture-handler"
import {
  ReduceMotion,
  runOnJS,
  type SharedValue,
  useAnimatedStyle,
  useReducedMotion,
  useSharedValue,
  withSpring,
} from "react-native-reanimated"
import { useHaptics } from "@/components/primitives/haptics"
import { AnimatedView } from "@/components/ui/animated-view"
import { Icon } from "@/components/ui/icon"
import { ItemGroupContext } from "@/components/ui/item"

type ReorderListContextProps = {
  order: SharedValue<string[]>
  heights: SharedValue<Record<string, number>>
  active: SharedValue<string | null>
  start: SharedValue<number>
  target: SharedValue<number>
  dragY: SharedValue<number>
  lift: SharedValue<number>
  activeKey: string | null
  setActiveKey: (key: string | null) => void
  commit: (next: string[], settled?: boolean) => void
  move: (key: string, delta: number) => void
  setHeight: (key: string, height: number) => void
  value: string[]
  moveUpLabel: string
  moveDownLabel: string
}

const ReorderListContext = React.createContext<ReorderListContextProps | null>(
  null
)

const ReorderListItemContext = React.createContext<string | null>(null)

function useReorderListItemKey(): string {
  const key = React.useContext(ReorderListItemContext)
  if (key === null) {
    throw new Error(
      "ReorderListHandle must be used within a <ReorderListItem />"
    )
  }
  return key
}

function useReorderList() {
  const context = React.useContext(ReorderListContext)
  if (!context) {
    throw new Error("useReorderList must be used within a <ReorderList />")
  }
  return context
}

const LIFT = {
  stiffness: 1500,
  damping: 78,
  mass: 1,
  reduceMotion: ReduceMotion.System,
}

const SETTLE = {
  stiffness: 400,
  damping: 40,
  mass: 1,
  reduceMotion: ReduceMotion.System,
}

function moveItem(list: string[], from: number, to: number) {
  "worklet"
  const next = list.slice()
  const [item] = next.splice(from, 1)
  next.splice(to, 0, item)
  return next
}

function targetIndex(
  order: string[],
  heights: Record<string, number>,
  from: number,
  dy: number
) {
  "worklet"
  let target = from
  let travelled = 0
  if (dy > 0) {
    for (let index = from + 1; index < order.length; index += 1) {
      const height = heights[order[index]] ?? 0
      if (dy <= travelled + height / 2) break
      travelled += height
      target = index
    }
  } else {
    for (let index = from - 1; index >= 0; index -= 1) {
      const height = heights[order[index]] ?? 0
      if (-dy <= travelled + height / 2) break
      travelled += height
      target = index
    }
  }
  return target
}

function dropOffset(
  order: string[],
  heights: Record<string, number>,
  from: number,
  to: number
) {
  "worklet"
  let offset = 0
  if (to > from) {
    for (let index = from + 1; index <= to; index += 1) {
      offset += heights[order[index]] ?? 0
    }
  } else {
    for (let index = to; index < from; index += 1) {
      offset -= heights[order[index]] ?? 0
    }
  }
  return offset
}

function ReorderList({
  value,
  onValueChange,
  moveUpLabel = "Move up",
  moveDownLabel = "Move down",
  className,
  children,
  ...props
}: ViewProps & {
  value: string[]
  onValueChange: (value: string[]) => void
  moveUpLabel?: string
  moveDownLabel?: string
}) {
  const order = useSharedValue(value)
  const heights = useSharedValue<Record<string, number>>({})
  const active = useSharedValue<string | null>(null)
  const start = useSharedValue(-1)
  const target = useSharedValue(-1)
  const dragY = useSharedValue(0)
  const lift = useSharedValue(0)
  const [activeKey, setActiveKey] = React.useState<string | null>(null)
  const pendingRef = React.useRef(false)

  const reset = React.useCallback(() => {
    pendingRef.current = false
    active.value = null
    dragY.value = 0
    setActiveKey(null)
  }, [active, dragY])

  React.useLayoutEffect(() => {
    order.value = value
    if (pendingRef.current) reset()
  }, [value, order, reset])

  const commit = React.useCallback(
    (next: string[], settled = true) => {
      pendingRef.current = settled
      onValueChange(next)
      if (!settled) return
      requestAnimationFrame(() => {
        if (pendingRef.current) reset()
      })
    },
    [onValueChange, reset]
  )

  const move = React.useCallback(
    (key: string, delta: number) => {
      const from = value.indexOf(key)
      const to = Math.min(Math.max(from + delta, 0), value.length - 1)
      if (from < 0 || from === to) return
      onValueChange(moveItem(value, from, to))
    },
    [value, onValueChange]
  )

  const setHeight = React.useCallback(
    (key: string, height: number) => {
      heights.modify((current) => {
        "worklet"
        current[key] = height
        return current
      })
    },
    [heights]
  )

  const items = new Map<string, React.ReactNode>()
  for (const child of React.Children.toArray(children)) {
    if (React.isValidElement<{ value?: string }>(child) && child.props.value) {
      items.set(child.props.value, child)
    }
  }

  const context = React.useMemo<ReorderListContextProps>(
    () => ({
      order,
      heights,
      active,
      start,
      target,
      dragY,
      lift,
      activeKey,
      setActiveKey,
      commit,
      move,
      setHeight,
      value,
      moveUpLabel,
      moveDownLabel,
    }),
    [
      order,
      heights,
      active,
      start,
      target,
      dragY,
      lift,
      activeKey,
      commit,
      move,
      setHeight,
      value,
      moveUpLabel,
      moveDownLabel,
    ]
  )

  return (
    <ReorderListContext.Provider value={context}>
      <View className={className} {...props}>
        {value.map((key) => items.get(key) ?? null)}
      </View>
    </ReorderListContext.Provider>
  )
}

function ReorderListItem({
  value,
  className,
  style,
  onLayout,
  children,
  ...props
}: ViewProps & {
  value: string
}) {
  const {
    order,
    heights,
    active,
    start,
    target,
    dragY,
    lift,
    activeKey,
    setHeight,
  } = useReorderList()
  const { inset } = React.useContext(ItemGroupContext)
  const reduced = useReducedMotion()
  const scaled = !inset && !reduced

  const animatedStyle = useAnimatedStyle(() => {
    const current = active.value
    if (current === null) {
      return { zIndex: 0, transform: [{ translateY: 0 }, { scale: 1 }] }
    }
    if (current === value) {
      return {
        zIndex: 10,
        transform: [
          { translateY: dragY.value },
          { scale: scaled ? 1 + 0.02 * lift.value : 1 },
        ],
      }
    }
    const index = order.value.indexOf(value)
    const from = start.value
    const to = target.value
    const height = heights.value[current] ?? 0
    let shift = 0
    if (from < index && index <= to) shift = -height
    else if (to <= index && index < from) shift = height
    return {
      zIndex: 0,
      transform: [{ translateY: withSpring(shift, SETTLE) }, { scale: 1 }],
    }
  })

  const raisedStyle = useAnimatedStyle(() => ({
    opacity: active.value === value ? lift.value : 0,
  }))

  return (
    <ReorderListItemContext.Provider value={value}>
      <AnimatedView
        className={cn("flex-row items-center gap-3", className)}
        style={[animatedStyle, style]}
        onLayout={(event) => {
          setHeight(value, event.nativeEvent.layout.height)
          onLayout?.(event)
        }}
        {...props}
      >
        {activeKey === value ? (
          <AnimatedView
            pointerEvents="none"
            className={cn(
              "absolute inset-0 bg-card shadow-lg",
              inset && "rounded-2xl"
            )}
            style={raisedStyle}
          />
        ) : null}
        {children}
      </AnimatedView>
    </ReorderListItemContext.Provider>
  )
}

function ReorderListHandle({
  className,
  accessibilityLabel = "Reorder",
  accessibilityActions,
  onAccessibilityAction,
  ...props
}: ViewProps) {
  const {
    order,
    heights,
    active,
    start,
    target,
    dragY,
    lift,
    setActiveKey,
    commit,
    move,
    value,
    moveUpLabel,
    moveDownLabel,
  } = useReorderList()
  const key = useReorderListItemKey()
  const { impact, selection } = useHaptics()

  const gesture = React.useMemo(
    () =>
      Gesture.Pan()
        .minDistance(0)
        .onStart(() => {
          const index = order.value.indexOf(key)
          start.value = index
          target.value = index
          dragY.value = 0
          lift.value = 0
          active.value = key
          lift.value = withSpring(1, LIFT)
          runOnJS(setActiveKey)(key)
          runOnJS(impact)("medium")
        })
        .onUpdate((event) => {
          dragY.value = event.translationY
          const next = targetIndex(
            order.value,
            heights.value,
            start.value,
            event.translationY
          )
          if (next !== target.value) {
            target.value = next
            runOnJS(selection)()
          }
        })
        .onEnd(() => {
          runOnJS(impact)("light")
          const from = start.value
          const to = target.value
          lift.value = withSpring(0, SETTLE)
          if (from === to || from < 0) {
            dragY.value = withSpring(0, SETTLE, (finished) => {
              if (!finished) return
              active.value = null
              runOnJS(setActiveKey)(null)
            })
            return
          }
          const offset = dropOffset(order.value, heights.value, from, to)
          const next = moveItem(order.value, from, to)
          dragY.value = withSpring(offset, SETTLE, (finished) => {
            runOnJS(commit)(next, finished === true)
          })
        }),
    [
      key,
      order,
      heights,
      active,
      start,
      target,
      dragY,
      lift,
      setActiveKey,
      commit,
      impact,
      selection,
    ]
  )

  const index = value.indexOf(key)
  const actions = [
    ...(index > 0 ? [{ name: "moveUp", label: moveUpLabel }] : []),
    ...(index >= 0 && index < value.length - 1
      ? [{ name: "moveDown", label: moveDownLabel }]
      : []),
  ]

  return (
    <GestureDetector gesture={gesture}>
      <View
        {...props}
        accessible
        role="button"
        accessibilityLabel={accessibilityLabel}
        accessibilityActions={[...actions, ...(accessibilityActions ?? [])]}
        onAccessibilityAction={(event) => {
          const name = event.nativeEvent.actionName
          if (name === "moveUp") move(key, -1)
          else if (name === "moveDown") move(key, 1)
          else onAccessibilityAction?.(event)
        }}
        className={cn("size-11 items-center justify-center", className)}
      >
        <Icon
          as={DotsSixVerticalIcon}
          weight="bold"
          className="size-5 text-muted-foreground"
        />
      </View>
    </GestureDetector>
  )
}

export { ReorderList, ReorderListHandle, ReorderListItem }
```

5. Update the import paths to match your project.

**NativeWind**

1. Install the dependencies:

```bash title="Terminal"
npx expo install cn phosphor-react-native react-native-gesture-handler react-native-reanimated react-native-svg react-native-worklets
```

2. Add the pieces it builds on: [Icon](https://ui.suiss.app/docs/components/icon), [Item](https://ui.suiss.app/docs/components/item), and the primitives `components/primitives/haptics.tsx`, and the animated view `components/ui/animated-view.tsx` from the next step.

3. Copy the animated view into `components/ui/animated-view.tsx`:

- `nativewind/components/ui/animated-view.tsx`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/nativewind/components/ui/animated-view.tsx)

4. Copy the source into `components/interactions/reorder-list.tsx`:

```tsx title="nativewind/components/interactions/reorder-list.tsx"
import { cn } from "cn"
import { DotsSixVerticalIcon } from "phosphor-react-native"
import * as React from "react"
import { View, type ViewProps } from "react-native"
import { Gesture, GestureDetector } from "react-native-gesture-handler"
import {
  ReduceMotion,
  runOnJS,
  type SharedValue,
  useAnimatedStyle,
  useReducedMotion,
  useSharedValue,
  withSpring,
} from "react-native-reanimated"
import { useHaptics } from "@/components/primitives/haptics"
import { AnimatedView } from "@/components/ui/animated-view"
import { Icon } from "@/components/ui/icon"
import { ItemGroupContext } from "@/components/ui/item"

type ReorderListContextProps = {
  order: SharedValue<string[]>
  heights: SharedValue<Record<string, number>>
  active: SharedValue<string | null>
  start: SharedValue<number>
  target: SharedValue<number>
  dragY: SharedValue<number>
  lift: SharedValue<number>
  activeKey: string | null
  setActiveKey: (key: string | null) => void
  commit: (next: string[], settled?: boolean) => void
  move: (key: string, delta: number) => void
  setHeight: (key: string, height: number) => void
  value: string[]
  moveUpLabel: string
  moveDownLabel: string
}

const ReorderListContext = React.createContext<ReorderListContextProps | null>(
  null
)

const ReorderListItemContext = React.createContext<string | null>(null)

function useReorderListItemKey(): string {
  const key = React.useContext(ReorderListItemContext)
  if (key === null) {
    throw new Error(
      "ReorderListHandle must be used within a <ReorderListItem />"
    )
  }
  return key
}

function useReorderList() {
  const context = React.useContext(ReorderListContext)
  if (!context) {
    throw new Error("useReorderList must be used within a <ReorderList />")
  }
  return context
}

const LIFT = {
  stiffness: 1500,
  damping: 78,
  mass: 1,
  reduceMotion: ReduceMotion.System,
}

const SETTLE = {
  stiffness: 400,
  damping: 40,
  mass: 1,
  reduceMotion: ReduceMotion.System,
}

function moveItem(list: string[], from: number, to: number) {
  "worklet"
  const next = list.slice()
  const [item] = next.splice(from, 1)
  next.splice(to, 0, item)
  return next
}

function targetIndex(
  order: string[],
  heights: Record<string, number>,
  from: number,
  dy: number
) {
  "worklet"
  let target = from
  let travelled = 0
  if (dy > 0) {
    for (let index = from + 1; index < order.length; index += 1) {
      const height = heights[order[index]] ?? 0
      if (dy <= travelled + height / 2) break
      travelled += height
      target = index
    }
  } else {
    for (let index = from - 1; index >= 0; index -= 1) {
      const height = heights[order[index]] ?? 0
      if (-dy <= travelled + height / 2) break
      travelled += height
      target = index
    }
  }
  return target
}

function dropOffset(
  order: string[],
  heights: Record<string, number>,
  from: number,
  to: number
) {
  "worklet"
  let offset = 0
  if (to > from) {
    for (let index = from + 1; index <= to; index += 1) {
      offset += heights[order[index]] ?? 0
    }
  } else {
    for (let index = to; index < from; index += 1) {
      offset -= heights[order[index]] ?? 0
    }
  }
  return offset
}

function ReorderList({
  value,
  onValueChange,
  moveUpLabel = "Move up",
  moveDownLabel = "Move down",
  className,
  children,
  ...props
}: ViewProps & {
  value: string[]
  onValueChange: (value: string[]) => void
  moveUpLabel?: string
  moveDownLabel?: string
}) {
  const order = useSharedValue(value)
  const heights = useSharedValue<Record<string, number>>({})
  const active = useSharedValue<string | null>(null)
  const start = useSharedValue(-1)
  const target = useSharedValue(-1)
  const dragY = useSharedValue(0)
  const lift = useSharedValue(0)
  const [activeKey, setActiveKey] = React.useState<string | null>(null)
  const pendingRef = React.useRef(false)

  const reset = React.useCallback(() => {
    pendingRef.current = false
    active.value = null
    dragY.value = 0
    setActiveKey(null)
  }, [active, dragY])

  React.useLayoutEffect(() => {
    order.value = value
    if (pendingRef.current) reset()
  }, [value, order, reset])

  const commit = React.useCallback(
    (next: string[], settled = true) => {
      pendingRef.current = settled
      onValueChange(next)
      if (!settled) return
      requestAnimationFrame(() => {
        if (pendingRef.current) reset()
      })
    },
    [onValueChange, reset]
  )

  const move = React.useCallback(
    (key: string, delta: number) => {
      const from = value.indexOf(key)
      const to = Math.min(Math.max(from + delta, 0), value.length - 1)
      if (from < 0 || from === to) return
      onValueChange(moveItem(value, from, to))
    },
    [value, onValueChange]
  )

  const setHeight = React.useCallback(
    (key: string, height: number) => {
      heights.modify((current) => {
        "worklet"
        current[key] = height
        return current
      })
    },
    [heights]
  )

  const items = new Map<string, React.ReactNode>()
  for (const child of React.Children.toArray(children)) {
    if (React.isValidElement<{ value?: string }>(child) && child.props.value) {
      items.set(child.props.value, child)
    }
  }

  const context = React.useMemo<ReorderListContextProps>(
    () => ({
      order,
      heights,
      active,
      start,
      target,
      dragY,
      lift,
      activeKey,
      setActiveKey,
      commit,
      move,
      setHeight,
      value,
      moveUpLabel,
      moveDownLabel,
    }),
    [
      order,
      heights,
      active,
      start,
      target,
      dragY,
      lift,
      activeKey,
      commit,
      move,
      setHeight,
      value,
      moveUpLabel,
      moveDownLabel,
    ]
  )

  return (
    <ReorderListContext.Provider value={context}>
      <View className={className} {...props}>
        {value.map((key) => items.get(key) ?? null)}
      </View>
    </ReorderListContext.Provider>
  )
}

function ReorderListItem({
  value,
  className,
  style,
  onLayout,
  children,
  ...props
}: ViewProps & {
  value: string
}) {
  const {
    order,
    heights,
    active,
    start,
    target,
    dragY,
    lift,
    activeKey,
    setHeight,
  } = useReorderList()
  const { inset } = React.useContext(ItemGroupContext)
  const reduced = useReducedMotion()
  const scaled = !inset && !reduced

  const animatedStyle = useAnimatedStyle(() => {
    const current = active.value
    if (current === null) {
      return { zIndex: 0, transform: [{ translateY: 0 }, { scale: 1 }] }
    }
    if (current === value) {
      return {
        zIndex: 10,
        transform: [
          { translateY: dragY.value },
          { scale: scaled ? 1 + 0.02 * lift.value : 1 },
        ],
      }
    }
    const index = order.value.indexOf(value)
    const from = start.value
    const to = target.value
    const height = heights.value[current] ?? 0
    let shift = 0
    if (from < index && index <= to) shift = -height
    else if (to <= index && index < from) shift = height
    return {
      zIndex: 0,
      transform: [{ translateY: withSpring(shift, SETTLE) }, { scale: 1 }],
    }
  })

  const raisedStyle = useAnimatedStyle(() => ({
    opacity: active.value === value ? lift.value : 0,
  }))

  return (
    <ReorderListItemContext.Provider value={value}>
      <AnimatedView
        className={cn("flex-row items-center gap-3", className)}
        style={[animatedStyle, style]}
        onLayout={(event) => {
          setHeight(value, event.nativeEvent.layout.height)
          onLayout?.(event)
        }}
        {...props}
      >
        {activeKey === value ? (
          <AnimatedView
            pointerEvents="none"
            className={cn(
              "absolute inset-0 bg-card shadow-lg",
              inset && "rounded-2xl"
            )}
            style={raisedStyle}
          />
        ) : null}
        {children}
      </AnimatedView>
    </ReorderListItemContext.Provider>
  )
}

function ReorderListHandle({
  className,
  accessibilityLabel = "Reorder",
  accessibilityActions,
  onAccessibilityAction,
  ...props
}: ViewProps) {
  const {
    order,
    heights,
    active,
    start,
    target,
    dragY,
    lift,
    setActiveKey,
    commit,
    move,
    value,
    moveUpLabel,
    moveDownLabel,
  } = useReorderList()
  const key = useReorderListItemKey()
  const { impact, selection } = useHaptics()

  const gesture = React.useMemo(
    () =>
      Gesture.Pan()
        .minDistance(0)
        .onStart(() => {
          const index = order.value.indexOf(key)
          start.value = index
          target.value = index
          dragY.value = 0
          lift.value = 0
          active.value = key
          lift.value = withSpring(1, LIFT)
          runOnJS(setActiveKey)(key)
          runOnJS(impact)("medium")
        })
        .onUpdate((event) => {
          dragY.value = event.translationY
          const next = targetIndex(
            order.value,
            heights.value,
            start.value,
            event.translationY
          )
          if (next !== target.value) {
            target.value = next
            runOnJS(selection)()
          }
        })
        .onEnd(() => {
          runOnJS(impact)("light")
          const from = start.value
          const to = target.value
          lift.value = withSpring(0, SETTLE)
          if (from === to || from < 0) {
            dragY.value = withSpring(0, SETTLE, (finished) => {
              if (!finished) return
              active.value = null
              runOnJS(setActiveKey)(null)
            })
            return
          }
          const offset = dropOffset(order.value, heights.value, from, to)
          const next = moveItem(order.value, from, to)
          dragY.value = withSpring(offset, SETTLE, (finished) => {
            runOnJS(commit)(next, finished === true)
          })
        }),
    [
      key,
      order,
      heights,
      active,
      start,
      target,
      dragY,
      lift,
      setActiveKey,
      commit,
      impact,
      selection,
    ]
  )

  const index = value.indexOf(key)
  const actions = [
    ...(index > 0 ? [{ name: "moveUp", label: moveUpLabel }] : []),
    ...(index >= 0 && index < value.length - 1
      ? [{ name: "moveDown", label: moveDownLabel }]
      : []),
  ]

  return (
    <GestureDetector gesture={gesture}>
      <View
        {...props}
        accessible
        role="button"
        accessibilityLabel={accessibilityLabel}
        accessibilityActions={[...actions, ...(accessibilityActions ?? [])]}
        onAccessibilityAction={(event) => {
          const name = event.nativeEvent.actionName
          if (name === "moveUp") move(key, -1)
          else if (name === "moveDown") move(key, 1)
          else onAccessibilityAction?.(event)
        }}
        className={cn("size-11 items-center justify-center", className)}
      >
        <Icon
          as={DotsSixVerticalIcon}
          weight="bold"
          className="size-5 text-muted-foreground"
        />
      </View>
    </GestureDetector>
  )
}

export { ReorderList, ReorderListHandle, ReorderListItem }
```

5. Update the import paths to match your project.

**StyleSheet**

1. Install the dependencies:

```bash title="Terminal"
npx expo install phosphor-react-native react-native-gesture-handler react-native-reanimated react-native-svg react-native-worklets
```

2. Add the pieces it builds on: [Icon](https://ui.suiss.app/docs/components/icon), [Item](https://ui.suiss.app/docs/components/item), and the primitives `components/primitives/haptics.tsx`, and the animated view `components/ui/animated-view.tsx` from the next step.

3. Copy the animated view into `components/ui/animated-view.tsx`:

- `stylesheet/components/ui/animated-view.tsx`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/stylesheet/components/ui/animated-view.tsx)

4. Copy the source into `components/interactions/reorder-list.tsx`:

```tsx title="stylesheet/components/interactions/reorder-list.tsx"
import { DotsSixVerticalIcon } from "phosphor-react-native"
import * as React from "react"
import { StyleSheet, View, type ViewProps } from "react-native"
import { Gesture, GestureDetector } from "react-native-gesture-handler"
import {
  ReduceMotion,
  runOnJS,
  type SharedValue,
  useAnimatedStyle,
  useReducedMotion,
  useSharedValue,
  withSpring,
} from "react-native-reanimated"
import { useHaptics } from "@/components/primitives/haptics"
import { AnimatedView } from "@/components/ui/animated-view"
import { Icon } from "@/components/ui/icon"
import { ItemGroupContext } from "@/components/ui/item"
import { radius, shadow, useTheme } from "@/components/ui/theme"

type ReorderListContextProps = {
  order: SharedValue<string[]>
  heights: SharedValue<Record<string, number>>
  active: SharedValue<string | null>
  start: SharedValue<number>
  target: SharedValue<number>
  dragY: SharedValue<number>
  lift: SharedValue<number>
  activeKey: string | null
  setActiveKey: (key: string | null) => void
  commit: (next: string[], settled?: boolean) => void
  move: (key: string, delta: number) => void
  setHeight: (key: string, height: number) => void
  value: string[]
  moveUpLabel: string
  moveDownLabel: string
}

const ReorderListContext = React.createContext<ReorderListContextProps | null>(
  null
)

const ReorderListItemContext = React.createContext<string | null>(null)

function useReorderListItemKey(): string {
  const key = React.useContext(ReorderListItemContext)
  if (key === null) {
    throw new Error(
      "ReorderListHandle must be used within a <ReorderListItem />"
    )
  }
  return key
}

function useReorderList() {
  const context = React.useContext(ReorderListContext)
  if (!context) {
    throw new Error("useReorderList must be used within a <ReorderList />")
  }
  return context
}

const LIFT = {
  stiffness: 1500,
  damping: 78,
  mass: 1,
  reduceMotion: ReduceMotion.System,
}

const SETTLE = {
  stiffness: 400,
  damping: 40,
  mass: 1,
  reduceMotion: ReduceMotion.System,
}

const styles = StyleSheet.create({
  item: { flexDirection: "row", alignItems: "center", gap: 12 },
  raised: {
    position: "absolute",
    top: 0,
    right: 0,
    bottom: 0,
    left: 0,
    ...shadow.lg,
  },
  raisedInset: { borderRadius: radius["2xl"] },
  handle: {
    width: 44,
    height: 44,
    alignItems: "center",
    justifyContent: "center",
  },
})

function moveItem(list: string[], from: number, to: number) {
  "worklet"
  const next = list.slice()
  const [item] = next.splice(from, 1)
  next.splice(to, 0, item)
  return next
}

function targetIndex(
  order: string[],
  heights: Record<string, number>,
  from: number,
  dy: number
) {
  "worklet"
  let target = from
  let travelled = 0
  if (dy > 0) {
    for (let index = from + 1; index < order.length; index += 1) {
      const height = heights[order[index]] ?? 0
      if (dy <= travelled + height / 2) break
      travelled += height
      target = index
    }
  } else {
    for (let index = from - 1; index >= 0; index -= 1) {
      const height = heights[order[index]] ?? 0
      if (-dy <= travelled + height / 2) break
      travelled += height
      target = index
    }
  }
  return target
}

function dropOffset(
  order: string[],
  heights: Record<string, number>,
  from: number,
  to: number
) {
  "worklet"
  let offset = 0
  if (to > from) {
    for (let index = from + 1; index <= to; index += 1) {
      offset += heights[order[index]] ?? 0
    }
  } else {
    for (let index = to; index < from; index += 1) {
      offset -= heights[order[index]] ?? 0
    }
  }
  return offset
}

function ReorderList({
  value,
  onValueChange,
  moveUpLabel = "Move up",
  moveDownLabel = "Move down",
  children,
  ...props
}: ViewProps & {
  value: string[]
  onValueChange: (value: string[]) => void
  moveUpLabel?: string
  moveDownLabel?: string
}) {
  const order = useSharedValue(value)
  const heights = useSharedValue<Record<string, number>>({})
  const active = useSharedValue<string | null>(null)
  const start = useSharedValue(-1)
  const target = useSharedValue(-1)
  const dragY = useSharedValue(0)
  const lift = useSharedValue(0)
  const [activeKey, setActiveKey] = React.useState<string | null>(null)
  const pendingRef = React.useRef(false)

  const reset = React.useCallback(() => {
    pendingRef.current = false
    active.value = null
    dragY.value = 0
    setActiveKey(null)
  }, [active, dragY])

  React.useLayoutEffect(() => {
    order.value = value
    if (pendingRef.current) reset()
  }, [value, order, reset])

  const commit = React.useCallback(
    (next: string[], settled = true) => {
      pendingRef.current = settled
      onValueChange(next)
      if (!settled) return
      requestAnimationFrame(() => {
        if (pendingRef.current) reset()
      })
    },
    [onValueChange, reset]
  )

  const move = React.useCallback(
    (key: string, delta: number) => {
      const from = value.indexOf(key)
      const to = Math.min(Math.max(from + delta, 0), value.length - 1)
      if (from < 0 || from === to) return
      onValueChange(moveItem(value, from, to))
    },
    [value, onValueChange]
  )

  const setHeight = React.useCallback(
    (key: string, height: number) => {
      heights.modify((current) => {
        "worklet"
        current[key] = height
        return current
      })
    },
    [heights]
  )

  const items = new Map<string, React.ReactNode>()
  for (const child of React.Children.toArray(children)) {
    if (React.isValidElement<{ value?: string }>(child) && child.props.value) {
      items.set(child.props.value, child)
    }
  }

  const context = React.useMemo<ReorderListContextProps>(
    () => ({
      order,
      heights,
      active,
      start,
      target,
      dragY,
      lift,
      activeKey,
      setActiveKey,
      commit,
      move,
      setHeight,
      value,
      moveUpLabel,
      moveDownLabel,
    }),
    [
      order,
      heights,
      active,
      start,
      target,
      dragY,
      lift,
      activeKey,
      commit,
      move,
      setHeight,
      value,
      moveUpLabel,
      moveDownLabel,
    ]
  )

  return (
    <ReorderListContext.Provider value={context}>
      <View {...props}>{value.map((key) => items.get(key) ?? null)}</View>
    </ReorderListContext.Provider>
  )
}

function ReorderListItem({
  value,
  style,
  onLayout,
  children,
  ...props
}: ViewProps & {
  value: string
}) {
  const { colors } = useTheme()
  const {
    order,
    heights,
    active,
    start,
    target,
    dragY,
    lift,
    activeKey,
    setHeight,
  } = useReorderList()
  const { inset } = React.useContext(ItemGroupContext)
  const reduced = useReducedMotion()
  const scaled = !inset && !reduced

  const animatedStyle = useAnimatedStyle(() => {
    const current = active.value
    if (current === null) {
      return { zIndex: 0, transform: [{ translateY: 0 }, { scale: 1 }] }
    }
    if (current === value) {
      return {
        zIndex: 10,
        transform: [
          { translateY: dragY.value },
          { scale: scaled ? 1 + 0.02 * lift.value : 1 },
        ],
      }
    }
    const index = order.value.indexOf(value)
    const from = start.value
    const to = target.value
    const height = heights.value[current] ?? 0
    let shift = 0
    if (from < index && index <= to) shift = -height
    else if (to <= index && index < from) shift = height
    return {
      zIndex: 0,
      transform: [{ translateY: withSpring(shift, SETTLE) }, { scale: 1 }],
    }
  })

  const raisedStyle = useAnimatedStyle(() => ({
    opacity: active.value === value ? lift.value : 0,
  }))

  return (
    <ReorderListItemContext.Provider value={value}>
      <AnimatedView
        style={[styles.item, animatedStyle, style]}
        onLayout={(event) => {
          setHeight(value, event.nativeEvent.layout.height)
          onLayout?.(event)
        }}
        {...props}
      >
        {activeKey === value ? (
          <AnimatedView
            pointerEvents="none"
            style={[
              styles.raised,
              { backgroundColor: colors.card },
              inset && styles.raisedInset,
              raisedStyle,
            ]}
          />
        ) : null}
        {children}
      </AnimatedView>
    </ReorderListItemContext.Provider>
  )
}

function ReorderListHandle({
  style,
  accessibilityLabel = "Reorder",
  accessibilityActions,
  onAccessibilityAction,
  ...props
}: ViewProps) {
  const {
    order,
    heights,
    active,
    start,
    target,
    dragY,
    lift,
    setActiveKey,
    commit,
    move,
    value,
    moveUpLabel,
    moveDownLabel,
  } = useReorderList()
  const { colors } = useTheme()
  const key = useReorderListItemKey()
  const { impact, selection } = useHaptics()

  const gesture = React.useMemo(
    () =>
      Gesture.Pan()
        .minDistance(0)
        .onStart(() => {
          const index = order.value.indexOf(key)
          start.value = index
          target.value = index
          dragY.value = 0
          lift.value = 0
          active.value = key
          lift.value = withSpring(1, LIFT)
          runOnJS(setActiveKey)(key)
          runOnJS(impact)("medium")
        })
        .onUpdate((event) => {
          dragY.value = event.translationY
          const next = targetIndex(
            order.value,
            heights.value,
            start.value,
            event.translationY
          )
          if (next !== target.value) {
            target.value = next
            runOnJS(selection)()
          }
        })
        .onEnd(() => {
          runOnJS(impact)("light")
          const from = start.value
          const to = target.value
          lift.value = withSpring(0, SETTLE)
          if (from === to || from < 0) {
            dragY.value = withSpring(0, SETTLE, (finished) => {
              if (!finished) return
              active.value = null
              runOnJS(setActiveKey)(null)
            })
            return
          }
          const offset = dropOffset(order.value, heights.value, from, to)
          const next = moveItem(order.value, from, to)
          dragY.value = withSpring(offset, SETTLE, (finished) => {
            runOnJS(commit)(next, finished === true)
          })
        }),
    [
      key,
      order,
      heights,
      active,
      start,
      target,
      dragY,
      lift,
      setActiveKey,
      commit,
      impact,
      selection,
    ]
  )

  const index = value.indexOf(key)
  const actions = [
    ...(index > 0 ? [{ name: "moveUp", label: moveUpLabel }] : []),
    ...(index >= 0 && index < value.length - 1
      ? [{ name: "moveDown", label: moveDownLabel }]
      : []),
  ]

  return (
    <GestureDetector gesture={gesture}>
      <View
        {...props}
        accessible
        role="button"
        accessibilityLabel={accessibilityLabel}
        accessibilityActions={[...actions, ...(accessibilityActions ?? [])]}
        onAccessibilityAction={(event) => {
          const name = event.nativeEvent.actionName
          if (name === "moveUp") move(key, -1)
          else if (name === "moveDown") move(key, 1)
          else onAccessibilityAction?.(event)
        }}
        style={[styles.handle, style]}
      >
        <Icon
          as={DotsSixVerticalIcon}
          weight="bold"
          size={20}
          color={colors.mutedForeground}
        />
      </View>
    </GestureDetector>
  )
}

export { ReorderList, ReorderListHandle, ReorderListItem }
```

5. Update the import paths to match your project.

**SwiftUI**

1. Target iOS 17 or later.

2. Add the Swift package to your app:

```swift title="Package.swift"
.package(url: "https://github.com/phosphor-icons/swift", from: "2.1.0")
```

3. Copy the theme files every view uses:

- `swift/Theme/Theme.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Theme.swift)

- `swift/Theme/Tokens.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Theme/Tokens.swift)

4. Copy the source and every file it uses:

```swift title="swift/Interactions/ReorderList.swift"
import PhosphorSwift
import SwiftUI

enum ReorderMath {
  static func move<Element>(_ items: [Element], from source: Int, to destination: Int) -> [Element] {
    guard items.indices.contains(source), items.indices.contains(destination), source != destination else {
      return items
    }
    var result = items
    let element = result.remove(at: source)
    result.insert(element, at: destination)
    return result
  }

  static func target(from index: Int, translation: CGFloat, heights: [CGFloat]) -> Int {
    guard heights.indices.contains(index) else { return index }
    var target = index
    if translation > 0 {
      var travelled: CGFloat = 0
      while target + 1 < heights.count {
        let next = heights[target + 1]
        guard translation > travelled + next / 2 else { break }
        travelled += next
        target += 1
      }
    } else if translation < 0 {
      var travelled: CGFloat = 0
      while target - 1 >= 0 {
        let previous = heights[target - 1]
        guard -translation > travelled + previous / 2 else { break }
        travelled += previous
        target -= 1
      }
    }
    return target
  }

  static func shift(for index: Int, dragging: Int, target: Int, height: CGFloat) -> CGFloat {
    if dragging < target, index > dragging, index <= target { return -height }
    if dragging > target, index < dragging, index >= target { return height }
    return 0
  }
}

public struct ReorderList<Value: Hashable, Row: View>: View {
  let value: Binding<[Value]>
  let row: (Value) -> Row

  @State private var heights: [Value: CGFloat] = [:]
  @State private var dragging: Value?
  @State private var lifted: Value?
  @State private var translation: CGFloat = 0
  @State private var drops = 0
  @Environment(\.itemGroupInset) private var inset
  @Environment(\.accessibilityReduceMotion) private var reduceMotion

  public init(_ value: Binding<[Value]>, @ViewBuilder row: @escaping (Value) -> Row) {
    self.value = value
    self.row = row
  }

  private var items: [Value] { value.wrappedValue }

  private var sizes: [CGFloat] { items.map { heights[$0] ?? 0 } }

  private var draggingIndex: Int? { dragging.flatMap { items.firstIndex(of: $0) } }

  private var target: Int? {
    draggingIndex.map { ReorderMath.target(from: $0, translation: translation, heights: sizes) }
  }

  private func commit(from source: Int, to destination: Int) {
    let next = ReorderMath.move(items, from: source, to: destination)
    if reduceMotion {
      value.wrappedValue = next
    } else {
      withAnimation(ReorderMotion.settle) { value.wrappedValue = next }
    }
    AccessibilityNotification.Announcement(String(localized: "Moved to position \(destination + 1) of \(items.count)")).post()
  }

  public var body: some View {
    let draggingIndex = draggingIndex
    let target = target
    VStack(spacing: 0) {
      ForEach(Array(items.enumerated()), id: \.element) { index, item in
        let active = draggingIndex == index
        let shift = draggingIndex.flatMap { from in
          target.map { ReorderMath.shift(for: index, dragging: from, target: $0, height: sizes[from]) }
        } ?? 0
        rowView(item, index: index, active: active)
          .offset(y: active ? translation : shift)
          .animation(active || reduceMotion ? nil : ReorderMotion.settle, value: shift)
          .zIndex(active ? 1 : 0)
      }
    }
    .coordinateSpace(.named(ReorderSpace.name))
    .hapticFeedback(.impact(weight: .medium), trigger: dragging) { HapticMoments.lifted($0, $1) }
    .hapticFeedback(.selection, trigger: target) { HapticMoments.moved($0, $1) }
    .hapticFeedback(.impact(weight: .light), trigger: drops)
  }

  private func rowView(_ item: Value, index: Int, active: Bool) -> some View {
    let raised = lifted == item
    let shape = RoundedRectangle(cornerRadius: inset ? Radius.xl2 : 0, style: .continuous)
    return HStack(spacing: 12) {
      row(item)
        .frame(maxWidth: .infinity, alignment: .leading)
      Ph.dotsSixVertical.bold
        .frame(width: 20, height: 20)
        .foregroundStyle(raised ? EsuissColor.mutedForeground : EsuissColor.mutedForeground)
        .frame(width: 44, height: 44)
        .contentShape(Rectangle())
        .gesture(
          DragGesture(minimumDistance: 0, coordinateSpace: .named(ReorderSpace.name))
            .onChanged { gesture in
              if dragging != item {
                dragging = item
                withAnimation(reduceMotion ? nil : ReorderMotion.lift) { lifted = item }
              }
              translation = gesture.translation.height
            }
            .onEnded { gesture in
              drops += 1
              let destination = ReorderMath.target(from: index, translation: gesture.translation.height, heights: sizes)
              if destination != index {
                var transaction = Transaction()
                transaction.disablesAnimations = true
                withTransaction(transaction) {
                  value.wrappedValue = ReorderMath.move(items, from: index, to: destination)
                  translation = gesture.translation.height - travelled(from: index, to: destination)
                }
              }
              withAnimation(reduceMotion ? nil : ReorderMotion.settle) {
                translation = 0
                lifted = nil
              } completion: {
                dragging = nil
              }
            }
        )
        .accessibilityHidden(true)
    }
    .padding(.leading, 16)
    .padding(.trailing, 4)
    .frame(minHeight: 44)
    .background {
      shape
        .fill(EsuissColor.card)
        .shadow(.lg)
        .opacity(raised ? 1 : 0)
    }
    .overlay(alignment: .bottom) {
      if index < items.count - 1 && !active {
        EsuissColor.border.frame(height: 1).padding(.leading, 16)
      }
    }
    .scaleEffect(raised && !reduceMotion && !inset ? 1.02 : 1)
    .onGeometryChange(for: CGFloat.self) { $0.size.height } action: { heights[item] = $0 }
    .accessibilityElement(children: .combine)
    .accessibilityActions {
      if index > 0 {
        Button("Move up") { commit(from: index, to: index - 1) }
      }
      if index < items.count - 1 {
        Button("Move down") { commit(from: index, to: index + 1) }
      }
    }
  }

  private func travelled(from source: Int, to destination: Int) -> CGFloat {
    if destination > source {
      return sizes[(source + 1)...destination].reduce(0, +)
    }
    return -sizes[destination..<source].reduce(0, +)
  }
}

enum ReorderMotion {
  static let lift = Animation.smooth(duration: 0.16)
  static let settle = Animation.smooth(duration: 0.3)
}

enum ReorderSpace {
  static let name = "reorder-list"
}
```

- `swift/Components/Haptics.swift`: see [Haptics](https://ui.suiss.app/docs/components/haptics.md)

- `swift/Components/Item.swift`: see [Item](https://ui.suiss.app/docs/components/item.md)

- `swift/Components/Separator.swift`: see [Separator](https://ui.suiss.app/docs/components/separator.md)

- `swift/Components/TextVariant.swift`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/swiftui/Sources/EsuissUI/Components/TextVariant.swift)

5. Add the files to your app target.

**Jetpack Compose**

1. Set `minSdk` to 24 or higher and add the dependencies:

```kotlin title="build.gradle.kts"
implementation(platform("androidx.compose:compose-bom:2026.09.00"))
implementation("androidx.compose.foundation:foundation")
implementation("androidx.compose.ui:ui")
implementation("com.adamglin:phosphor-icon-android:1.0.0")
```

2. Copy the theme files every view uses:

- `kotlin/theme/Theme.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Theme.kt)

- `kotlin/theme/Tokens.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/theme/Tokens.kt)

3. Copy the source and every file it uses:

```kt title="kotlin/interactions/ReorderList.kt"
package com.esuiss.ui.interactions

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationVector1D
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.snap
import androidx.compose.animation.core.spring
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.draggable
import androidx.compose.foundation.gestures.rememberDraggableState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.onPlaced
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.semantics.CustomAccessibilityAction
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.customActions
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.DotsSixVertical
import com.esuiss.ui.components.Haptics
import com.esuiss.ui.components.Icon
import com.esuiss.ui.components.ItemGroupVariant
import com.esuiss.ui.components.LocalItemGroupVariant
import com.esuiss.ui.components.LocalContentColor
import com.esuiss.ui.components.LocalContentStyle
import com.esuiss.ui.components.formReducedMotion
import com.esuiss.ui.components.rememberHaptics
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Shadows
import com.esuiss.ui.theme.Typography
import com.esuiss.ui.theme.shadow
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@Stable
interface ReorderListScope {
    val key: String
    val index: Int
    val dragging: Boolean
}

private val liftSpring = spring<Float>(dampingRatio = Spring.DampingRatioNoBouncy, stiffness = Spring.StiffnessMedium)

private val settleSpring = spring<Float>(dampingRatio = Spring.DampingRatioNoBouncy, stiffness = Spring.StiffnessMediumLow)

private class ReorderListItemScope(
    override val key: String,
    override val index: Int,
    override val dragging: Boolean,
) : ReorderListScope

@Stable
private class ReorderController {
    var order by mutableStateOf(emptyList<String>())
    var active by mutableStateOf<String?>(null)
    var settling by mutableStateOf<String?>(null)
    val raised: String? get() = active ?: settling
    var reduced = false
    var offset by mutableFloatStateOf(0f)
    val heights = mutableStateMapOf<String, Int>()
    var onChange: (List<String>) -> Unit = {}
    val placements = mutableMapOf<String, Animatable<Float, AnimationVector1D>>()
    var scope: CoroutineScope? = null
    var haptics: Haptics? = null

    fun start(key: String) {
        active = key
        offset = placements[key]?.value ?: 0f
        haptics?.perform(HapticFeedbackType.LongPress)
    }

    fun drag(delta: Float) {
        val key = active ?: return
        offset += delta
        var index = order.indexOf(key)
        if (index < 0) return
        while (true) {
            val next = order.getOrNull(index + 1)
            val previous = order.getOrNull(index - 1)
            val nextHeight = next?.let { heights[it] } ?: 0
            val previousHeight = previous?.let { heights[it] } ?: 0
            when {
                next != null && offset > nextHeight / 2f -> {
                    order = order.toMutableList().apply { add(index + 1, removeAt(index)) }
                    offset -= nextHeight
                    index += 1
                    haptics?.selection()
                }
                previous != null && offset < -previousHeight / 2f -> {
                    order = order.toMutableList().apply { add(index - 1, removeAt(index)) }
                    offset += previousHeight
                    index -= 1
                    haptics?.selection()
                }
                else -> break
            }
        }
        onChange(order)
    }

    fun end() {
        val key = active ?: return
        haptics?.perform(HapticFeedbackType.GestureEnd)
        val released = offset
        val placement = placements[key]
        val launcher = scope
        if (placement == null || launcher == null) {
            active = null
            offset = 0f
            return
        }
        launcher.launch {
            placement.snapTo(released)
            settling = key
            active = null
            offset = 0f
            try {
                if (reduced) placement.snapTo(0f) else placement.animateTo(0f, settleSpring)
            } finally {
                if (settling == key) settling = null
            }
        }
    }
}

private class ReorderHandleTarget(val controller: ReorderController, val key: String)

private val LocalReorderHandle = staticCompositionLocalOf<ReorderHandleTarget?> { null }

private val LocalReorderLift = staticCompositionLocalOf { 0f }

@Composable
fun ReorderList(
    value: List<String>,
    onValueChange: (List<String>) -> Unit,
    modifier: Modifier = Modifier,
    moveUpLabel: String = "Move up",
    moveDownLabel: String = "Move down",
    item: @Composable ReorderListScope.(String) -> Unit,
) {
    val colors = EsuissTheme.colors
    val scope = rememberCoroutineScope()
    val controller = remember { ReorderController() }
    val change by rememberUpdatedState(onValueChange)
    controller.onChange = { if (it != value) change(it) }
    controller.scope = scope
    controller.haptics = rememberHaptics()
    val reduced = formReducedMotion()
    controller.reduced = reduced
    val inset = LocalItemGroupVariant.current == ItemGroupVariant.Inset
    if (controller.active == null && controller.order != value) controller.order = value
    val order = controller.order
    Column(modifier = modifier) {
        order.forEachIndexed { index, itemKey ->
            key(itemKey) {
                val dragging = controller.active == itemKey
                val raised = controller.raised
                val previous = order.getOrNull(index - 1)
                val hideLine = index == 0 || itemKey == raised || previous == raised
                val placement = remember { Animatable(0f) }
                DisposableEffect(itemKey, placement) {
                    controller.placements[itemKey] = placement
                    onDispose { controller.placements.remove(itemKey) }
                }
                var placed by remember { mutableFloatStateOf(Float.NaN) }
                val lift by animateFloatAsState(
                    targetValue = if (dragging) 1f else 0f,
                    animationSpec = when {
                        reduced -> snap()
                        dragging -> liftSpring
                        else -> settleSpring
                    },
                    label = "lift",
                )
                val actions = buildList {
                    if (index > 0) {
                        add(
                            CustomAccessibilityAction(moveUpLabel) {
                                change(order.toMutableList().apply { add(index - 1, removeAt(index)) })
                                true
                            },
                        )
                    }
                    if (index < order.lastIndex) {
                        add(
                            CustomAccessibilityAction(moveDownLabel) {
                                change(order.toMutableList().apply { add(index + 1, removeAt(index)) })
                                true
                            },
                        )
                    }
                }
                Box(
                    modifier = Modifier
                        .zIndex(if (itemKey == raised || lift > 0f) 1f else 0f)
                        .onSizeChanged { controller.heights[itemKey] = it.height }
                        .onPlaced { coordinates ->
                            val y = coordinates.parentCoordinates?.let { parent ->
                                parent.localPositionOf(coordinates, Offset.Zero).y
                            } ?: 0f
                            val old = placed
                            placed = y
                            if (!old.isNaN() && old != y && controller.active != itemKey && !reduced) {
                                scope.launch {
                                    val velocity = placement.velocity
                                    placement.snapTo(placement.value + old - y)
                                    placement.animateTo(0f, settleSpring, velocity)
                                }
                            }
                        }
                        .graphicsLayer {
                            translationY = if (dragging) controller.offset else placement.value
                            val scale = if (reduced || inset) 1f else 1f + 0.02f * lift
                            scaleX = scale
                            scaleY = scale
                        }
                        .drawBehind {
                            if (!hideLine) {
                                val stroke = 1.dp.toPx()
                                val inset = 16.dp.toPx()
                                val start = if (layoutDirection == LayoutDirection.Rtl) 0f else inset
                                drawRect(colors.border, Offset(start, 0f), Size(size.width - inset, stroke))
                            }
                        }
                        .semantics { customActions = actions },
                ) {
                    CompositionLocalProvider(
                        LocalReorderHandle provides ReorderHandleTarget(controller, itemKey),
                        LocalReorderLift provides lift,
                    ) {
                        ReorderListItemScope(itemKey, index, dragging).item(itemKey)
                    }
                }
            }
        }
    }
}

@Composable
fun ReorderListItem(
    modifier: Modifier = Modifier,
    content: @Composable RowScope.() -> Unit,
) {
    val colors = EsuissTheme.colors
    val lift = LocalReorderLift.current
    val shape = if (LocalItemGroupVariant.current == ItemGroupVariant.Inset) RoundedCornerShape(Radius.xl2) else RectangleShape
    val shadow = Shadows.lg
    Row(
        modifier = modifier
            .fillMaxWidth()
            .then(
                if (lift > 0f) {
                    Modifier
                        .shadow(shadow.alpha(lift), shape)
                        .background(colors.card.copy(alpha = lift), shape)
                } else {
                    Modifier
                },
            )
            .heightIn(min = 52.dp)
            .padding(start = 16.dp, end = 4.dp),
        horizontalArrangement = Arrangement.spacedBy(12.dp),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        CompositionLocalProvider(
            LocalContentStyle provides Typography.base.copy(color = colors.foreground),
            LocalContentColor provides colors.foreground,
        ) {
            content()
        }
    }
}

@Composable
fun ReorderListHandle(
    modifier: Modifier = Modifier,
    contentDescription: String = "Reorder",
) {
    val colors = EsuissTheme.colors
    val target = LocalReorderHandle.current ?: return
    val controller = target.controller
    val itemKey = target.key
    val state = rememberDraggableState { delta -> controller.drag(delta) }
    Box(
        modifier = modifier
            .size(44.dp)
            .draggable(
                state = state,
                orientation = Orientation.Vertical,
                startDragImmediately = true,
                onDragStarted = { controller.start(itemKey) },
                onDragStopped = { controller.end() },
            )
            .semantics { this.contentDescription = contentDescription },
        contentAlignment = Alignment.Center,
    ) {
        Icon(PhosphorIcons.Regular.DotsSixVertical, contentDescription = null, size = 20.dp, tint = colors.mutedForeground)
    }
}
```

- `kotlin/components/Button.kt`: see [Button](https://ui.suiss.app/docs/components/button.md)

- `kotlin/components/ButtonGroup.kt`: see [Button Group](https://ui.suiss.app/docs/components/button-group.md)

- `kotlin/components/Content.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/Content.kt)

- `kotlin/components/FormSupport.kt`: [source](https://github.com/e-suiss/ui/blob/main/packages/mobile/kotlin/ui/src/main/kotlin/com/esuiss/ui/components/FormSupport.kt)

- `kotlin/components/Haptics.kt`: see [Haptics](https://ui.suiss.app/docs/components/haptics.md)

- `kotlin/components/Header.kt`: see [Header](https://ui.suiss.app/docs/components/header.md)

- `kotlin/components/Icon.kt`: see [Icon](https://ui.suiss.app/docs/components/icon.md)

- `kotlin/components/Item.kt`: see [Item](https://ui.suiss.app/docs/components/item.md)

4. Update the `com.esuiss.ui` package names to match your project.

## Usage

```tsx
import { ReorderList, ReorderListItem, ReorderListHandle } from "@/components/interactions/reorder-list"
```

```tsx
<ReorderDemo />
```

`ReorderList` is controlled: pass `value` as an array of item keys and update it in `onValueChange`. Give each `ReorderListItem` a `value` matching its key, and place a `ReorderListHandle` anywhere inside it, at the start or end. Place the list inside an `ItemGroup` with the `inset` variant for a rounded group; the lifted row then keeps the group's shape.

Only the handle starts a drag, so the rest of the row can still be pressed or scrolled.

## Examples

### Inset

Rows inside an inset `ItemGroup`.

![Preview](https://ui.suiss.app/previews/interactions-reorder-list--inset.light.webp)

```tsx
import * as React from "react"
import { View } from "react-native"
import { ReorderList, ReorderListHandle, ReorderListItem } from "@/components/interactions/reorder-list"
import { ItemGroup } from "@/components/ui/item"
import { Text } from "@/components/ui/text"

const tasks: Record<string, { title: string; detail?: string }> = {
  inbox: { title: "Inbox", detail: "12 messages" },
  today: { title: "Today" },
  upcoming: { title: "Upcoming", detail: "Next 7 days" },
  someday: { title: "Someday" },
  archive: {
    title: "Archive",
    detail: "Everything you finished, kept for later reference",
  },
}

const initialOrder = Object.keys(tasks)

function renderRows(value: string[]) {
  return value.map((key) => {
    const task = tasks[key]
    return (
      <ReorderListItem key={key} value={key} className="ps-4">
        <View className="min-w-0 flex-1 py-3">
          <Text numberOfLines={1}>{task.title}</Text>
          {task.detail ? (
            <Text className="text-sm text-muted-foreground">{task.detail}</Text>
          ) : null}
        </View>
        <ReorderListHandle accessibilityLabel={`Reorder ${task.title}`} />
      </ReorderListItem>
    )
  })
}

function ReorderDemo({ inset = false }: { inset?: boolean }) {
  const [value, setValue] = React.useState(initialOrder)
  return (
    <View className="gap-3">
      {inset ? (
        <ItemGroup variant="inset">
          <ReorderList value={value} onValueChange={setValue}>
            {renderRows(value)}
          </ReorderList>
        </ItemGroup>
      ) : (
        <ReorderList value={value} onValueChange={setValue}>
          {renderRows(value)}
        </ReorderList>
      )}
      <Text role="status" className="text-sm text-muted-foreground">
        {value.map((key) => tasks[key].title).join(", ")}
      </Text>
    </View>
  )
}

export function ReorderListInsetExample() {
  return (
    <ReorderDemo inset />
  )
}
```

```swift
import EsuissUI
import SwiftUI

struct ReorderListInsetExample: View {
  var body: some View {
    ReorderListDemo(inset: true)
  }
}

struct ReorderListTask {
  let title: String
  var detail: String?
}

let reorderListTasks: [String: ReorderListTask] = [
  "inbox": ReorderListTask(title: "Inbox", detail: "12 messages"),
  "today": ReorderListTask(title: "Today"),
  "upcoming": ReorderListTask(title: "Upcoming", detail: "Next 7 days"),
  "someday": ReorderListTask(title: "Someday"),
  "archive": ReorderListTask(title: "Archive", detail: "Everything you finished, kept for later reference"),
]

let reorderListOrder = ["inbox", "today", "upcoming", "someday", "archive"]

struct ReorderListDemo: View {
  var inset = false

  @State private var value = reorderListOrder

  var body: some View {
    VStack(alignment: .leading, spacing: 12) {
      list
      Text(verbatim: value.compactMap { reorderListTasks[$0]?.title }.joined(separator: ", "))
        .textStyle(.sm)
        .foregroundStyle(EsuissColor.mutedForeground)
        .accessibilityAddTraits(.updatesFrequently)
    }
  }

  @ViewBuilder
  var list: some View {
    if inset {
      ItemGroup(.inset) {
        rows
      }
    } else {
      rows
    }
  }

  var rows: some View {
    ReorderList($value) { key in
      if let task = reorderListTasks[key] {
        VStack(alignment: .leading, spacing: 0) {
          Text(verbatim: task.title)
            .textStyle(.base)
            .foregroundStyle(EsuissColor.foreground)
            .lineLimit(1)
          if let detail = task.detail {
            Text(verbatim: detail)
              .textStyle(.sm)
              .foregroundStyle(EsuissColor.mutedForeground)
          }
        }
        .padding(.vertical, 12)
      }
    }
  }
}
```

```kotlin
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.LiveRegionMode
import androidx.compose.ui.semantics.liveRegion
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.ItemGroup
import com.esuiss.ui.components.ItemGroupVariant
import com.esuiss.ui.components.Text
import com.esuiss.ui.interactions.ReorderList
import com.esuiss.ui.interactions.ReorderListHandle
import com.esuiss.ui.interactions.ReorderListItem
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography

@Composable
fun ReorderListInsetExample() {
    ReorderListDemo(inset = true)
}

class ReorderListTask(val title: String, val detail: String? = null)

val reorderListTasks = linkedMapOf(
    "inbox" to ReorderListTask("Inbox", "12 messages"),
    "today" to ReorderListTask("Today"),
    "upcoming" to ReorderListTask("Upcoming", "Next 7 days"),
    "someday" to ReorderListTask("Someday"),
    "archive" to ReorderListTask("Archive", "Everything you finished, kept for later reference"),
)

val reorderListInitial = reorderListTasks.keys.toList()

@Composable
fun ReorderListDemo(inset: Boolean) {
    val colors = EsuissTheme.colors
    var value by rememberSaveable { mutableStateOf(reorderListInitial) }
    Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
        val list = @Composable {
            ReorderList(
                value = value,
                onValueChange = { value = it },
            ) { key ->
                val task = reorderListTasks.getValue(key)
                ReorderListItem {
                    Column(Modifier.weight(1f).padding(vertical = 12.dp)) {
                        Text(task.title, maxLines = 1, overflow = TextOverflow.Ellipsis)
                        if (task.detail != null) {
                            Text(task.detail, style = Typography.sm.copy(color = colors.mutedForeground))
                        }
                    }
                    ReorderListHandle(contentDescription = "Reorder ${task.title}")
                }
            }
        }
        if (inset) ItemGroup(variant = ItemGroupVariant.Inset) { list() } else list()
        Text(
            value.joinToString(", ") { reorderListTasks.getValue(it).title },
            modifier = Modifier.semantics { liveRegion = LiveRegionMode.Polite },
            style = Typography.sm.copy(color = colors.mutedForeground),
        )
    }
}
```

**React Native, Jetpack Compose**

### Leading handle

Places the handle at the start of each row.

![Preview](https://ui.suiss.app/previews/interactions-reorder-list--leading-handle.light.webp)

```tsx
import * as React from "react"
import { ReorderList, ReorderListHandle, ReorderListItem } from "@/components/interactions/reorder-list"
import { Text } from "@/components/ui/text"

const tasks: Record<string, { title: string; detail?: string }> = {
  inbox: { title: "Inbox", detail: "12 messages" },
  today: { title: "Today" },
  upcoming: { title: "Upcoming", detail: "Next 7 days" },
  someday: { title: "Someday" },
  archive: {
    title: "Archive",
    detail: "Everything you finished, kept for later reference",
  },
}

const initialOrder = Object.keys(tasks)

function LeadingHandleDemo() {
  const [value, setValue] = React.useState(initialOrder)
  return (
    <ReorderList
      value={value}
      onValueChange={setValue}
      moveUpLabel="Move earlier"
      moveDownLabel="Move later"
    >
      {value.map((key) => (
        <ReorderListItem key={key} value={key} className="pe-4">
          <ReorderListHandle
            accessibilityLabel={`Reorder ${tasks[key].title}`}
          />
          <Text numberOfLines={1} className="flex-1 py-3">
            {tasks[key].title}
          </Text>
        </ReorderListItem>
      ))}
    </ReorderList>
  )
}

export function ReorderListLeadingHandleExample() {
  return (
    <LeadingHandleDemo />
  )
}
```

```kotlin
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Text
import com.esuiss.ui.interactions.ReorderList
import com.esuiss.ui.interactions.ReorderListHandle
import com.esuiss.ui.interactions.ReorderListItem

class ReorderListTask(val title: String, val detail: String? = null)

val reorderListTasks = linkedMapOf(
    "inbox" to ReorderListTask("Inbox", "12 messages"),
    "today" to ReorderListTask("Today"),
    "upcoming" to ReorderListTask("Upcoming", "Next 7 days"),
    "someday" to ReorderListTask("Someday"),
    "archive" to ReorderListTask("Archive", "Everything you finished, kept for later reference"),
)

val reorderListInitial = reorderListTasks.keys.toList()

@Composable
fun ReorderListLeadingHandle() {
    var value by rememberSaveable { mutableStateOf(reorderListInitial) }
    ReorderList(
        value = value,
        onValueChange = { value = it },
        moveUpLabel = "Move earlier",
        moveDownLabel = "Move later",
    ) { key ->
        val task = reorderListTasks.getValue(key)
        ReorderListItem(Modifier.padding(end = 12.dp)) {
            ReorderListHandle(contentDescription = "Reorder ${task.title}")
            Text(
                task.title,
                modifier = Modifier.weight(1f).padding(vertical = 12.dp),
                maxLines = 1,
                overflow = TextOverflow.Ellipsis,
            )
        }
    }
}
```

## API Reference

### ReorderList

The root that renders items in `value` order.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string[]` | Required | Item keys in their current order. |
| `onValueChange` | `(value: string[]) => void` | Required | Called with the new order after a move. |
| `moveUpLabel` | `string` | `"Move up"` | Label of the move up accessibility action. Defaults to `Move up`. |
| `moveDownLabel` | `string` | `"Move down"` | Label of the move down accessibility action. Defaults to `Move down`. |

Also accepts the props of `ViewProps`.

### ReorderListItem

One row, keyed by its `value`.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | Required | The key of this item. |

Also accepts the props of `ViewProps`.

### ReorderListHandle

The grip that starts a drag.

Also accepts the props of `ViewProps`.

## Accessibility

- The handle has the `button` role and offers `moveUp` and `moveDown` accessibility actions, so screen reader users can reorder without dragging.
- Move up is omitted on the first row and move down on the last.

## Notes

- Haptics play when the drag starts (medium impact), each time the target slot changes (selection) and on release (light impact), if the app provides an adapter through `HapticsProvider`.
- The dragged row shows a `bg-card` layer with a shadow, rounded inside an inset group.
- The lift scale is skipped inside an inset group and when reduce motion is on; springs respect the system reduce motion setting.

