Skip to main content

DraxList

List-agnostic sortable list component. Wraps any list component (FlatList, FlashList, LegendList) with drag-to-reorder powered by useSortableList + SortableContainer + SortableItem.

Import

import { DraxList } from 'react-native-drax';

Usage

<DraxList
data={items}
keyExtractor={(item) => item.id}
onReorder={({ data }) => setItems(data)}
renderItem={({ item }) => <ItemCard item={item} />}
/>

Props

PropTypeDefaultDescription
componentComponentType<any>FlatListList component to render
refRef<any>Ref forwarded to the list component
idstringauto-generatedDraxView id for the container
dataT[]requiredArray of items
keyExtractor(item: T, index: number) => stringrequiredUnique key per item
onReorder(event: SortableReorderEvent<T>) => voidrequiredCalled after reorder
renderItem(info: ListRenderItemInfo<T>) => ReactNoderequiredRender function per item
reorderStrategySortableReorderStrategy'insert''insert' or 'swap'
longPressDelaynumber250ms before drag activates
lockToMainAxisbooleanfalseLock drag to list direction
animationConfigSortableAnimationConfig'default'Animation preset or custom config
inactiveItemStyleViewStyleStyle applied to all non-dragged items during drag
itemEnteringEntryOrExitLayoutTypeReanimated layout animation for items entering
itemExitingEntryOrExitLayoutTypeReanimated layout animation for items exiting
horizontalbooleanfalseHorizontal list layout
numColumnsnumber1Number of columns (grid)
containerStyleStyleProp<ViewStyle>Style for the DraxView wrapper
styleStyleProp<ViewStyle>Style for the list component
itemDraxViewPropsPartial<DraxViewProps>Extra DraxView props per item
containerDraxViewPropsPartial<DraxViewProps>Extra DraxView props for container
onDragStart(event: SortableDragStartEvent<T>) => voidDrag started
onDragPositionChange(event: SortableDragPositionChangeEvent<T>) => voidPosition changed
onDragEnd(event: SortableDragEndEvent<T>) => voidDrag ended

Extra props are forwarded to the underlying list component (e.g., estimatedItemSize for FlashList).

With FlashList

import { FlashList } from '@shopify/flash-list';

<DraxList
component={FlashList}
estimatedItemSize={60}
data={items}
keyExtractor={(item) => item.id}
onReorder={({ data }) => setItems(data)}
renderItem={({ item }) => <ItemCard item={item} />}
/>