React Native · Components
SortableList
A list sorted by dragging: task lists, priority order, form rows.
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
- Finish the designDesign
- Write the API endpointsBackend
- Finish the testsTest
- Update the docsDocs
- Publish the releaseRelease
Code
Events
- Events appear here when you interact with the preview.
Grid: color order (mouse, touch, keyboard: Space + arrows)
- #ef4444
- #f59e0b
- #10b981
- #3b82f6
- #8b5cf6
- #ec4899
- #14b8a6
- #64748b
- #f97316
Order of options inside a form (SelectField options in this order)
- 1.Turkish
- 2.English
- 3.German
Import
SortableList
componentA list sorted by dragging: task lists, priority order, form rows. Same API as the web SortableList.
- Touch: long-press an item and drag (immediately from the handle with
handle); other items slide to make room, and the item settles into place on release. List scrolling works normally until the long press completes. - Accessibility: every item has "Move up" / "Move down" actions (VoiceOver/TalkBack rotor); moves and drops are announced.
- Layout: stacked, side by side or grid; items of different sizes also land in the right place.
Examples
SortableHandle
componentDrag handle of a SortableList item. When the list has handle, the item drags only from here, immediately without a long press. For screen readers the "Move up" / "Move down" actions are on the handle.
Examples
moveItem
functionMoves an item in an array from index from to index to; returns a new array (the input is not changed). SortableList onReorder and useFieldArray move use the same rule.
Examples
Layout: stacked, side by side or grid.
SortableItemState
interfaceCurrent state of a SortableList item (when rendering content).
| Name | Type | Description |
|---|---|---|
index | number | Its current index. |
dragging | false | "pointer" | Being dragged? On native only by touch ("pointer"). |
active | boolean | Is this the dragged item (same as dragging; same name as web). |
disabled | boolean | Not draggable? |
SortableMoveInfo
interfaceInformation about a move.
| Name | Type | Description |
|---|---|---|
item | T | The moved item. |
key | string | The item's key. |
from | number | Its old index. |
to | number | Its new index. |
SortableListProps
interfaceProps of the SortableList component.
| Name | Type | Default | Description |
|---|---|---|---|
items? | readonly T[] | Items (controlled). When the order changes onReorder is called with the new array. | |
defaultItems? | readonly T[] | Initial items in uncontrolled use; the list keeps the order itself. | |
onReorder? | (items: T[], info: SortableMoveInfo<T>) => void | Called with the new array when the order changes. | |
onMove? | (from: number, to: number) => void | Only the order change (from → to); useFieldArray's move can be passed. | |
getKey? | (item: T) => string | number | The item's stable key. Defaults to item.key, then item.id. | |
getLabel? | (item: T) => string | The item's name in screen reader announcements. Defaults to label, title, name. | |
children | (item: T, state: SortableItemState) => ReactNode | The item's content. When handle is given, use SortableHandle in the content; the item is dragged only from there. | |
orientation? | SortableOrientation | "vertical" | Layout. In a grid, columns are set via style (flexDirection: "row", flexWrap: "wrap"). |
handle? | boolean | false | true: the item drags only from SortableHandle, immediately (for form rows). false: from anywhere on the item, after a long press, so the list scrolls normally. |
longPressDelay? | number | 250 | Long press duration (ms; without handle). |
disabled? | boolean | Disables all sorting. | |
isItemDisabled? | (item: T) => boolean | This item cannot be dragged. | |
gap? | number | 2 | Gap between items (ui.space units). |
onDragStart? | (info: { item: T; key: string; index: number; }) => void | When a drag starts. | |
onDragEnd? | (info: SortableMoveInfo<T> & { cancelled: boolean; }) => void | When a drag ends; on cancel to equals from. | |
style? | StyleProp<ViewStyle> | Container style. | |
itemStyle? | StyleProp<ViewStyle> | Style of each item's container. | |
testID? | string | Test id. |
SortableHandleProps
interfaceSortableHandle props.
| Name | Type | Description |
|---|---|---|
children? | ReactNode | Content instead of the icon. If omitted the ⋮⋮ handle icon is drawn. |
style? | StyleProp<ViewStyle> | Container style. |