react-native-reorderable-list 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/components/ReorderableList.js +8 -5
- package/dist/types/props.d.ts +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,9 +44,10 @@ Additional props:
|
|
|
44
44
|
|
|
45
45
|
At the moment it doesn't support these FlatList props:
|
|
46
46
|
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
47
|
+
- `horizontal`
|
|
48
|
+
- `onScroll`
|
|
49
|
+
- `scrollEventThrottle`
|
|
50
|
+
- `numColumns`
|
|
50
51
|
|
|
51
52
|
## Usage
|
|
52
53
|
|
|
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
|
13
|
-
import { FlatList, StatusBar, unstable_batchedUpdates, } from 'react-native';
|
|
13
|
+
import { FlatList, StatusBar, unstable_batchedUpdates, Platform, } from 'react-native';
|
|
14
14
|
import { NativeViewGestureHandler, PanGestureHandler, State, } from 'react-native-gesture-handler';
|
|
15
15
|
import Animated, { useAnimatedGestureHandler, useSharedValue, useAnimatedReaction, runOnJS, useAnimatedStyle, useAnimatedRef, useAnimatedScrollHandler, scrollTo, withTiming, Easing, runOnUI, } from 'react-native-reanimated';
|
|
16
16
|
import composeRefs from '@seznam/compose-react-refs';
|
|
@@ -187,7 +187,7 @@ const ReorderableList = (_a, ref) => {
|
|
|
187
187
|
speed = autoScrollSpeed.value;
|
|
188
188
|
}
|
|
189
189
|
if (speed !== 0) {
|
|
190
|
-
scrollTo(flatList, 0, autoScrollOffset.value + speed,
|
|
190
|
+
scrollTo(flatList, 0, autoScrollOffset.value + speed, Platform.OS === 'android');
|
|
191
191
|
autoScrollOffset.value += speed;
|
|
192
192
|
}
|
|
193
193
|
const { index } = getIndexFromY(currentY.value, autoScrollOffset.value);
|
|
@@ -199,11 +199,14 @@ const ReorderableList = (_a, ref) => {
|
|
|
199
199
|
scrollOffset.value = e.contentOffset.y;
|
|
200
200
|
},
|
|
201
201
|
});
|
|
202
|
-
const handleItemLayout = useCallback(memoize((index) => (e) => {
|
|
202
|
+
const handleItemLayout = useCallback(memoize((index, onLayoutCell) => (e) => {
|
|
203
203
|
itemOffsets[index].value = {
|
|
204
204
|
offset: e.nativeEvent.layout.y,
|
|
205
205
|
length: e.nativeEvent.layout.height,
|
|
206
206
|
};
|
|
207
|
+
if (onLayoutCell) {
|
|
208
|
+
onLayoutCell(e);
|
|
209
|
+
}
|
|
207
210
|
}), [itemOffsets]);
|
|
208
211
|
const drag = useCallback(memoize((index) => () => runOnUI(() => {
|
|
209
212
|
'worklet';
|
|
@@ -232,7 +235,7 @@ const ReorderableList = (_a, ref) => {
|
|
|
232
235
|
var { index, children } = _a, cellProps = __rest(_a, ["index", "children"]);
|
|
233
236
|
return (React.createElement(ReorderableListItem, { key: cellProps.keyExtractor
|
|
234
237
|
? cellProps.keyExtractor(cellProps.data[index], index)
|
|
235
|
-
: index, index: index, currentIndex: currentIndex, draggedIndex: draggedIndex, itemOffsets: itemOffsets, enabledOpacity: enabledOpacity, onLayout: handleItemLayout(index)
|
|
238
|
+
: index, index: index, currentIndex: currentIndex, draggedIndex: draggedIndex, itemOffsets: itemOffsets, enabledOpacity: enabledOpacity, onLayout: handleItemLayout(index, cellProps.onLayout), children: children }));
|
|
236
239
|
}, [currentIndex, draggedIndex, itemOffsets, enabledOpacity, handleItemLayout]);
|
|
237
240
|
const renderDraggableItem = useCallback((info) => {
|
|
238
241
|
itemSeparators.current[info.index] = info.separators;
|
|
@@ -290,7 +293,7 @@ const ReorderableList = (_a, ref) => {
|
|
|
290
293
|
return (React.createElement(PanGestureHandler, { maxPointers: 1, onGestureEvent: handleGestureEvent, onHandlerStateChange: handleGestureEvent, simultaneousHandlers: nativeHandler },
|
|
291
294
|
React.createElement(Animated.View, { ref: container, style: containerStyle, onLayout: handleContainerLayout },
|
|
292
295
|
React.createElement(NativeViewGestureHandler, { ref: nativeHandler },
|
|
293
|
-
React.createElement(AnimatedFlatList, Object.assign({}, rest, { ref: composeRefs(flatList, ref), data: data, CellRendererComponent: renderAnimatedCell, renderItem: renderDraggableItem, onLayout: handleFlatListLayout, onScroll: scrollHandler, keyExtractor: keyExtractor, scrollEventThrottle: 1, horizontal: false }))),
|
|
296
|
+
React.createElement(AnimatedFlatList, Object.assign({}, rest, { ref: composeRefs(flatList, ref), data: data, CellRendererComponent: renderAnimatedCell, renderItem: renderDraggableItem, onLayout: handleFlatListLayout, onScroll: scrollHandler, keyExtractor: keyExtractor, scrollEventThrottle: 1, horizontal: false, numColumns: 1 }))),
|
|
294
297
|
dragged && (React.createElement(Animated.View, { style: [
|
|
295
298
|
styles.draggedItem,
|
|
296
299
|
draggedItemFallbackStyle,
|
package/dist/types/props.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { FlatListProps, ListRenderItemInfo, StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
import { FlatListProps, ListRenderItemInfo, StyleProp, ViewStyle, LayoutChangeEvent } from 'react-native';
|
|
3
3
|
import Animated from 'react-native-reanimated';
|
|
4
|
-
export interface CellProps<T>
|
|
4
|
+
export interface CellProps<T> {
|
|
5
5
|
index: number;
|
|
6
6
|
children?: React.ReactElement;
|
|
7
7
|
data: T[];
|
|
8
|
+
onLayout?: (e: LayoutChangeEvent) => void;
|
|
9
|
+
keyExtractor?: (item: T, index: number) => string;
|
|
8
10
|
}
|
|
9
11
|
export interface ReorderableListRenderItemInfo<T> extends ListRenderItemInfo<T> {
|
|
10
12
|
drag?: () => void;
|
|
@@ -14,7 +16,7 @@ export interface ReorderableListReorderEvent {
|
|
|
14
16
|
fromIndex: number;
|
|
15
17
|
toIndex: number;
|
|
16
18
|
}
|
|
17
|
-
declare type UnsupportedProps = 'horizontal' | 'onScroll' | 'scrollEventThrottle';
|
|
19
|
+
declare type UnsupportedProps = 'horizontal' | 'onScroll' | 'scrollEventThrottle' | 'numColumns';
|
|
18
20
|
export interface ReorderableListProps<T> extends Omit<FlatListProps<T>, UnsupportedProps> {
|
|
19
21
|
data: T[];
|
|
20
22
|
containerStyle?: StyleProp<Animated.AnimateStyle<StyleProp<ViewStyle>>>;
|