Migrate from react-native-draggable-flatlist
- import DraggableFlatList, { ScaleDecorator } from 'react-native-draggable-flatlist';
+ import { SortableHandle, SortableList } from 'patine-ui';
- <DraggableFlatList
- data={data}
- keyExtractor={(item) => item.id}
- onDragEnd={({ data }) => setData(data)}
- renderItem={({ item, drag, isActive }) => (
- <ScaleDecorator>
- <TouchableOpacity onLongPress={drag} disabled={isActive}><Row item={item} /></TouchableOpacity>
- </ScaleDecorator>
- )}
- />
+ <SortableList
+ data={data}
+ keyExtractor={(item) => item.id}
+ onReorder={setData}
+ getItemLabel={(item) => item.title}
+ renderItem={({ item, isActive }) => <Row item={item} highlighted={isActive} trailing={<SortableHandle />} />}
+ />
| react-native-draggable-flatlist | Patine UI |
|---|---|
onDragEnd({ data, from, to }) | onReorder(data, { from, to }) |
renderItem({ drag }) + onLongPress={drag} | rows lift on a long press by themselves; <SortableHandle /> lifts at once |
activationDistance / handle-only rows | activation="handle" |
isActive | isActive |
ScaleDecorator / ShadowDecorator | built in: the design's shadow and scale |
onDragBegin | onDragStart(index) |
autoscrollThreshold / autoscrollSpeed | built in |
containerStyle / FlatList props | style / ScrollView props |
NestableScrollContainer | — |
There's no Reanimated or gesture handler to install. Keyboard users reorder on the web with Space and the arrow keys, and screen readers get Move up and Move down. SortableList renders every row, so it suits lists up to a few hundred rows.
See all migration guides for other libraries, and Comparison for when another library is the better choice.