SortableGridList
An sortable grid list (based on GridList component)
(code example)
info
This component extends GridList props.
note
This component supports square items only
Usageβ
Live Editor
function Example(props) { const [shouldOrderByIndex, setShouldOrderByIndex] = useState(false); const data = Data.products.map(product => ({...product})); renderItem = ({item}) => { return ( <Card flex customValue={item.id}> <Card.Section imageSource={{uri: item.mediaUrl}} imageStyle={{width: '100%', height: 108.7, borderRadius: BorderRadiuses.br10}} imageProps={{ customOverlayContent: ( <Text margin-s1 h1 orange30> {item.id} </Text> ) }} /> </Card> ); }; return ( <div> <View style={{width: 800}}> <Playground.ToggleControl title={'Order by index'} state={shouldOrderByIndex} setState={setShouldOrderByIndex}/> <SortableGridList data={data} flexMigration // onOrderChange={onOrderChange} maxItemWidth={140} renderItem={renderItem} itemSpacing={Spacings.s3} listPadding={Spacings.s5} containerWidth={800} orderByIndex={shouldOrderByIndex} /> </View> </div> ); }
Result
Loading...
APIβ
dataβ
Do not update 'data' in 'onOrderChange' (i.e. for each order change); only update it when you change the items (i.g. adding and removing an item).β
Data of items with an id prop as unique identifier
any[] & {id: string}
extraDataβ
Pass any extra data that should trigger a re-render
any
flexMigrationβ
A temporary migration flag for enabling flex on the list's container (like it should be by default)
boolean
onOrderChangeβ
Order change callback
(newData: T[], newOrder: ItemsOrder) => void
orderByIndexβ
Wether to reorder the items by index instead of by swapping locations.
Items will move to the new index by pushing other items ahead or aback instead of swapping places with the item at the new index.
boolean
renderItemβ
Custom render item callback
FlatListProps['renderItem']