Skip to main content

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-flatlistPatine 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 rowsactivation="handle"
isActiveisActive
ScaleDecorator / ShadowDecoratorbuilt in: the design's shadow and scale
onDragBeginonDragStart(index)
autoscrollThreshold / autoscrollSpeedbuilt in
containerStyle / FlatList propsstyle / 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.