react-native-reorderable-list 0.7.1 → 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 +131 -47
- package/lib/commonjs/components/ReorderableList.js +11 -13
- package/lib/commonjs/components/ReorderableList.js.map +1 -1
- package/lib/commonjs/components/ReorderableListCell.js +44 -31
- package/lib/commonjs/components/ReorderableListCell.js.map +1 -1
- package/lib/commonjs/components/ReorderableListCore/ReorderableListCore.js +18 -17
- package/lib/commonjs/components/ReorderableListCore/ReorderableListCore.js.map +1 -1
- package/lib/commonjs/components/ReorderableListCore/animationDefaults.js +34 -0
- package/lib/commonjs/components/ReorderableListCore/animationDefaults.js.map +1 -0
- package/lib/commonjs/components/ReorderableListCore/{constants.js → autoscrollConfig.js} +1 -1
- package/lib/commonjs/components/ReorderableListCore/autoscrollConfig.js.map +1 -0
- package/lib/commonjs/components/ReorderableListCore/useReorderableListCore.js +82 -33
- package/lib/commonjs/components/ReorderableListCore/useReorderableListCore.js.map +1 -1
- package/lib/commonjs/components/ScrollViewContainer.js +2 -2
- package/lib/commonjs/components/ScrollViewContainer.js.map +1 -1
- package/lib/commonjs/components/index.js +0 -11
- package/lib/commonjs/components/index.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 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/misc.js +3 -3
- package/lib/module/components/ReorderableList.js +11 -13
- package/lib/module/components/ReorderableList.js.map +1 -1
- package/lib/module/components/ReorderableListCell.js +45 -32
- package/lib/module/components/ReorderableListCell.js.map +1 -1
- package/lib/module/components/ReorderableListCore/ReorderableListCore.js +17 -15
- package/lib/module/components/ReorderableListCore/ReorderableListCore.js.map +1 -1
- package/lib/module/components/ReorderableListCore/animationDefaults.js +28 -0
- package/lib/module/components/ReorderableListCore/animationDefaults.js.map +1 -0
- package/lib/module/components/ReorderableListCore/{constants.js → autoscrollConfig.js} +1 -1
- package/lib/module/components/ReorderableListCore/autoscrollConfig.js.map +1 -0
- package/lib/module/components/ReorderableListCore/useReorderableListCore.js +82 -33
- package/lib/module/components/ReorderableListCore/useReorderableListCore.js.map +1 -1
- package/lib/module/components/ScrollViewContainer.js +3 -3
- package/lib/module/components/ScrollViewContainer.js.map +1 -1
- package/lib/module/components/index.js +0 -1
- package/lib/module/components/index.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 +3 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/misc.js +3 -3
- package/lib/typescript/components/ReorderableList.d.ts.map +1 -1
- package/lib/typescript/components/ReorderableListCell.d.ts +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/animationDefaults.d.ts +13 -0
- package/lib/typescript/components/ReorderableListCore/animationDefaults.d.ts.map +1 -0
- package/lib/typescript/components/ReorderableListCore/{constants.d.ts → autoscrollConfig.d.ts} +1 -1
- package/lib/typescript/components/ReorderableListCore/autoscrollConfig.d.ts.map +1 -0
- package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts +11 -4
- package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts.map +1 -1
- package/lib/typescript/components/ScrollViewContainer.d.ts.map +1 -1
- package/lib/typescript/components/index.d.ts +0 -1
- package/lib/typescript/components/index.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 +3 -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 +4 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/types/misc.d.ts +3 -3
- package/lib/typescript/types/misc.d.ts.map +1 -1
- package/lib/typescript/types/props.d.ts +31 -31
- package/lib/typescript/types/props.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/components/ReorderableList.tsx +14 -16
- package/src/components/ReorderableListCell.tsx +38 -33
- package/src/components/ReorderableListCore/ReorderableListCore.tsx +22 -13
- package/src/components/ReorderableListCore/animationDefaults.ts +35 -0
- package/src/components/ReorderableListCore/useReorderableListCore.ts +117 -40
- package/src/components/ScrollViewContainer.tsx +7 -3
- package/src/components/index.ts +0 -1
- package/src/contexts/ReorderableCellContext.ts +1 -0
- package/src/contexts/ReorderableListContext.ts +3 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useIsActive.ts +7 -0
- package/src/index.ts +6 -6
- package/src/types/misc.ts +3 -3
- package/src/types/props.ts +32 -37
- package/lib/commonjs/components/ReorderableListCore/constants.js.map +0 -1
- package/lib/commonjs/components/ReorderableListItem.js +0 -87
- package/lib/commonjs/components/ReorderableListItem.js.map +0 -1
- package/lib/module/components/ReorderableListCore/constants.js.map +0 -1
- package/lib/module/components/ReorderableListItem.js +0 -78
- package/lib/module/components/ReorderableListItem.js.map +0 -1
- package/lib/typescript/components/ReorderableListCore/constants.d.ts.map +0 -1
- package/lib/typescript/components/ReorderableListItem.d.ts +0 -4
- package/lib/typescript/components/ReorderableListItem.d.ts.map +0 -1
- package/src/components/ReorderableListItem.tsx +0 -108
- /package/src/components/ReorderableListCore/{constants.ts → autoscrollConfig.ts} +0 -0
|
@@ -4,18 +4,16 @@ import { ReorderableListCore } from './ReorderableListCore';
|
|
|
4
4
|
const ReorderableListWithRef = ({
|
|
5
5
|
scrollEnabled = true,
|
|
6
6
|
...rest
|
|
7
|
-
}, ref) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}));
|
|
19
|
-
};
|
|
7
|
+
}, ref) => /*#__PURE__*/React.createElement(ReorderableListCore, _extends({}, rest, {
|
|
8
|
+
ref: ref,
|
|
9
|
+
scrollEnabled: scrollEnabled,
|
|
10
|
+
initialScrollViewScrollEnabled: true,
|
|
11
|
+
scrollable: true,
|
|
12
|
+
scrollViewContainerRef: undefined,
|
|
13
|
+
scrollViewScrollOffsetY: undefined,
|
|
14
|
+
scrollViewHeightY: undefined,
|
|
15
|
+
outerScrollGesture: undefined,
|
|
16
|
+
scrollViewScrollEnabled: undefined
|
|
17
|
+
}));
|
|
20
18
|
export const ReorderableList = /*#__PURE__*/forwardRef(ReorderableListWithRef);
|
|
21
19
|
//# sourceMappingURL=ReorderableList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","forwardRef","ReorderableListCore","ReorderableListWithRef","scrollEnabled","rest","ref","createElement","_extends","initialScrollViewScrollEnabled","scrollable","scrollViewContainerRef","undefined","scrollViewScrollOffsetY","scrollViewHeightY","outerScrollGesture","scrollViewScrollEnabled","ReorderableList"],"sourceRoot":"../../../src","sources":["components/ReorderableList.tsx"],"mappings":";AAAA,OAAOA,KAAK,IAAGC,UAAU,QAAO,OAAO;AAGvC,SAAQC,mBAAmB,QAAO,uBAAuB;AAGzD,MAAMC,sBAAsB,GAAGA,CAC7B;EAACC,aAAa,GAAG,IAAI;EAAE,GAAGC;AAA6B,CAAC,EACxDC,GAA2B,
|
|
1
|
+
{"version":3,"names":["React","forwardRef","ReorderableListCore","ReorderableListWithRef","scrollEnabled","rest","ref","createElement","_extends","initialScrollViewScrollEnabled","scrollable","scrollViewContainerRef","undefined","scrollViewScrollOffsetY","scrollViewHeightY","outerScrollGesture","scrollViewScrollEnabled","ReorderableList"],"sourceRoot":"../../../src","sources":["components/ReorderableList.tsx"],"mappings":";AAAA,OAAOA,KAAK,IAAGC,UAAU,QAAO,OAAO;AAGvC,SAAQC,mBAAmB,QAAO,uBAAuB;AAGzD,MAAMC,sBAAsB,GAAGA,CAC7B;EAACC,aAAa,GAAG,IAAI;EAAE,GAAGC;AAA6B,CAAC,EACxDC,GAA2B,kBAE3BN,KAAA,CAAAO,aAAA,CAACL,mBAAmB,EAAAM,QAAA,KACdH,IAAI;EACRC,GAAG,EAAEA,GAAI;EACTF,aAAa,EAAEA,aAAc;EAC7BK,8BAA8B,EAAE,IAAK;EACrCC,UAAU,EAAE,IAAK;EACjBC,sBAAsB,EAAEC,SAAU;EAClCC,uBAAuB,EAAED,SAAU;EACnCE,iBAAiB,EAAEF,SAAU;EAC7BG,kBAAkB,EAAEH,SAAU;EAC9BI,uBAAuB,EAAEJ;AAAU,EACpC,CACF;AAED,OAAO,MAAMK,eAAe,gBAAGhB,UAAU,CAACE,sBAAsB,CAEhD","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { memo, useCallback, useMemo } from 'react';
|
|
2
|
-
import Animated, { Easing, runOnUI, useAnimatedReaction, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
2
|
+
import Animated, { Easing, runOnUI, useAnimatedReaction, useAnimatedStyle, useDerivedValue, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
3
3
|
import { ReorderableCellContext, ReorderableListContext } from '../contexts';
|
|
4
4
|
import { useContext } from '../hooks';
|
|
5
5
|
export const ReorderableListCell = /*#__PURE__*/memo(({
|
|
@@ -13,57 +13,70 @@ export const ReorderableListCell = /*#__PURE__*/memo(({
|
|
|
13
13
|
draggedIndex,
|
|
14
14
|
animationDuration
|
|
15
15
|
}) => {
|
|
16
|
-
const dragHandler = useCallback(() => {
|
|
17
|
-
'worklet';
|
|
18
|
-
|
|
19
|
-
startDrag(index);
|
|
20
|
-
}, [startDrag, index]);
|
|
21
|
-
const contextValue = useMemo(() => ({
|
|
22
|
-
index,
|
|
23
|
-
dragHandler,
|
|
24
|
-
draggedIndex
|
|
25
|
-
}), [index, dragHandler, draggedIndex]);
|
|
26
16
|
const {
|
|
27
17
|
currentIndex,
|
|
28
|
-
draggedHeight
|
|
18
|
+
draggedHeight,
|
|
19
|
+
scale,
|
|
20
|
+
opacity,
|
|
21
|
+
activeIndex
|
|
29
22
|
} = useContext(ReorderableListContext);
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
23
|
+
const dragHandler = useCallback(() => runOnUI(startDrag)(index), [startDrag, index]);
|
|
24
|
+
const isActive = activeIndex === index;
|
|
25
|
+
const contextValue = useMemo(() => ({
|
|
26
|
+
index,
|
|
27
|
+
dragHandler,
|
|
28
|
+
draggedIndex,
|
|
29
|
+
isActive
|
|
30
|
+
}), [index, dragHandler, draggedIndex, isActive]);
|
|
31
|
+
|
|
32
|
+
// Keep separate animated reactions that update itemTranslateY
|
|
33
|
+
// otherwise animations might stutter if multiple are triggered
|
|
34
|
+
// (even in other cells, e.g. released item and reordering cells)
|
|
35
|
+
const itemTranslateY = useSharedValue(0);
|
|
36
|
+
const isActiveCell = useDerivedValue(() => draggedIndex.value === index);
|
|
34
37
|
useAnimatedReaction(() => dragY.value, () => {
|
|
35
|
-
if (
|
|
36
|
-
|
|
38
|
+
if (index === draggedIndex.value && currentIndex.value >= 0 && draggedIndex.value >= 0) {
|
|
39
|
+
itemTranslateY.value = dragY.value;
|
|
37
40
|
}
|
|
38
41
|
});
|
|
39
42
|
useAnimatedReaction(() => currentIndex.value, () => {
|
|
40
|
-
if (
|
|
43
|
+
if (index !== draggedIndex.value && currentIndex.value >= 0 && draggedIndex.value >= 0) {
|
|
41
44
|
const moveDown = currentIndex.value > draggedIndex.value;
|
|
42
45
|
const startMove = Math.min(draggedIndex.value, currentIndex.value);
|
|
43
46
|
const endMove = Math.max(draggedIndex.value, currentIndex.value);
|
|
44
47
|
let newValue = 0;
|
|
45
|
-
if (
|
|
48
|
+
if (index >= startMove && index <= endMove) {
|
|
46
49
|
newValue = moveDown ? -draggedHeight.value : draggedHeight.value;
|
|
47
50
|
}
|
|
48
|
-
if (newValue !==
|
|
49
|
-
|
|
51
|
+
if (newValue !== itemTranslateY.value) {
|
|
52
|
+
itemTranslateY.value = withTiming(newValue, {
|
|
50
53
|
duration: animationDuration.value,
|
|
51
54
|
easing: Easing.out(Easing.ease)
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
});
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
60
|
+
if (isActiveCell.value) {
|
|
61
|
+
return {
|
|
62
|
+
transform: [{
|
|
63
|
+
translateY: itemTranslateY.value
|
|
64
|
+
}, {
|
|
65
|
+
scale: scale.value
|
|
66
|
+
}],
|
|
67
|
+
opacity: opacity.value,
|
|
68
|
+
zIndex: 999
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
transform: [{
|
|
73
|
+
translateY: itemTranslateY.value
|
|
74
|
+
}],
|
|
75
|
+
// TODO: move to stylesheet when this is fixed
|
|
76
|
+
// https://github.com/software-mansion/react-native-reanimated/issues/6681#issuecomment-2514228447
|
|
77
|
+
zIndex: 0
|
|
78
|
+
};
|
|
58
79
|
});
|
|
59
|
-
const animatedStyle = useAnimatedStyle(() => ({
|
|
60
|
-
zIndex: itemZIndex.value,
|
|
61
|
-
transform: [{
|
|
62
|
-
translateY: itemDragY.value
|
|
63
|
-
}, {
|
|
64
|
-
translateY: itemPositionY.value
|
|
65
|
-
}]
|
|
66
|
-
}));
|
|
67
80
|
const handleLayout = e => {
|
|
68
81
|
runOnUI((y, height) => {
|
|
69
82
|
itemOffset.value[index] = y;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","memo","useCallback","useMemo","Animated","Easing","runOnUI","useAnimatedReaction","useAnimatedStyle","useSharedValue","withTiming","ReorderableCellContext","ReorderableListContext","useContext","ReorderableListCell","index","startDrag","children","onLayout","itemOffset","itemHeight","dragY","draggedIndex","animationDuration","
|
|
1
|
+
{"version":3,"names":["React","memo","useCallback","useMemo","Animated","Easing","runOnUI","useAnimatedReaction","useAnimatedStyle","useDerivedValue","useSharedValue","withTiming","ReorderableCellContext","ReorderableListContext","useContext","ReorderableListCell","index","startDrag","children","onLayout","itemOffset","itemHeight","dragY","draggedIndex","animationDuration","currentIndex","draggedHeight","scale","opacity","activeIndex","dragHandler","isActive","contextValue","itemTranslateY","isActiveCell","value","moveDown","startMove","Math","min","endMove","max","newValue","duration","easing","out","ease","animatedStyle","transform","translateY","zIndex","handleLayout","e","y","height","nativeEvent","layout","createElement","Provider","View","style"],"sourceRoot":"../../../src","sources":["components/ReorderableListCell.tsx"],"mappings":"AAAA,OAAOA,KAAK,IAAGC,IAAI,EAAEC,WAAW,EAAEC,OAAO,QAAO,OAAO;AAGvD,OAAOC,QAAQ,IACbC,MAAM,EAENC,OAAO,EACPC,mBAAmB,EACnBC,gBAAgB,EAChBC,eAAe,EACfC,cAAc,EACdC,UAAU,QACL,yBAAyB;AAEhC,SAAQC,sBAAsB,EAAEC,sBAAsB,QAAO,aAAa;AAC1E,SAAQC,UAAU,QAAO,UAAU;AAYnC,OAAO,MAAMC,mBAAmB,gBAAGd,IAAI,CACrC,CAAK;EACHe,KAAK;EACLC,SAAS;EACTC,QAAQ;EACRC,QAAQ;EACRC,UAAU;EACVC,UAAU;EACVC,KAAK;EACLC,YAAY;EACZC;AAC2B,CAAC,KAAK;EACjC,M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C,CAAC,CAAC,CAACF,CAAC,CAACG,WAAW,CAACC,MAAM,CAACH,CAAC,EAAED,CAAC,CAACG,WAAW,CAACC,MAAM,CAACF,MAAM,CAAC;IAEvDnC,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAGiC,CAAC,CAAC;EACf,CAAC;EAED,oBACEpD,KAAA,CAAAyD,aAAA,CAAC7C,sBAAsB,CAAC8C,QAAQ;IAACvB,KAAK,EAAEH;EAAa,gBACnDhC,KAAA,CAAAyD,aAAA,CAACrD,QAAQ,CAACuD,IAAI;IAACC,KAAK,EAAEb,aAAc;IAAC5B,QAAQ,EAAEgC;EAAa,GACzDjC,QACY,CACgB,CAAC;AAEtC,CACF,CAAC","ignoreList":[]}
|
|
@@ -2,14 +2,13 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
|
|
|
2
2
|
import React, { useCallback, useMemo } from 'react';
|
|
3
3
|
import { FlatList, Platform } from 'react-native';
|
|
4
4
|
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
5
|
-
import Animated from 'react-native-reanimated';
|
|
6
|
-
import { AUTOSCROLL_CONFIG } from './
|
|
5
|
+
import Animated, { useComposedEventHandler } from 'react-native-reanimated';
|
|
6
|
+
import { AUTOSCROLL_CONFIG } from './autoscrollConfig';
|
|
7
7
|
import { useReorderableListCore } from './useReorderableListCore';
|
|
8
8
|
import { ReorderableListContext } from '../../contexts';
|
|
9
9
|
import { ReorderableListCell } from '../ReorderableListCell';
|
|
10
10
|
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
|
|
11
11
|
const ReorderableListCore = ({
|
|
12
|
-
data,
|
|
13
12
|
autoscrollThreshold = 0.1,
|
|
14
13
|
autoscrollSpeedScale = 1,
|
|
15
14
|
autoscrollDelay = AUTOSCROLL_CONFIG.delay,
|
|
@@ -18,17 +17,19 @@ const ReorderableListCore = ({
|
|
|
18
17
|
onLayout,
|
|
19
18
|
onReorder,
|
|
20
19
|
onScroll,
|
|
20
|
+
onDragStart,
|
|
21
21
|
onDragEnd,
|
|
22
|
-
keyExtractor,
|
|
23
|
-
extraData,
|
|
24
22
|
scrollViewContainerRef,
|
|
25
23
|
scrollViewHeightY,
|
|
26
24
|
scrollViewScrollOffsetY,
|
|
27
25
|
scrollViewScrollEnabled,
|
|
28
|
-
scrollEnabled,
|
|
29
26
|
initialScrollViewScrollEnabled,
|
|
30
27
|
scrollable,
|
|
31
28
|
outerScrollGesture,
|
|
29
|
+
cellAnimations,
|
|
30
|
+
shouldUpdateActiveItem,
|
|
31
|
+
panEnabled = true,
|
|
32
|
+
panActivateAfterLongPress,
|
|
32
33
|
...rest
|
|
33
34
|
}, ref) => {
|
|
34
35
|
const {
|
|
@@ -52,7 +53,7 @@ const ReorderableListCore = ({
|
|
|
52
53
|
dragReorderThreshold,
|
|
53
54
|
onLayout,
|
|
54
55
|
onReorder,
|
|
55
|
-
|
|
56
|
+
onDragStart,
|
|
56
57
|
onDragEnd,
|
|
57
58
|
scrollViewContainerRef,
|
|
58
59
|
scrollViewHeightY,
|
|
@@ -60,9 +61,13 @@ const ReorderableListCore = ({
|
|
|
60
61
|
scrollViewScrollEnabled,
|
|
61
62
|
// flatlist will default to true if we pass explicitly undefined,
|
|
62
63
|
// but internally we would treat it as false, so we force true
|
|
63
|
-
initialScrollEnabled: typeof scrollEnabled === 'undefined' ? true : scrollEnabled,
|
|
64
|
+
initialScrollEnabled: typeof rest.scrollEnabled === 'undefined' ? true : rest.scrollEnabled,
|
|
64
65
|
initialScrollViewScrollEnabled: typeof initialScrollViewScrollEnabled === 'undefined' ? true : initialScrollViewScrollEnabled,
|
|
65
|
-
nestedScrollable: scrollable
|
|
66
|
+
nestedScrollable: scrollable,
|
|
67
|
+
cellAnimations,
|
|
68
|
+
shouldUpdateActiveItem,
|
|
69
|
+
panEnabled,
|
|
70
|
+
panActivateAfterLongPress
|
|
66
71
|
});
|
|
67
72
|
const combinedGesture = useMemo(() => {
|
|
68
73
|
// android is able to handle nested scroll view, but not the full height ones like iOS
|
|
@@ -71,6 +76,7 @@ const ReorderableListCore = ({
|
|
|
71
76
|
}
|
|
72
77
|
return gestureHandler;
|
|
73
78
|
}, [scrollable, outerScrollGesture, gestureHandler]);
|
|
79
|
+
const composedScrollHandler = useComposedEventHandler([handleScroll, onScroll || null]);
|
|
74
80
|
const renderAnimatedCell = useCallback(({
|
|
75
81
|
cellKey,
|
|
76
82
|
...props
|
|
@@ -90,17 +96,13 @@ const ReorderableListCore = ({
|
|
|
90
96
|
gesture: combinedGesture
|
|
91
97
|
}, /*#__PURE__*/React.createElement(AnimatedFlatList, _extends({}, rest, {
|
|
92
98
|
ref: handleRef,
|
|
93
|
-
data: data,
|
|
94
99
|
CellRendererComponent: renderAnimatedCell,
|
|
95
100
|
onLayout: handleFlatListLayout,
|
|
96
|
-
onScroll:
|
|
101
|
+
onScroll: composedScrollHandler,
|
|
97
102
|
scrollEventThrottle: 1,
|
|
98
103
|
horizontal: false,
|
|
99
104
|
removeClippedSubviews: false,
|
|
100
|
-
|
|
101
|
-
extraData: extraData,
|
|
102
|
-
numColumns: 1,
|
|
103
|
-
scrollEnabled: scrollEnabled
|
|
105
|
+
numColumns: 1
|
|
104
106
|
}))));
|
|
105
107
|
};
|
|
106
108
|
const MemoizedReorderableListCore = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(ReorderableListCore));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useCallback","useMemo","FlatList","Platform","Gesture","GestureDetector","Animated","AUTOSCROLL_CONFIG","useReorderableListCore","ReorderableListContext","ReorderableListCell","AnimatedFlatList","createAnimatedComponent","ReorderableListCore","
|
|
1
|
+
{"version":3,"names":["React","useCallback","useMemo","FlatList","Platform","Gesture","GestureDetector","Animated","useComposedEventHandler","AUTOSCROLL_CONFIG","useReorderableListCore","ReorderableListContext","ReorderableListCell","AnimatedFlatList","createAnimatedComponent","ReorderableListCore","autoscrollThreshold","autoscrollSpeedScale","autoscrollDelay","delay","animationDuration","dragReorderThreshold","onLayout","onReorder","onScroll","onDragStart","onDragEnd","scrollViewContainerRef","scrollViewHeightY","scrollViewScrollOffsetY","scrollViewScrollEnabled","initialScrollViewScrollEnabled","scrollable","outerScrollGesture","cellAnimations","shouldUpdateActiveItem","panEnabled","panActivateAfterLongPress","rest","ref","gestureHandler","handleScroll","handleFlatListLayout","handleRef","startDrag","listContextValue","itemOffset","itemHeight","dragY","draggedIndex","duration","initialScrollEnabled","scrollEnabled","nestedScrollable","combinedGesture","OS","Simultaneous","composedScrollHandler","renderAnimatedCell","cellKey","props","createElement","_extends","key","index","Provider","value","gesture","CellRendererComponent","scrollEventThrottle","horizontal","removeClippedSubviews","numColumns","MemoizedReorderableListCore","memo","forwardRef"],"sourceRoot":"../../../../src","sources":["components/ReorderableListCore/ReorderableListCore.tsx"],"mappings":";AAAA,OAAOA,KAAK,IAAGC,WAAW,EAAEC,OAAO,QAAO,OAAO;AACjD,SAEEC,QAAQ,EAERC,QAAQ,QAEH,cAAc;AAErB,SACEC,OAAO,EACPC,eAAe,QAEV,8BAA8B;AACrC,OAAOC,QAAQ,IAEbC,uBAAuB,QAClB,yBAAyB;AAEhC,SAAQC,iBAAiB,QAAO,oBAAoB;AACpD,SAAQC,sBAAsB,QAAO,0BAA0B;AAC/D,SAAQC,sBAAsB,QAAO,gBAAgB;AAErD,SAAQC,mBAAmB,QAAO,wBAAwB;AAE1D,MAAMC,gBAAgB,GAAGN,QAAQ,CAACO,uBAAuB,CACvDX,QACF,CAEuB;AAcvB,MAAMY,mBAAmB,GAAGA,CAC1B;EACEC,mBAAmB,GAAG,GAAG;EACzBC,oBAAoB,GAAG,CAAC;EACxBC,eAAe,GAAGT,iBAAiB,CAACU,KAAK;EACzCC,iBAAiB,GAAG,GAAG;EACvBC,oBAAoB,GAAG,GAAG;EAC1BC,QAAQ;EACRC,SAAS;EACTC,QAAQ;EACRC,WAAW;EACXC,SAAS;EACTC,sBAAsB;EACtBC,iBAAiB;EACjBC,uBAAuB;EACvBC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animated';
|
|
2
|
+
const DURATION_START = 150;
|
|
3
|
+
const DURATION_END = 200;
|
|
4
|
+
export const SCALE_ANIMATION_CONFIG_DEFAULT = {
|
|
5
|
+
start: {
|
|
6
|
+
toValue: 1.025,
|
|
7
|
+
easing: Easing.in(Easing.ease),
|
|
8
|
+
duration: DURATION_START
|
|
9
|
+
},
|
|
10
|
+
end: {
|
|
11
|
+
toValue: 1,
|
|
12
|
+
easing: Easing.out(Easing.ease),
|
|
13
|
+
duration: DURATION_END
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export const OPACITY_ANIMATION_CONFIG_DEFAULT = {
|
|
17
|
+
start: {
|
|
18
|
+
toValue: 0.75,
|
|
19
|
+
easing: Easing.in(Easing.ease),
|
|
20
|
+
duration: DURATION_START
|
|
21
|
+
},
|
|
22
|
+
end: {
|
|
23
|
+
toValue: 1,
|
|
24
|
+
easing: Easing.out(Easing.ease),
|
|
25
|
+
duration: DURATION_END
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=animationDefaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Easing","DURATION_START","DURATION_END","SCALE_ANIMATION_CONFIG_DEFAULT","start","toValue","easing","in","ease","duration","end","out","OPACITY_ANIMATION_CONFIG_DEFAULT"],"sourceRoot":"../../../../src","sources":["components/ReorderableListCore/animationDefaults.ts"],"mappings":"AAAA,SAAQA,MAAM,QAAyB,yBAAyB;AAEhE,MAAMC,cAAc,GAAG,GAAG;AAC1B,MAAMC,YAAY,GAAG,GAAG;AAOxB,OAAO,MAAMC,8BAA+C,GAAG;EAC7DC,KAAK,EAAE;IACLC,OAAO,EAAE,KAAK;IACdC,MAAM,EAAEN,MAAM,CAACO,EAAE,CAACP,MAAM,CAACQ,IAAI,CAAC;IAC9BC,QAAQ,EAAER;EACZ,CAAC;EACDS,GAAG,EAAE;IACHL,OAAO,EAAE,CAAC;IACVC,MAAM,EAAEN,MAAM,CAACW,GAAG,CAACX,MAAM,CAACQ,IAAI,CAAC;IAC/BC,QAAQ,EAAEP;EACZ;AACF,CAAC;AAED,OAAO,MAAMU,gCAAiD,GAAG;EAC/DR,KAAK,EAAE;IACLC,OAAO,EAAE,IAAI;IACbC,MAAM,EAAEN,MAAM,CAACO,EAAE,CAACP,MAAM,CAACQ,IAAI,CAAC;IAC9BC,QAAQ,EAAER;EACZ,CAAC;EACDS,GAAG,EAAE;IACHL,OAAO,EAAE,CAAC;IACVC,MAAM,EAAEN,MAAM,CAACW,GAAG,CAACX,MAAM,CAACQ,IAAI,CAAC;IAC/BC,QAAQ,EAAEP;EACZ;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Platform","IOS_CONFIG","delay","increment","ANDROID_FABRIC_CONFIG","ANDROID_PAPER_CONFIG","IS_FABRIC","global","AUTOSCROLL_CONFIG","select","android","ios","web","macos","windows","native"],"sourceRoot":"../../../../src","sources":["components/ReorderableListCore/autoscrollConfig.ts"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,cAAc;AAErC,MAAMC,UAAU,GAAG;EACjBC,KAAK,EAAE,EAAE;EACTC,SAAS,EAAE;AACb,CAAC;AAED,MAAMC,qBAAqB,GAAG;EAC5BF,KAAK,EAAE,EAAE;EACTC,SAAS,EAAE;AACb,CAAC;AAED,MAAME,oBAAoB,GAAG;EAC3BH,KAAK,EAAE,EAAE;EACTC,SAAS,EAAE;AACb,CAAC;AAED,OAAO,MAAMG,SAAS,GACpBC,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAI,uBAAuB,IAAIA,MAAM;AAE3E,OAAO,MAAMC,iBAAiB,GAAGR,QAAQ,CAACS,MAAM,CAAC;EAC/C;EACAC,OAAO,EAAEJ,SAAS,GAAGF,qBAAqB,GAAGC,oBAAoB;EACjEM,GAAG,EAAEV,UAAU;EAEf;EACAW,GAAG,EAAEX,UAAU;EACfY,KAAK,EAAEZ,UAAU;EACjBa,OAAO,EAAEb,UAAU;EACnBc,MAAM,EAAEd;AACV,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useMemo } from 'react';
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { unstable_batchedUpdates } from 'react-native';
|
|
3
3
|
import { Gesture, State } from 'react-native-gesture-handler';
|
|
4
4
|
import { Easing, runOnJS, runOnUI, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedScrollHandler, useSharedValue, withDelay, withTiming } from 'react-native-reanimated';
|
|
5
|
-
import {
|
|
5
|
+
import { OPACITY_ANIMATION_CONFIG_DEFAULT, SCALE_ANIMATION_CONFIG_DEFAULT } from './animationDefaults';
|
|
6
|
+
import { AUTOSCROLL_CONFIG } from './autoscrollConfig';
|
|
6
7
|
import { ReorderableListState } from '../../types';
|
|
7
8
|
const version = React.version.split('.');
|
|
8
9
|
const hasAutomaticBatching = version.length ? parseInt(version[0], 10) >= 18 : false;
|
|
@@ -14,8 +15,8 @@ export const useReorderableListCore = ({
|
|
|
14
15
|
animationDuration,
|
|
15
16
|
dragReorderThreshold,
|
|
16
17
|
onReorder,
|
|
18
|
+
onDragStart,
|
|
17
19
|
onDragEnd,
|
|
18
|
-
onScroll,
|
|
19
20
|
onLayout,
|
|
20
21
|
scrollViewContainerRef,
|
|
21
22
|
scrollViewHeightY,
|
|
@@ -23,9 +24,14 @@ export const useReorderableListCore = ({
|
|
|
23
24
|
scrollViewScrollEnabled,
|
|
24
25
|
initialScrollEnabled,
|
|
25
26
|
initialScrollViewScrollEnabled,
|
|
26
|
-
nestedScrollable
|
|
27
|
+
nestedScrollable,
|
|
28
|
+
cellAnimations,
|
|
29
|
+
shouldUpdateActiveItem,
|
|
30
|
+
panActivateAfterLongPress,
|
|
31
|
+
panEnabled
|
|
27
32
|
}) => {
|
|
28
33
|
const flatListRef = useAnimatedRef();
|
|
34
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
29
35
|
const scrollEnabled = useSharedValue(initialScrollEnabled);
|
|
30
36
|
const gestureState = useSharedValue(State.UNDETERMINED);
|
|
31
37
|
const currentY = useSharedValue(0);
|
|
@@ -52,6 +58,12 @@ export const useReorderableListCore = ({
|
|
|
52
58
|
const dragEndHandlers = useSharedValue([]);
|
|
53
59
|
const startY = useSharedValue(0);
|
|
54
60
|
const duration = useSharedValue(animationDuration);
|
|
61
|
+
const scaleDefault = useSharedValue(1);
|
|
62
|
+
const opacityDefault = useSharedValue(1);
|
|
63
|
+
const {
|
|
64
|
+
scale,
|
|
65
|
+
opacity
|
|
66
|
+
} = cellAnimations || {};
|
|
55
67
|
useEffect(() => {
|
|
56
68
|
duration.value = animationDuration;
|
|
57
69
|
}, [duration, animationDuration]);
|
|
@@ -59,30 +71,38 @@ export const useReorderableListCore = ({
|
|
|
59
71
|
draggedHeight,
|
|
60
72
|
currentIndex,
|
|
61
73
|
draggedIndex,
|
|
62
|
-
dragEndHandlers
|
|
63
|
-
|
|
74
|
+
dragEndHandlers,
|
|
75
|
+
activeIndex,
|
|
76
|
+
scale: scale || scaleDefault,
|
|
77
|
+
opacity: opacity || opacityDefault
|
|
78
|
+
}), [draggedHeight, currentIndex, draggedIndex, dragEndHandlers, activeIndex, scale, scaleDefault, opacity, opacityDefault]);
|
|
64
79
|
const panGestureHandler = useMemo(() => Gesture.Pan().onBegin(e => {
|
|
65
80
|
// prevent new dragging until item is completely released
|
|
66
81
|
if (state.value === ReorderableListState.IDLE) {
|
|
67
82
|
startY.value = e.y;
|
|
68
83
|
currentY.value = e.y;
|
|
69
84
|
currentTranslationY.value = e.translationY;
|
|
70
|
-
|
|
71
|
-
dragY.value = e.translationY;
|
|
72
|
-
}
|
|
85
|
+
dragY.value = e.translationY;
|
|
73
86
|
gestureState.value = e.state;
|
|
74
87
|
}
|
|
75
88
|
}).onUpdate(e => {
|
|
76
|
-
if (state.value !== ReorderableListState.
|
|
89
|
+
if (state.value !== ReorderableListState.RELEASED) {
|
|
77
90
|
currentY.value = startY.value + e.translationY;
|
|
78
91
|
currentTranslationY.value = e.translationY;
|
|
79
|
-
|
|
80
|
-
dragY.value = e.translationY + dragScrollTranslationY.value + scrollViewDragScrollTranslationY.value;
|
|
81
|
-
}
|
|
92
|
+
dragY.value = e.translationY + dragScrollTranslationY.value + scrollViewDragScrollTranslationY.value;
|
|
82
93
|
gestureState.value = e.state;
|
|
83
94
|
}
|
|
84
|
-
}).onEnd(e => gestureState.value = e.state).onFinalize(e => gestureState.value = e.state), [currentTranslationY, currentY, dragScrollTranslationY, scrollViewDragScrollTranslationY,
|
|
85
|
-
const
|
|
95
|
+
}).onEnd(e => gestureState.value = e.state).onFinalize(e => gestureState.value = e.state), [currentTranslationY, currentY, dragScrollTranslationY, scrollViewDragScrollTranslationY, gestureState, dragY, startY, state]);
|
|
96
|
+
const panGestureHandlerWithOptions = useMemo(() => {
|
|
97
|
+
if (typeof panActivateAfterLongPress === 'number') {
|
|
98
|
+
panGestureHandler.activateAfterLongPress(panActivateAfterLongPress);
|
|
99
|
+
}
|
|
100
|
+
if (!panEnabled) {
|
|
101
|
+
panGestureHandler.enabled(panEnabled);
|
|
102
|
+
}
|
|
103
|
+
return panGestureHandler;
|
|
104
|
+
}, [panActivateAfterLongPress, panEnabled, panGestureHandler]);
|
|
105
|
+
const gestureHandler = useMemo(() => Gesture.Simultaneous(Gesture.Native(), panGestureHandlerWithOptions), [panGestureHandlerWithOptions]);
|
|
86
106
|
const setScrollEnabled = useCallback(enabled => {
|
|
87
107
|
// if scroll is enabled on list props then we can toggle it
|
|
88
108
|
if (initialScrollEnabled) {
|
|
@@ -103,14 +123,15 @@ export const useReorderableListCore = ({
|
|
|
103
123
|
const resetSharedValues = useCallback(() => {
|
|
104
124
|
'worklet';
|
|
105
125
|
|
|
106
|
-
// current index is reset on item render for the on end event
|
|
107
|
-
draggedIndex.value = -1;
|
|
108
|
-
// released flag is reset after release is triggered in the item
|
|
109
126
|
state.value = ReorderableListState.IDLE;
|
|
127
|
+
draggedIndex.value = -1;
|
|
110
128
|
dragY.value = 0;
|
|
111
129
|
dragScrollTranslationY.value = 0;
|
|
112
130
|
scrollViewDragScrollTranslationY.value = 0;
|
|
113
|
-
}, [dragY, dragScrollTranslationY, scrollViewDragScrollTranslationY,
|
|
131
|
+
}, [draggedIndex, dragY, dragScrollTranslationY, scrollViewDragScrollTranslationY, state]);
|
|
132
|
+
const resetSharedValuesAfterAnimations = useCallback(() => {
|
|
133
|
+
setTimeout(runOnUI(resetSharedValues), duration.value);
|
|
134
|
+
}, [resetSharedValues, duration]);
|
|
114
135
|
const reorder = (fromIndex, toIndex) => {
|
|
115
136
|
runOnUI(resetSharedValues)();
|
|
116
137
|
if (fromIndex !== toIndex) {
|
|
@@ -180,12 +201,31 @@ export const useReorderableListCore = ({
|
|
|
180
201
|
currentIndex.value = newIndex;
|
|
181
202
|
}
|
|
182
203
|
}, [currentIndex, previousIndex, previousDirection, previousY, itemOffset, itemHeight, getIndexFromY]);
|
|
204
|
+
const runDefaultDragAnimations = useCallback(type => {
|
|
205
|
+
'worklet';
|
|
206
|
+
|
|
207
|
+
// if animation is not disabled and not custom run the default
|
|
208
|
+
if (scale !== false && !scale) {
|
|
209
|
+
const scaleConfig = SCALE_ANIMATION_CONFIG_DEFAULT[type];
|
|
210
|
+
scaleDefault.value = withTiming(scaleConfig.toValue, scaleConfig);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// if animation is not disabled and not custom run the default
|
|
214
|
+
if (opacity !== false && !opacity) {
|
|
215
|
+
const opacityConfig = OPACITY_ANIMATION_CONFIG_DEFAULT[type];
|
|
216
|
+
opacityDefault.value = withTiming(opacityConfig.toValue, opacityConfig);
|
|
217
|
+
}
|
|
218
|
+
}, [scale, scaleDefault, opacity, opacityDefault]);
|
|
183
219
|
useAnimatedReaction(() => gestureState.value, () => {
|
|
184
|
-
if (gestureState.value !== State.ACTIVE && gestureState.value !== State.BEGAN && (state.value === ReorderableListState.
|
|
185
|
-
state.value = ReorderableListState.
|
|
220
|
+
if (gestureState.value !== State.ACTIVE && gestureState.value !== State.BEGAN && (state.value === ReorderableListState.DRAGGED || state.value === ReorderableListState.AUTOSCROLL)) {
|
|
221
|
+
state.value = ReorderableListState.RELEASED;
|
|
186
222
|
|
|
187
223
|
// enable back scroll on releasing
|
|
188
224
|
runOnJS(setScrollEnabled)(true);
|
|
225
|
+
if (shouldUpdateActiveItem) {
|
|
226
|
+
runOnJS(setActiveIndex)(-1);
|
|
227
|
+
}
|
|
228
|
+
|
|
189
229
|
// trigger onDragEnd event
|
|
190
230
|
let e = {
|
|
191
231
|
from: draggedIndex.value,
|
|
@@ -203,6 +243,7 @@ export const useReorderableListCore = ({
|
|
|
203
243
|
const draggedItemOffset = itemOffset.value[currentIndex.value];
|
|
204
244
|
const draggedItemHeight = itemHeight.value[currentIndex.value];
|
|
205
245
|
const newTopPosition = currentIndex.value > draggedIndex.value ? draggedItemOffset - currentItemOffset : draggedItemOffset - currentItemOffset + (draggedItemHeight - currentItemHeight);
|
|
246
|
+
runDefaultDragAnimations('end');
|
|
206
247
|
if (dragY.value !== newTopPosition) {
|
|
207
248
|
// animate dragged item to its new position on release
|
|
208
249
|
dragY.value = withTiming(newTopPosition, {
|
|
@@ -215,7 +256,7 @@ export const useReorderableListCore = ({
|
|
|
215
256
|
// user might drag and release the item without moving it so,
|
|
216
257
|
// since the animation end callback is not executed in that case
|
|
217
258
|
// we need to reset values as the reorder function would do
|
|
218
|
-
|
|
259
|
+
runOnJS(resetSharedValuesAfterAnimations)();
|
|
219
260
|
}
|
|
220
261
|
}
|
|
221
262
|
});
|
|
@@ -297,22 +338,22 @@ export const useReorderableListCore = ({
|
|
|
297
338
|
return 0;
|
|
298
339
|
}, [nestedScrollable, shouldScrollParent, calculateHiddenArea, calculateThresholdArea, calculateThresholdAreaParent]);
|
|
299
340
|
useAnimatedReaction(() => currentY.value + scrollViewDragScrollTranslationY.value, y => {
|
|
300
|
-
if (state.value === ReorderableListState.
|
|
341
|
+
if (state.value === ReorderableListState.DRAGGED || state.value === ReorderableListState.AUTOSCROLL) {
|
|
301
342
|
setCurrentIndex(y);
|
|
302
343
|
if (scrollDirection(y) !== 0) {
|
|
303
|
-
if (state.value !== ReorderableListState.
|
|
344
|
+
if (state.value !== ReorderableListState.AUTOSCROLL) {
|
|
304
345
|
// trigger autoscroll
|
|
305
346
|
lastAutoscrollTrigger.value = autoscrollTrigger.value;
|
|
306
347
|
autoscrollTrigger.value *= -1;
|
|
307
|
-
state.value = ReorderableListState.
|
|
348
|
+
state.value = ReorderableListState.AUTOSCROLL;
|
|
308
349
|
}
|
|
309
|
-
} else if (state.value === ReorderableListState.
|
|
310
|
-
state.value = ReorderableListState.
|
|
350
|
+
} else if (state.value === ReorderableListState.AUTOSCROLL) {
|
|
351
|
+
state.value = ReorderableListState.DRAGGED;
|
|
311
352
|
}
|
|
312
353
|
}
|
|
313
354
|
});
|
|
314
355
|
useAnimatedReaction(() => autoscrollTrigger.value, () => {
|
|
315
|
-
if (autoscrollTrigger.value !== lastAutoscrollTrigger.value && state.value === ReorderableListState.
|
|
356
|
+
if (autoscrollTrigger.value !== lastAutoscrollTrigger.value && state.value === ReorderableListState.AUTOSCROLL) {
|
|
316
357
|
let y = currentY.value + scrollViewDragScrollTranslationY.value;
|
|
317
358
|
const autoscrollIncrement = scrollDirection(y) * AUTOSCROLL_CONFIG.increment * autoscrollSpeedScale;
|
|
318
359
|
if (autoscrollIncrement !== 0) {
|
|
@@ -341,14 +382,13 @@ export const useReorderableListCore = ({
|
|
|
341
382
|
if (!scrollEnabled.value) {
|
|
342
383
|
dragScrollTranslationY.value = flatListScrollOffsetY.value - dragInitialScrollOffsetY.value;
|
|
343
384
|
}
|
|
344
|
-
if (state.value === ReorderableListState.
|
|
385
|
+
if (state.value === ReorderableListState.AUTOSCROLL) {
|
|
345
386
|
dragY.value = currentTranslationY.value + dragScrollTranslationY.value + scrollViewDragScrollTranslationY.value;
|
|
346
387
|
lastAutoscrollTrigger.value = autoscrollTrigger.value;
|
|
347
388
|
autoscrollTrigger.value = withDelay(autoscrollDelay, withTiming(autoscrollTrigger.value * -1, {
|
|
348
389
|
duration: 0
|
|
349
390
|
}));
|
|
350
391
|
}
|
|
351
|
-
onScroll === null || onScroll === void 0 || onScroll(e);
|
|
352
392
|
});
|
|
353
393
|
|
|
354
394
|
// parent scroll handler
|
|
@@ -360,7 +400,7 @@ export const useReorderableListCore = ({
|
|
|
360
400
|
if (!scrollViewScrollEnabled.value) {
|
|
361
401
|
scrollViewDragScrollTranslationY.value = value - scrollViewDragInitialScrollOffsetY.value;
|
|
362
402
|
}
|
|
363
|
-
if (state.value === ReorderableListState.
|
|
403
|
+
if (state.value === ReorderableListState.AUTOSCROLL) {
|
|
364
404
|
dragY.value = currentTranslationY.value + scrollViewDragScrollTranslationY.value;
|
|
365
405
|
lastAutoscrollTrigger.value = autoscrollTrigger.value;
|
|
366
406
|
autoscrollTrigger.value = withDelay(autoscrollDelay, withTiming(autoscrollTrigger.value * -1, {
|
|
@@ -377,16 +417,25 @@ export const useReorderableListCore = ({
|
|
|
377
417
|
// resetting shared values again fixes a flickeing bug in nested lists where
|
|
378
418
|
// after scrolling the parent list it would offset the new dragged item in another nested list
|
|
379
419
|
resetSharedValues();
|
|
420
|
+
if (shouldUpdateActiveItem) {
|
|
421
|
+
runOnJS(setActiveIndex)(index);
|
|
422
|
+
}
|
|
380
423
|
dragInitialScrollOffsetY.value = flatListScrollOffsetY.value;
|
|
381
424
|
scrollViewDragInitialScrollOffsetY.value = scrollViewScrollOffsetY ? scrollViewScrollOffsetY.value : 0;
|
|
382
425
|
draggedHeight.value = itemHeight.value[index];
|
|
383
426
|
draggedIndex.value = index;
|
|
384
427
|
previousIndex.value = -1;
|
|
385
428
|
currentIndex.value = index;
|
|
386
|
-
state.value = ReorderableListState.
|
|
429
|
+
state.value = ReorderableListState.DRAGGED;
|
|
387
430
|
runOnJS(setScrollEnabled)(false);
|
|
431
|
+
|
|
432
|
+
// run animation before onDragStart to avoid potentially waiting for it
|
|
433
|
+
runDefaultDragAnimations('start');
|
|
434
|
+
onDragStart === null || onDragStart === void 0 || onDragStart({
|
|
435
|
+
index
|
|
436
|
+
});
|
|
388
437
|
}
|
|
389
|
-
}, [resetSharedValues, dragInitialScrollOffsetY, scrollViewScrollOffsetY, scrollViewDragInitialScrollOffsetY, setScrollEnabled, currentIndex, previousIndex, draggedHeight, draggedIndex, state, flatListScrollOffsetY, itemHeight]);
|
|
438
|
+
}, [resetSharedValues, shouldUpdateActiveItem, dragInitialScrollOffsetY, scrollViewScrollOffsetY, scrollViewDragInitialScrollOffsetY, setScrollEnabled, currentIndex, previousIndex, draggedHeight, draggedIndex, state, flatListScrollOffsetY, itemHeight, onDragStart, runDefaultDragAnimations]);
|
|
390
439
|
const handleFlatListLayout = useCallback(e => {
|
|
391
440
|
nestedFlatListPositionY.value = e.nativeEvent.layout.y;
|
|
392
441
|
flatListHeightY.value = e.nativeEvent.layout.height;
|