Drag List
A React Native reorderable list where you drag a grip and the other rows spring out of the way, with move actions for screen readers.
A reorderable list. Press the grip on a row and drag: the row lifts and follows the pointer, the rows it passes spring out of the way, and on release it settles into its slot. Each grip is also an accessible control with move up and move down actions, so reordering never needs a gesture. Built for React Native and Expo with react-native only; this page previews it in the browser through react-native-web.
Installation
CLI
npx @modus-ui/cli add drag-listManual
- Copy the code from the component tab.
- Create a file at
components/ui/drag-list.tsx. - Paste the code.
It needs no packages beyond react-native, which your Expo or React Native app already has.
Usage
The list is controlled: it reorders only when you pass it a new data. It is as tall as its rows, so put it inside a ScrollView if there are many.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | T[] | - | The items, in order. The list reorders only when data does. |
renderItem | (item: T, state: { dragging: boolean }) => ReactNode | - | Renders a row's content. The grip handle is added beside it. |
keyExtractor | (item: T, index: number) => string | - | A stable key for each item. |
onReorder | (next: T[]) => void | - | Called once, after a dragged row has settled, with the new order. Not called if nothing moved. |
rowHeight | number | 64 | Height of every row. Rows have a fixed height so slots can be computed exactly. |
colors | Partial<DragListColors> | - | Overrides row, border and handle. |
style | StyleProp<ViewStyle> | - | Style for the list container. |
Comments