react-native-reorderable-list 0.8.0 → 0.9.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 +90 -12
- package/lib/commonjs/components/ReorderableListCell.js +8 -5
- package/lib/commonjs/components/ReorderableListCell.js.map +1 -1
- package/lib/commonjs/components/ReorderableListCore/ReorderableListCore.js +9 -11
- package/lib/commonjs/components/ReorderableListCore/ReorderableListCore.js.map +1 -1
- package/lib/commonjs/components/ReorderableListCore/useReorderableListCore.js +24 -4
- package/lib/commonjs/components/ReorderableListCore/useReorderableListCore.js.map +1 -1
- package/lib/commonjs/contexts/ReorderableCellContext.js.map +1 -1
- package/lib/commonjs/contexts/ReorderableListContext.js.map +1 -1
- package/lib/commonjs/hooks/index.js +11 -0
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useIsActive.js +16 -0
- package/lib/commonjs/hooks/useIsActive.js.map +1 -0
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/components/ReorderableListCell.js +8 -5
- package/lib/module/components/ReorderableListCell.js.map +1 -1
- package/lib/module/components/ReorderableListCore/ReorderableListCore.js +9 -11
- package/lib/module/components/ReorderableListCore/ReorderableListCore.js.map +1 -1
- package/lib/module/components/ReorderableListCore/useReorderableListCore.js +25 -5
- package/lib/module/components/ReorderableListCore/useReorderableListCore.js.map +1 -1
- package/lib/module/contexts/ReorderableCellContext.js.map +1 -1
- package/lib/module/contexts/ReorderableListContext.js.map +1 -1
- package/lib/module/hooks/index.js +1 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useIsActive.js +9 -0
- package/lib/module/hooks/useIsActive.js.map +1 -0
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/components/ReorderableListCell.d.ts.map +1 -1
- package/lib/typescript/components/ReorderableListCore/ReorderableListCore.d.ts.map +1 -1
- package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts +5 -1
- package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts.map +1 -1
- package/lib/typescript/contexts/ReorderableCellContext.d.ts +1 -0
- package/lib/typescript/contexts/ReorderableCellContext.d.ts.map +1 -1
- package/lib/typescript/contexts/ReorderableListContext.d.ts +1 -0
- package/lib/typescript/contexts/ReorderableListContext.d.ts.map +1 -1
- package/lib/typescript/hooks/index.d.ts +1 -0
- package/lib/typescript/hooks/index.d.ts.map +1 -1
- package/lib/typescript/hooks/useIsActive.d.ts +2 -0
- package/lib/typescript/hooks/useIsActive.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/types/props.d.ts +12 -0
- package/lib/typescript/types/props.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/ReorderableListCell.tsx +7 -6
- package/src/components/ReorderableListCore/ReorderableListCore.tsx +7 -9
- package/src/components/ReorderableListCore/useReorderableListCore.ts +33 -3
- package/src/contexts/ReorderableCellContext.ts +1 -0
- package/src/contexts/ReorderableListContext.ts +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useIsActive.ts +7 -0
- package/src/index.ts +2 -0
- package/src/types/props.ts +12 -0
|
@@ -43,7 +43,6 @@ interface ReorderableListCoreProps<T> extends ReorderableListProps<T> {
|
|
|
43
43
|
|
|
44
44
|
const ReorderableListCore = <T,>(
|
|
45
45
|
{
|
|
46
|
-
data,
|
|
47
46
|
autoscrollThreshold = 0.1,
|
|
48
47
|
autoscrollSpeedScale = 1,
|
|
49
48
|
autoscrollDelay = AUTOSCROLL_CONFIG.delay,
|
|
@@ -54,17 +53,17 @@ const ReorderableListCore = <T,>(
|
|
|
54
53
|
onScroll,
|
|
55
54
|
onDragStart,
|
|
56
55
|
onDragEnd,
|
|
57
|
-
keyExtractor,
|
|
58
|
-
extraData,
|
|
59
56
|
scrollViewContainerRef,
|
|
60
57
|
scrollViewHeightY,
|
|
61
58
|
scrollViewScrollOffsetY,
|
|
62
59
|
scrollViewScrollEnabled,
|
|
63
|
-
scrollEnabled,
|
|
64
60
|
initialScrollViewScrollEnabled,
|
|
65
61
|
scrollable,
|
|
66
62
|
outerScrollGesture,
|
|
67
63
|
cellAnimations,
|
|
64
|
+
shouldUpdateActiveItem,
|
|
65
|
+
panEnabled = true,
|
|
66
|
+
panActivateAfterLongPress,
|
|
68
67
|
...rest
|
|
69
68
|
}: ReorderableListCoreProps<T>,
|
|
70
69
|
ref: React.ForwardedRef<FlatList<T>>,
|
|
@@ -99,13 +98,16 @@ const ReorderableListCore = <T,>(
|
|
|
99
98
|
// flatlist will default to true if we pass explicitly undefined,
|
|
100
99
|
// but internally we would treat it as false, so we force true
|
|
101
100
|
initialScrollEnabled:
|
|
102
|
-
typeof scrollEnabled === 'undefined' ? true : scrollEnabled,
|
|
101
|
+
typeof rest.scrollEnabled === 'undefined' ? true : rest.scrollEnabled,
|
|
103
102
|
initialScrollViewScrollEnabled:
|
|
104
103
|
typeof initialScrollViewScrollEnabled === 'undefined'
|
|
105
104
|
? true
|
|
106
105
|
: initialScrollViewScrollEnabled,
|
|
107
106
|
nestedScrollable: scrollable,
|
|
108
107
|
cellAnimations,
|
|
108
|
+
shouldUpdateActiveItem,
|
|
109
|
+
panEnabled,
|
|
110
|
+
panActivateAfterLongPress,
|
|
109
111
|
});
|
|
110
112
|
|
|
111
113
|
const combinedGesture = useMemo(() => {
|
|
@@ -145,17 +147,13 @@ const ReorderableListCore = <T,>(
|
|
|
145
147
|
<AnimatedFlatList
|
|
146
148
|
{...rest}
|
|
147
149
|
ref={handleRef}
|
|
148
|
-
data={data}
|
|
149
150
|
CellRendererComponent={renderAnimatedCell}
|
|
150
151
|
onLayout={handleFlatListLayout}
|
|
151
152
|
onScroll={composedScrollHandler}
|
|
152
153
|
scrollEventThrottle={1}
|
|
153
154
|
horizontal={false}
|
|
154
155
|
removeClippedSubviews={false}
|
|
155
|
-
keyExtractor={keyExtractor}
|
|
156
|
-
extraData={extraData}
|
|
157
156
|
numColumns={1}
|
|
158
|
-
scrollEnabled={scrollEnabled}
|
|
159
157
|
/>
|
|
160
158
|
</GestureDetector>
|
|
161
159
|
</ReorderableListContext.Provider>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {useCallback, useEffect, useMemo} from 'react';
|
|
1
|
+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
FlatList,
|
|
4
4
|
LayoutChangeEvent,
|
|
@@ -59,6 +59,9 @@ interface UseReorderableListCoreArgs<T> {
|
|
|
59
59
|
initialScrollViewScrollEnabled: boolean | undefined;
|
|
60
60
|
nestedScrollable: boolean | undefined;
|
|
61
61
|
cellAnimations: ReorderableListCellAnimations | undefined;
|
|
62
|
+
shouldUpdateActiveItem: boolean | undefined;
|
|
63
|
+
panEnabled: boolean;
|
|
64
|
+
panActivateAfterLongPress: number | undefined;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
export const useReorderableListCore = <T>({
|
|
@@ -80,8 +83,12 @@ export const useReorderableListCore = <T>({
|
|
|
80
83
|
initialScrollViewScrollEnabled,
|
|
81
84
|
nestedScrollable,
|
|
82
85
|
cellAnimations,
|
|
86
|
+
shouldUpdateActiveItem,
|
|
87
|
+
panActivateAfterLongPress,
|
|
88
|
+
panEnabled,
|
|
83
89
|
}: UseReorderableListCoreArgs<T>) => {
|
|
84
90
|
const flatListRef = useAnimatedRef<FlatList>();
|
|
91
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
85
92
|
const scrollEnabled = useSharedValue(initialScrollEnabled);
|
|
86
93
|
const gestureState = useSharedValue<State>(State.UNDETERMINED);
|
|
87
94
|
const currentY = useSharedValue(0);
|
|
@@ -124,6 +131,7 @@ export const useReorderableListCore = <T>({
|
|
|
124
131
|
currentIndex,
|
|
125
132
|
draggedIndex,
|
|
126
133
|
dragEndHandlers,
|
|
134
|
+
activeIndex,
|
|
127
135
|
scale: scale || scaleDefault,
|
|
128
136
|
opacity: opacity || opacityDefault,
|
|
129
137
|
}),
|
|
@@ -132,6 +140,7 @@ export const useReorderableListCore = <T>({
|
|
|
132
140
|
currentIndex,
|
|
133
141
|
draggedIndex,
|
|
134
142
|
dragEndHandlers,
|
|
143
|
+
activeIndex,
|
|
135
144
|
scale,
|
|
136
145
|
scaleDefault,
|
|
137
146
|
opacity,
|
|
@@ -177,9 +186,21 @@ export const useReorderableListCore = <T>({
|
|
|
177
186
|
],
|
|
178
187
|
);
|
|
179
188
|
|
|
189
|
+
const panGestureHandlerWithOptions = useMemo(() => {
|
|
190
|
+
if (typeof panActivateAfterLongPress === 'number') {
|
|
191
|
+
panGestureHandler.activateAfterLongPress(panActivateAfterLongPress);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!panEnabled) {
|
|
195
|
+
panGestureHandler.enabled(panEnabled);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return panGestureHandler;
|
|
199
|
+
}, [panActivateAfterLongPress, panEnabled, panGestureHandler]);
|
|
200
|
+
|
|
180
201
|
const gestureHandler = useMemo(
|
|
181
|
-
() => Gesture.Simultaneous(Gesture.Native(),
|
|
182
|
-
[
|
|
202
|
+
() => Gesture.Simultaneous(Gesture.Native(), panGestureHandlerWithOptions),
|
|
203
|
+
[panGestureHandlerWithOptions],
|
|
183
204
|
);
|
|
184
205
|
|
|
185
206
|
const setScrollEnabled = useCallback(
|
|
@@ -367,6 +388,10 @@ export const useReorderableListCore = <T>({
|
|
|
367
388
|
// enable back scroll on releasing
|
|
368
389
|
runOnJS(setScrollEnabled)(true);
|
|
369
390
|
|
|
391
|
+
if (shouldUpdateActiveItem) {
|
|
392
|
+
runOnJS(setActiveIndex)(-1);
|
|
393
|
+
}
|
|
394
|
+
|
|
370
395
|
// trigger onDragEnd event
|
|
371
396
|
let e = {from: draggedIndex.value, to: currentIndex.value};
|
|
372
397
|
onDragEnd?.(e);
|
|
@@ -644,6 +669,10 @@ export const useReorderableListCore = <T>({
|
|
|
644
669
|
// after scrolling the parent list it would offset the new dragged item in another nested list
|
|
645
670
|
resetSharedValues();
|
|
646
671
|
|
|
672
|
+
if (shouldUpdateActiveItem) {
|
|
673
|
+
runOnJS(setActiveIndex)(index);
|
|
674
|
+
}
|
|
675
|
+
|
|
647
676
|
dragInitialScrollOffsetY.value = flatListScrollOffsetY.value;
|
|
648
677
|
scrollViewDragInitialScrollOffsetY.value = scrollViewScrollOffsetY
|
|
649
678
|
? scrollViewScrollOffsetY.value
|
|
@@ -664,6 +693,7 @@ export const useReorderableListCore = <T>({
|
|
|
664
693
|
},
|
|
665
694
|
[
|
|
666
695
|
resetSharedValues,
|
|
696
|
+
shouldUpdateActiveItem,
|
|
667
697
|
dragInitialScrollOffsetY,
|
|
668
698
|
scrollViewScrollOffsetY,
|
|
669
699
|
scrollViewDragInitialScrollOffsetY,
|
|
@@ -8,6 +8,7 @@ interface ReorderableListContextData {
|
|
|
8
8
|
dragEndHandlers: SharedValue<((from: number, to: number) => void)[][]>;
|
|
9
9
|
scale: SharedValue<number>;
|
|
10
10
|
opacity: SharedValue<number>;
|
|
11
|
+
activeIndex: number;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export const ReorderableListContext = React.createContext<
|
package/src/hooks/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
ScrollViewContainer,
|
|
5
5
|
} from './components';
|
|
6
6
|
import {
|
|
7
|
+
useIsActive,
|
|
7
8
|
useReorderableDrag,
|
|
8
9
|
useReorderableDragEnd,
|
|
9
10
|
useReorderableDragStart,
|
|
@@ -19,6 +20,7 @@ import type {
|
|
|
19
20
|
import {reorderItems} from './utils';
|
|
20
21
|
|
|
21
22
|
export {
|
|
23
|
+
useIsActive,
|
|
22
24
|
useReorderableDrag,
|
|
23
25
|
useReorderableDragStart,
|
|
24
26
|
useReorderableDragEnd,
|
package/src/types/props.ts
CHANGED
|
@@ -74,6 +74,18 @@ export interface ReorderableListProps<T>
|
|
|
74
74
|
* Allows passing an object with shared values that can animate a cell by using the `onDragStart` and `onDragEnd` events.
|
|
75
75
|
*/
|
|
76
76
|
cellAnimations?: ReorderableListCellAnimations;
|
|
77
|
+
/**
|
|
78
|
+
* Whether the active item should be updated. Enables usage of `useIsActive` hook. Default: `false`.
|
|
79
|
+
*/
|
|
80
|
+
shouldUpdateActiveItem?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Wether the pan gestures necessary for dragging are enabled. Default: `true`.
|
|
83
|
+
*/
|
|
84
|
+
panEnabled?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Duration in milliseconds of a long press on the list before pan gestures, necessary for dragging, are allowed to activate.
|
|
87
|
+
*/
|
|
88
|
+
panActivateAfterLongPress?: number;
|
|
77
89
|
/**
|
|
78
90
|
* Event fired after an item is released and the list is reordered.
|
|
79
91
|
*/
|