# ReorderableList

> Organism — orn-ui

> ⚠️ Requires <UIProvider>: This component (like every orn-ui component) must render inside a <UIProvider> ancestor, or it throws at runtime. See https://orn-ui-docs.vercel.app/getting-started.md

> Runs on Expo SDK 54, 55, 56 and 57, and on bare React Native >=0.81 with react >=19.1. No native modules — works in Expo Go, no prebuild.

## Installation

Install just this component (copies the source into your project, no npm dependency)
```bash
npx orn-ui add reorderable-list
```

Or install the whole package and import it
```tsx
pnpm add orn-ui
import { ReorderableList } from 'orn-ui/reorderable-list';
```

Depends on: core (theme + icons)

## Variants

### Long-press a row and drag — the rows in between shift out of the way

```tsx
<ReorderableList
  data={data}
  keyExtractor={(item) => item.id}
  itemHeight={ITEM_HEIGHT}
  onReorder={setData}
  renderItem={(item, _index, dragging) => <Row name={item.name} dragging={dragging} />}
/>
```

### disabled — rows render but can’t be dragged

```tsx
<ReorderableList
  data={INITIAL}
  keyExtractor={(item) => item.id}
  itemHeight={ITEM_HEIGHT}
  disabled
  onReorder={() => {}}
  renderItem={(item, _index, dragging) => <Row name={item.name} dragging={dragging} />}
/>
```

## Full demo source

```tsx
const variants: VariantDef[] = [
  {
    label: 'Long-press a row and drag — the rows in between shift out of the way',
    content: (
      <ReorderableList
        data={data}
        keyExtractor={(item) => item.id}
        itemHeight={ITEM_HEIGHT}
        onReorder={setData}
        renderItem={(item, _index, dragging) => <Row name={item.name} dragging={dragging} />}
      />
    ),
  },
  {
    label: 'disabled — rows render but can’t be dragged',
    content: (
      <ReorderableList
        data={INITIAL}
        keyExtractor={(item) => item.id}
        itemHeight={ITEM_HEIGHT}
        disabled
        onReorder={() => {}}
        renderItem={(item, _index, dragging) => <Row name={item.name} dragging={dragging} />}
      />
    ),
  },
];
return (
  <>
    <Caption style={{ marginBottom: 8 }}>Web preview doesn’t simulate touch drag — see the gif on this page.</Caption>
    <VariantList variants={variants} />
  </>
);
```

## Props

| Name | Type | Default | Description |
|---|---|---|---|
| `data` | `T[]` | — | — |
| `keyExtractor` | `(item: T, index: number) => string` | — | — |
| `itemHeight` | `number` | — | Fixed height of each row: needed to calculate the target index without measuring layout async. |
| `renderItem` | `(item: T, index: number, dragging: boolean) => ReactElement<unknown, string \| JSXElementConstructor<any>>` | — | — |
| `onReorder` | `(data: T[]) => void` | — | Called on release, with the array already reordered. Does not mutate `data`. |
| `onDragStart?` | `(index: number) => void` | — | Starts dragging row `index`. Use it to turn off the container's scroll (`scrollEnabled={false}`) while it lasts: on iOS the parent `UIScrollView` cancels touches on the content as soon as its vertical gesture starts, and without this the drag dies within a few pixels. |
| `onDragEnd?` | `() => void` | — | Ends the drag — on release or cancellation. Always runs if `onDragStart` ran. |
| `disabled?` | `boolean` | false | — |
| `style?` | `StyleProp<ViewStyle>` | — | — |
