A sortable scrollable grid / list component for React Native, essentially based on react-native-sortable-grid. Does not require react-native-reanimated.
- Change number of columns and row height on the fly
- Performant item additions, deletions, order shuffles, container width/height changes
- Controllable order
- Allows for not-swappable and not-draggable grid elements
- Auto-scroll when dragged item is close to container's borders
npm install react-native-yet-another-sortable --save
Check out example project.
Or check a minimal example to copy-paste:
import React, { useState } from 'react';
import { View, Text } from 'react-native';
import { SortableGrid } from 'react-native-yet-another-sortable';
const Component = () => {
const [ items, setItems ] = useState(Array.from({ length: 5 }, (_, i) => ({ value: i, key: i })));
const [ order, setOrder ] = useState(items.map(({ key }) => key));
return (
<SortableGrid
items={items}
order={order}
renderItem={({ value }) => (<View><Text>{value}</Text></View>)}
onDeactivateDrag={(order) => setOrder(order)}
/>
);
};Autogenerated documentation is here.
When passing items array set dragDisabled property to true for those items that you don't want to be draggable.
Provide a fixed prop with a Set of keys.
- Use
animateActiveStyleproperty by providing function to animate activation progressanimationlike this:
(animation) => requestAnimationFrame(() => {
animation.setValue(1);
Animated.spring(animation, { toValue: 0, velocity: 2000, tension: 2000, friction: 5, useNativeDriver: true }).start();
})- Use
getActiveStyleproperty by providing function that maps theanimationto active Cell style:
(animation) => ({
transform: [ { rotate: animation.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '1deg'] }) } ],
elevation: 10,
zIndex: 1,
})Other side-effects could be performed in onActivateDrag callback.
In order to develop the application or build android .apk from the sources one should:
- Clone this repository
- Navigate to parent directory and install dev dependencies with
npm cifor lintingnpm run lintand typescript typecheckingnpm run typecheck. - Navigate to example folder:
cd example - Install example project dependencies
npm ci, since library has only peer dependencies - Run Metro bundler with
npm run start - Connect physical device or an emulator via adb, like this (tested with mEMU):
adb connect 127.0.0.1:21503adb reverse tcp:8081 tcp:8081
- Build and watch with
npm run-android, changes from src directory are picked automatically because of example metro and babel configurations.
Note: example project is configured in a way, that may cause issues if you save anything as a regular dependency in parent library
PR are always welcome!
