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
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-

|
|
2
|
-

|
|
3
|
-

|
|
1
|
+
[](https://www.npmjs.com/package/react-native-reorderable-list)
|
|
2
|
+
[](https://github.com/omahili/react-native-reorderable-list?tab=MIT-1-ov-file#readme)
|
|
3
|
+
[](https://www.npmjs.com/package/react-native-reorderable-list?activeTab=versions)
|
|
4
4
|
<br />
|
|
5
5
|

|
|
6
6
|

|
|
@@ -17,19 +17,23 @@ A reorderable list for React Native applications, powered by Reanimated 🚀
|
|
|
17
17
|
- [Install](#install)
|
|
18
18
|
- [Components](#components)
|
|
19
19
|
- [ReorderableList](#reorderablelist)
|
|
20
|
-
- [ReorderableListItem](#reorderablelistitem)
|
|
21
20
|
- [ScrollViewContainer](#scrollviewcontainer)
|
|
22
21
|
- [NestedReorderableList](#nestedreorderablelist)
|
|
23
22
|
- [Hooks](#hooks)
|
|
24
23
|
- [useReorderableDrag](#usereorderabledrag)
|
|
25
24
|
- [useReorderableDragStart](#usereorderabledragstart)
|
|
26
25
|
- [useReorderableDragEnd](#usereorderabledragend)
|
|
26
|
+
- [useIsActive](#useisactive)
|
|
27
27
|
- [Utils](#utils)
|
|
28
|
+
- [Troubleshooting](#troubleshooting)
|
|
29
|
+
- [RefreshControl](#refreshcontrol)
|
|
28
30
|
- [Example](#example)
|
|
29
31
|
- [License](#license)
|
|
30
32
|
|
|
31
33
|
## Install
|
|
32
34
|
|
|
35
|
+
> **NOTE**: This package follows [semantic versioning](https://semver.org/). Versions 0.X.0 are safe to use but may introduce breaking changes, as the public API is not considered stable yet.
|
|
36
|
+
|
|
33
37
|
Npm:
|
|
34
38
|
|
|
35
39
|
```bash
|
|
@@ -44,8 +48,8 @@ yarn add react-native-reorderable-list
|
|
|
44
48
|
|
|
45
49
|
Then you need to install these two peer dependencies:
|
|
46
50
|
|
|
47
|
-
- [React Native Reanimated](https://docs.swmansion.com/react-native-reanimated) >=3.
|
|
48
|
-
- [React Native Gesture Handler](https://docs.swmansion.com/react-native-gesture-handler) >=2.
|
|
51
|
+
- [React Native Reanimated](https://docs.swmansion.com/react-native-reanimated) >=3.12.0
|
|
52
|
+
- [React Native Gesture Handler](https://docs.swmansion.com/react-native-gesture-handler) >=2.12.0
|
|
49
53
|
|
|
50
54
|
## Components
|
|
51
55
|
|
|
@@ -53,16 +57,21 @@ Then you need to install these two peer dependencies:
|
|
|
53
57
|
|
|
54
58
|
This component uses a [FlatList](https://reactnative.dev/docs/flatlist) and it extends its props:
|
|
55
59
|
|
|
56
|
-
| Props
|
|
57
|
-
|
|
|
58
|
-
| autoscrollThreshold
|
|
59
|
-
| autoscrollSpeedScale
|
|
60
|
-
| autoscrollDelay
|
|
61
|
-
| dragReorderThreshold
|
|
62
|
-
| animationDuration
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
60
|
+
| Props | Type | Required | Default | Description |
|
|
61
|
+
| ------------------------- | -------------------------------------------------------------------------------- | -------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
62
|
+
| autoscrollThreshold | `number` | No | `0.1` | Threshold at the extremity of the list that triggers autoscroll when an item is dragged to it. A value of `0.1` means that 10% of the area at the top and 10% at the bottom will trigger autoscroll. Min value: `0`. Max value: `0.4`. |
|
|
63
|
+
| autoscrollSpeedScale | `number` | No | `1` | Scales the autoscroll speed at which the list scrolls when an item is dragged to the scroll areas. |
|
|
64
|
+
| autoscrollDelay | `number` | No | `0` (Android), `100` (iOS) | Delay in between autoscroll triggers. Can be used to tune the autoscroll smoothness. Default values differ between platforms: `0` for Android and `100` for iOS. |
|
|
65
|
+
| dragReorderThreshold | `number` | No | `0.2` | Specifies the fraction of an item's size at which it will shift when a dragged item crosses over it. For example, `0.2` means the item shifts when the dragged item passes 20% of its height (in a vertical list). |
|
|
66
|
+
| animationDuration | `number` | No | `200` | Duration of the animations in milliseconds. Users won't be able to drag a new item until the dragged item is released and its animation to its new position ends. |
|
|
67
|
+
| cellAnimations | `{ scale: SharedValue<number> \| false, opacity: SharedValue<number> \| false }` | No | N/A | Allows passing an object with shared values that can animate a cell by using the `onDragStart` and `onDragEnd` events. Set the property in the object to false to disable the animation. Check the [examples](https://github.com/omahili/react-native-reorderable-list/tree/master/example) for more details. |
|
|
68
|
+
| shouldUpdateActiveItem | boolean | No | `false` | Whether the active item should be updated. Enables usage of `useIsActive` hook. |
|
|
69
|
+
| panEnabled | `boolean` | No | `true` | Wether the pan gestures necessary for dragging are enabled. |
|
|
70
|
+
| panActivateAfterLongPress | `number` | No | N/A | Duration in milliseconds a the long press on the list before pan gestures, necessary for dragging, are allowed to activate. |
|
|
71
|
+
| onReorder | `(event: { from: number, to: number }) => void` | Yes | N/A | Event fired after an item is released and the list is reordered. |
|
|
72
|
+
| onDragStart | `(event: { index: number }) => void` | No | N/A | Event fired when an item is dragged. Needs to be a `worklet`. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info. |
|
|
73
|
+
| onDragEnd | `(event: { from: number, to: number }) => void` | No | N/A | Event fired when the dragged item is released. Needs to be a `worklet`. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info. |
|
|
74
|
+
| onScroll | `ReturnType<typeof useAnimatedScrollHandler>` | No | N/A | An animated scroll handler created with useAnimatedScrollHandler. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info. |
|
|
66
75
|
|
|
67
76
|
The following props from FlatList are not supported:
|
|
68
77
|
|
|
@@ -72,22 +81,13 @@ The following props from FlatList are not supported:
|
|
|
72
81
|
- CellRendererComponent
|
|
73
82
|
- numColumns
|
|
74
83
|
|
|
75
|
-
### ReorderableListItem
|
|
76
|
-
|
|
77
|
-
This component allows you to animate the item when it's dragged. It currently supports two animations: `scale` and `opacity`. Using this component is optional.
|
|
78
|
-
|
|
79
|
-
| Props | Type | Required | Default | Description |
|
|
80
|
-
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
|
|
81
|
-
| scaleAnimationConfig | `{ enabled?: boolean, valueEnd?: number, valueStart?: number, easingEnd?: EasingFunction, easingStart?: EasingFunction, duration?: number }` | false | `{ enabled: true, valueEnd: 1, valueStart: 1.025, easingStart: Easing.in(Easing.ease), easingEnd: Easing.out(Easing.ease), duration: 200 }` | Configures the scale animation of the reorderable item. |
|
|
82
|
-
| opacityAnimationConfig | `{ enabled?: boolean, valueEnd?: number, valueStart?: number, easingEnd?: EasingFunction, easingStart?: EasingFunction, duration?: number }` | false | `{ enabled: true, valueEnd: 1, valueStart: 0.75, easingStart: Easing.in(Easing.ease), easingEnd: Easing.out(Easing.ease), duration: 200, }` | Configures the opacity animation of the reorderable item. |
|
|
83
|
-
|
|
84
84
|
### ScrollViewContainer
|
|
85
85
|
|
|
86
86
|
This component extends the [ScrollView](https://reactnative.dev/docs/scrollview) component and is used for nesting a [NestedReorderableList](#nestedreorderablelist) within a scrollable container:
|
|
87
87
|
|
|
88
|
-
| Props | Type
|
|
89
|
-
| -------- |
|
|
90
|
-
| onScroll | `
|
|
88
|
+
| Props | Type | Required | Default | Description |
|
|
89
|
+
| -------- | --------------------------------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
90
|
+
| onScroll | `ReturnType<typeof useAnimatedScrollHandler>` | No | N/A | An animated scroll handler created with useAnimatedScrollHandler. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info. |
|
|
91
91
|
|
|
92
92
|
### NestedReorderableList
|
|
93
93
|
|
|
@@ -109,19 +109,52 @@ This hook creates a function that triggers the drag of a list item. It's usually
|
|
|
109
109
|
|
|
110
110
|
### useReorderableDragStart
|
|
111
111
|
|
|
112
|
-
This hook allows handling the drag start event of a list item. It receives a worklet callback that is called when the drag starts. It's recommended to wrap the handler function in a useCallback as follows:
|
|
112
|
+
This hook allows handling the drag start event of a list item. This hook can only be used inside of a list item component. It receives a worklet callback that is called when the drag starts. It's recommended to wrap the handler function in a useCallback as follows:
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
```typescript
|
|
115
|
+
useReorderableDragStart(
|
|
116
|
+
useCallback((index: number) => {
|
|
117
|
+
'worklet';
|
|
115
118
|
|
|
116
|
-
|
|
119
|
+
// ...
|
|
120
|
+
}, []),
|
|
121
|
+
);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Using this hook in large lists is discouraged due to performance bottlenecks, prefer `onDragStart` on the ReorderableList instead.
|
|
117
125
|
|
|
118
126
|
### useReorderableDragEnd
|
|
119
127
|
|
|
120
|
-
This hook allows handling the drag end event of a list item. It receives a worklet callback that is called when the drag
|
|
128
|
+
This hook allows handling the drag end event of a list item. This hook can only be used inside of a list item component. It receives a worklet callback that is called when the drag starts. It's recommended to wrap the handler function in a useCallback as follows:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
useReorderableDragEnd(
|
|
132
|
+
useCallback((from: number, to: number) => {
|
|
133
|
+
'worklet';
|
|
134
|
+
|
|
135
|
+
// ...
|
|
136
|
+
}, []),
|
|
137
|
+
);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Using this hook in large lists is discouraged due to performance bottlenecks, prefer `onDragEnd` on the ReorderableList instead.
|
|
121
141
|
|
|
122
|
-
|
|
142
|
+
### useIsActive
|
|
123
143
|
|
|
124
|
-
|
|
144
|
+
This hook returns a boolean indicating whether the current item is active. It will return true on drag start and false on drag end. This hook can only be used inside of a list item component.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const isActive = useIsActive();
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Additionally this hook requires setting `shouldUpdateActiveItem` to true on the ReorderableList:
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
<ReorderableList
|
|
154
|
+
// ...
|
|
155
|
+
shouldUpdateActiveItem
|
|
156
|
+
/>
|
|
157
|
+
```
|
|
125
158
|
|
|
126
159
|
## Utils
|
|
127
160
|
|
|
@@ -129,15 +162,69 @@ This hook allows handling the drag end event of a list item. It receives a workl
|
|
|
129
162
|
|
|
130
163
|
This function receives an array of items, the index of the item to be moved, and the index of the new position and it returns a new array with the items reordered.
|
|
131
164
|
|
|
165
|
+
## Troubleshooting
|
|
166
|
+
|
|
167
|
+
### RefreshControl
|
|
168
|
+
|
|
169
|
+
If you want to use RefreshControl with ReorderableList you might encounter some issues on Android, where gestures are conflicting making one or both of the components non responsive. To overcome this issues you can delay the activation of pan gestures necessary for dragging items by using the `panActivateAfterLongPress` prop. This duration should be slightly longer than the long press delay necessary to drag your items. If you're using Pressable the `delayLongPress` is 500 ms by default.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
<ReorderableList
|
|
173
|
+
// ...
|
|
174
|
+
panActivateAfterLongPress={Platform.OS === 'android' ? 520 : undefined}
|
|
175
|
+
/>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
If you change `delayLongPress` on your Pressable, update this prop accordingly.
|
|
179
|
+
|
|
180
|
+
Another issue you'll encounter is that when you drag your items the RefreshControl might animate. To avoid this you can enable and disable it on drag start and drag end like so:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const [refreshEnabled, setRefreshEnabled] = useState(true);
|
|
184
|
+
|
|
185
|
+
const handleDragStart = useCallback(() => {
|
|
186
|
+
'worklet';
|
|
187
|
+
|
|
188
|
+
// NOTE: if it's refreshing we don't want the refresh control to disappear
|
|
189
|
+
// and we can keep it enabled since it won't conflict with the drag
|
|
190
|
+
if (Platform.OS === 'android' && !refreshing) {
|
|
191
|
+
runOnJS(setRefreshEnabled)(false);
|
|
192
|
+
}
|
|
193
|
+
}, [refreshing]);
|
|
194
|
+
|
|
195
|
+
const handleDragEnd = useCallback(() => {
|
|
196
|
+
'worklet';
|
|
197
|
+
|
|
198
|
+
// NOTE: if it's refreshing we don't want the refresh control to disappear
|
|
199
|
+
// and we can keep it enabled since it won't conflict with the drag
|
|
200
|
+
if (Platform.OS === 'android' && !refreshing) {
|
|
201
|
+
runOnJS(setRefreshEnabled)(true);
|
|
202
|
+
}
|
|
203
|
+
}, [refreshing]);
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<ReorderableList
|
|
207
|
+
// ...
|
|
208
|
+
onDragStart={handleDragStart}
|
|
209
|
+
onDragEnd={handleDragEnd}
|
|
210
|
+
refreshControl={
|
|
211
|
+
<RefreshControl
|
|
212
|
+
// ...
|
|
213
|
+
enabled={refreshEnabled}
|
|
214
|
+
/>
|
|
215
|
+
}
|
|
216
|
+
/>
|
|
217
|
+
);
|
|
218
|
+
```
|
|
219
|
+
|
|
132
220
|
## Example
|
|
133
221
|
|
|
134
222
|
Here is simple example of how to use this component. Examples of nested lists and much more can be found in the [example](https://github.com/omahili/react-native-reorderable-list/tree/feat/nested-lists/example) directory.
|
|
135
223
|
|
|
136
224
|
```typescript
|
|
137
|
-
import React, {useState} from 'react';
|
|
225
|
+
import React, {memo, useState} from 'react';
|
|
138
226
|
import {ListRenderItemInfo, Pressable, StyleSheet, Text} from 'react-native';
|
|
139
227
|
import ReorderableList, {
|
|
140
|
-
ReorderableListItem,
|
|
141
228
|
ReorderableListReorderEvent,
|
|
142
229
|
reorderItems,
|
|
143
230
|
useReorderableDrag,
|
|
@@ -162,30 +249,27 @@ const list: CardProps[] = [
|
|
|
162
249
|
{id: '9', color: 'seagreen', height: 90},
|
|
163
250
|
];
|
|
164
251
|
|
|
165
|
-
const Card: React.FC<CardProps> =
|
|
252
|
+
const Card: React.FC<CardProps> = memo(({id, color, height}) => {
|
|
166
253
|
const drag = useReorderableDrag();
|
|
167
254
|
|
|
168
255
|
return (
|
|
169
|
-
<
|
|
170
|
-
<
|
|
171
|
-
|
|
172
|
-
</Pressable>
|
|
173
|
-
</ReorderableListItem>
|
|
256
|
+
<Pressable style={[styles.card, {height}]} onLongPress={drag}>
|
|
257
|
+
<Text style={[styles.text, {color}]}>Card {id}</Text>
|
|
258
|
+
</Pressable>
|
|
174
259
|
);
|
|
175
260
|
});
|
|
176
261
|
|
|
177
262
|
const Example = () => {
|
|
178
263
|
const [data, setData] = useState(list);
|
|
179
264
|
|
|
265
|
+
const handleReorder = ({from, to}: ReorderableListReorderEvent) => {
|
|
266
|
+
setData(value => reorderItems(value, from, to));
|
|
267
|
+
};
|
|
268
|
+
|
|
180
269
|
const renderItem = ({item}: ListRenderItemInfo<CardProps>) => (
|
|
181
270
|
<Card {...item} />
|
|
182
271
|
);
|
|
183
272
|
|
|
184
|
-
const handleReorder = ({from, to}: ReorderableListReorderEvent) => {
|
|
185
|
-
const newData = reorderItems(data, from, to);
|
|
186
|
-
setData(newData);
|
|
187
|
-
};
|
|
188
|
-
|
|
189
273
|
return (
|
|
190
274
|
<ReorderableList
|
|
191
275
|
data={data}
|
|
@@ -12,18 +12,16 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
|
|
|
12
12
|
const ReorderableListWithRef = ({
|
|
13
13
|
scrollEnabled = true,
|
|
14
14
|
...rest
|
|
15
|
-
}, ref) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}));
|
|
27
|
-
};
|
|
15
|
+
}, ref) => /*#__PURE__*/_react.default.createElement(_ReorderableListCore.ReorderableListCore, _extends({}, rest, {
|
|
16
|
+
ref: ref,
|
|
17
|
+
scrollEnabled: scrollEnabled,
|
|
18
|
+
initialScrollViewScrollEnabled: true,
|
|
19
|
+
scrollable: true,
|
|
20
|
+
scrollViewContainerRef: undefined,
|
|
21
|
+
scrollViewScrollOffsetY: undefined,
|
|
22
|
+
scrollViewHeightY: undefined,
|
|
23
|
+
outerScrollGesture: undefined,
|
|
24
|
+
scrollViewScrollEnabled: undefined
|
|
25
|
+
}));
|
|
28
26
|
const ReorderableList = exports.ReorderableList = /*#__PURE__*/(0, _react.forwardRef)(ReorderableListWithRef);
|
|
29
27
|
//# sourceMappingURL=ReorderableList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_ReorderableListCore","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_extends","assign","bind","arguments","length","apply","ReorderableListWithRef","scrollEnabled","rest","ref","createElement","ReorderableListCore","initialScrollViewScrollEnabled","scrollable","scrollViewContainerRef","undefined","scrollViewScrollOffsetY","scrollViewHeightY","outerScrollGesture","scrollViewScrollEnabled","ReorderableList","exports","forwardRef"],"sourceRoot":"../../../src","sources":["components/ReorderableList.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,oBAAA,GAAAD,OAAA;AAA0D,SAAAE,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAe,GAAA,CAAAlB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAAA,SAAAW,SAAA,WAAAA,QAAA,GAAAR,MAAA,CAAAS,MAAA,GAAAT,MAAA,CAAAS,MAAA,CAAAC,IAAA,eAAAb,CAAA,aAAAR,CAAA,MAAAA,CAAA,GAAAsB,SAAA,CAAAC,MAAA,EAAAvB,CAAA,UAAAG,CAAA,GAAAmB,SAAA,CAAAtB,CAAA,YAAAE,CAAA,IAAAC,CAAA,OAAAY,cAAA,CAAAC,IAAA,CAAAb,CAAA,EAAAD,CAAA,MAAAM,CAAA,CAAAN,CAAA,IAAAC,CAAA,CAAAD,CAAA,aAAAM,CAAA,KAAAW,QAAA,CAAAK,KAAA,OAAAF,SAAA;AAG1D,MAAMG,sBAAsB,GAAGA,CAC7B;EAACC,aAAa,GAAG,IAAI;EAAE,GAAGC;AAA6B,CAAC,EACxDC,GAA2B,
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_ReorderableListCore","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_extends","assign","bind","arguments","length","apply","ReorderableListWithRef","scrollEnabled","rest","ref","createElement","ReorderableListCore","initialScrollViewScrollEnabled","scrollable","scrollViewContainerRef","undefined","scrollViewScrollOffsetY","scrollViewHeightY","outerScrollGesture","scrollViewScrollEnabled","ReorderableList","exports","forwardRef"],"sourceRoot":"../../../src","sources":["components/ReorderableList.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,oBAAA,GAAAD,OAAA;AAA0D,SAAAE,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAe,GAAA,CAAAlB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAAA,SAAAW,SAAA,WAAAA,QAAA,GAAAR,MAAA,CAAAS,MAAA,GAAAT,MAAA,CAAAS,MAAA,CAAAC,IAAA,eAAAb,CAAA,aAAAR,CAAA,MAAAA,CAAA,GAAAsB,SAAA,CAAAC,MAAA,EAAAvB,CAAA,UAAAG,CAAA,GAAAmB,SAAA,CAAAtB,CAAA,YAAAE,CAAA,IAAAC,CAAA,OAAAY,cAAA,CAAAC,IAAA,CAAAb,CAAA,EAAAD,CAAA,MAAAM,CAAA,CAAAN,CAAA,IAAAC,CAAA,CAAAD,CAAA,aAAAM,CAAA,KAAAW,QAAA,CAAAK,KAAA,OAAAF,SAAA;AAG1D,MAAMG,sBAAsB,GAAGA,CAC7B;EAACC,aAAa,GAAG,IAAI;EAAE,GAAGC;AAA6B,CAAC,EACxDC,GAA2B,kBAE3BjC,MAAA,CAAAU,OAAA,CAAAwB,aAAA,CAAC/B,oBAAA,CAAAgC,mBAAmB,EAAAX,QAAA,KACdQ,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;AAEM,MAAMK,eAAe,GAAAC,OAAA,CAAAD,eAAA,gBAAG,IAAAE,iBAAU,EAAChB,sBAAsB,CAEhD","ignoreList":[]}
|
|
@@ -21,57 +21,70 @@ const ReorderableListCell = exports.ReorderableListCell = /*#__PURE__*/(0, _reac
|
|
|
21
21
|
draggedIndex,
|
|
22
22
|
animationDuration
|
|
23
23
|
}) => {
|
|
24
|
-
const dragHandler = (0, _react.useCallback)(() => {
|
|
25
|
-
'worklet';
|
|
26
|
-
|
|
27
|
-
startDrag(index);
|
|
28
|
-
}, [startDrag, index]);
|
|
29
|
-
const contextValue = (0, _react.useMemo)(() => ({
|
|
30
|
-
index,
|
|
31
|
-
dragHandler,
|
|
32
|
-
draggedIndex
|
|
33
|
-
}), [index, dragHandler, draggedIndex]);
|
|
34
24
|
const {
|
|
35
25
|
currentIndex,
|
|
36
|
-
draggedHeight
|
|
26
|
+
draggedHeight,
|
|
27
|
+
scale,
|
|
28
|
+
opacity,
|
|
29
|
+
activeIndex
|
|
37
30
|
} = (0, _hooks.useContext)(_contexts.ReorderableListContext);
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
31
|
+
const dragHandler = (0, _react.useCallback)(() => (0, _reactNativeReanimated.runOnUI)(startDrag)(index), [startDrag, index]);
|
|
32
|
+
const isActive = activeIndex === index;
|
|
33
|
+
const contextValue = (0, _react.useMemo)(() => ({
|
|
34
|
+
index,
|
|
35
|
+
dragHandler,
|
|
36
|
+
draggedIndex,
|
|
37
|
+
isActive
|
|
38
|
+
}), [index, dragHandler, draggedIndex, isActive]);
|
|
39
|
+
|
|
40
|
+
// Keep separate animated reactions that update itemTranslateY
|
|
41
|
+
// otherwise animations might stutter if multiple are triggered
|
|
42
|
+
// (even in other cells, e.g. released item and reordering cells)
|
|
43
|
+
const itemTranslateY = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
44
|
+
const isActiveCell = (0, _reactNativeReanimated.useDerivedValue)(() => draggedIndex.value === index);
|
|
42
45
|
(0, _reactNativeReanimated.useAnimatedReaction)(() => dragY.value, () => {
|
|
43
|
-
if (
|
|
44
|
-
|
|
46
|
+
if (index === draggedIndex.value && currentIndex.value >= 0 && draggedIndex.value >= 0) {
|
|
47
|
+
itemTranslateY.value = dragY.value;
|
|
45
48
|
}
|
|
46
49
|
});
|
|
47
50
|
(0, _reactNativeReanimated.useAnimatedReaction)(() => currentIndex.value, () => {
|
|
48
|
-
if (
|
|
51
|
+
if (index !== draggedIndex.value && currentIndex.value >= 0 && draggedIndex.value >= 0) {
|
|
49
52
|
const moveDown = currentIndex.value > draggedIndex.value;
|
|
50
53
|
const startMove = Math.min(draggedIndex.value, currentIndex.value);
|
|
51
54
|
const endMove = Math.max(draggedIndex.value, currentIndex.value);
|
|
52
55
|
let newValue = 0;
|
|
53
|
-
if (
|
|
56
|
+
if (index >= startMove && index <= endMove) {
|
|
54
57
|
newValue = moveDown ? -draggedHeight.value : draggedHeight.value;
|
|
55
58
|
}
|
|
56
|
-
if (newValue !==
|
|
57
|
-
|
|
59
|
+
if (newValue !== itemTranslateY.value) {
|
|
60
|
+
itemTranslateY.value = (0, _reactNativeReanimated.withTiming)(newValue, {
|
|
58
61
|
duration: animationDuration.value,
|
|
59
62
|
easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.ease)
|
|
60
63
|
});
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
});
|
|
64
|
-
(0, _reactNativeReanimated.
|
|
65
|
-
|
|
67
|
+
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
68
|
+
if (isActiveCell.value) {
|
|
69
|
+
return {
|
|
70
|
+
transform: [{
|
|
71
|
+
translateY: itemTranslateY.value
|
|
72
|
+
}, {
|
|
73
|
+
scale: scale.value
|
|
74
|
+
}],
|
|
75
|
+
opacity: opacity.value,
|
|
76
|
+
zIndex: 999
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
transform: [{
|
|
81
|
+
translateY: itemTranslateY.value
|
|
82
|
+
}],
|
|
83
|
+
// TODO: move to stylesheet when this is fixed
|
|
84
|
+
// https://github.com/software-mansion/react-native-reanimated/issues/6681#issuecomment-2514228447
|
|
85
|
+
zIndex: 0
|
|
86
|
+
};
|
|
66
87
|
});
|
|
67
|
-
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
|
68
|
-
zIndex: itemZIndex.value,
|
|
69
|
-
transform: [{
|
|
70
|
-
translateY: itemDragY.value
|
|
71
|
-
}, {
|
|
72
|
-
translateY: itemPositionY.value
|
|
73
|
-
}]
|
|
74
|
-
}));
|
|
75
88
|
const handleLayout = e => {
|
|
76
89
|
(0, _reactNativeReanimated.runOnUI)((y, height) => {
|
|
77
90
|
itemOffset.value[index] = y;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNativeReanimated","_contexts","_hooks","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","ReorderableListCell","exports","memo","index","startDrag","children","onLayout","itemOffset","itemHeight","dragY","draggedIndex","animationDuration","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNativeReanimated","_contexts","_hooks","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","ReorderableListCell","exports","memo","index","startDrag","children","onLayout","itemOffset","itemHeight","dragY","draggedIndex","animationDuration","currentIndex","draggedHeight","scale","opacity","activeIndex","useContext","ReorderableListContext","dragHandler","useCallback","runOnUI","isActive","contextValue","useMemo","itemTranslateY","useSharedValue","isActiveCell","useDerivedValue","value","useAnimatedReaction","moveDown","startMove","Math","min","endMove","max","newValue","withTiming","duration","easing","Easing","out","ease","animatedStyle","useAnimatedStyle","transform","translateY","zIndex","handleLayout","y","height","nativeEvent","layout","createElement","ReorderableCellContext","Provider","View","style"],"sourceRoot":"../../../src","sources":["components/ReorderableListCell.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAGA,IAAAC,sBAAA,GAAAF,uBAAA,CAAAC,OAAA;AAWA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAAoC,SAAAI,yBAAAC,CAAA,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AEC,MAAc,KAAK;MACrC5C,UAAU,CAACsB,KAAK,CAAC1B,KAAK,CAAC,GAAG+C,CAAC;MAC3B1C,UAAU,CAACqB,KAAK,CAAC1B,KAAK,CAAC,GAAGgD,MAAM;IAClC,CAAC,CAAC,CAACtE,CAAC,CAACuE,WAAW,CAACC,MAAM,CAACH,CAAC,EAAErE,CAAC,CAACuE,WAAW,CAACC,MAAM,CAACF,MAAM,CAAC;IAEvD7C,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAGzB,CAAC,CAAC;EACf,CAAC;EAED,oBACEP,MAAA,CAAAY,OAAA,CAAAoE,aAAA,CAAC5E,SAAA,CAAA6E,sBAAsB,CAACC,QAAQ;IAAC3B,KAAK,EAAEN;EAAa,gBACnDjD,MAAA,CAAAY,OAAA,CAAAoE,aAAA,CAAC7E,sBAAA,CAAAS,OAAQ,CAACuE,IAAI;IAACC,KAAK,EAAEd,aAAc;IAACtC,QAAQ,EAAE2C;EAAa,GACzD5C,QACY,CACgB,CAAC;AAEtC,CACF,CAAC","ignoreList":[]}
|
|
@@ -7,37 +7,37 @@ exports.ReorderableListCore = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _reactNativeGestureHandler = require("react-native-gesture-handler");
|
|
10
|
-
var _reactNativeReanimated =
|
|
11
|
-
var
|
|
10
|
+
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
11
|
+
var _autoscrollConfig = require("./autoscrollConfig");
|
|
12
12
|
var _useReorderableListCore = require("./useReorderableListCore");
|
|
13
13
|
var _contexts = require("../../contexts");
|
|
14
14
|
var _ReorderableListCell = require("../ReorderableListCell");
|
|
15
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
17
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
19
18
|
const AnimatedFlatList = _reactNativeReanimated.default.createAnimatedComponent(_reactNative.FlatList);
|
|
20
19
|
const ReorderableListCore = ({
|
|
21
|
-
data,
|
|
22
20
|
autoscrollThreshold = 0.1,
|
|
23
21
|
autoscrollSpeedScale = 1,
|
|
24
|
-
autoscrollDelay =
|
|
22
|
+
autoscrollDelay = _autoscrollConfig.AUTOSCROLL_CONFIG.delay,
|
|
25
23
|
animationDuration = 200,
|
|
26
24
|
dragReorderThreshold = 0.2,
|
|
27
25
|
onLayout,
|
|
28
26
|
onReorder,
|
|
29
27
|
onScroll,
|
|
28
|
+
onDragStart,
|
|
30
29
|
onDragEnd,
|
|
31
|
-
keyExtractor,
|
|
32
|
-
extraData,
|
|
33
30
|
scrollViewContainerRef,
|
|
34
31
|
scrollViewHeightY,
|
|
35
32
|
scrollViewScrollOffsetY,
|
|
36
33
|
scrollViewScrollEnabled,
|
|
37
|
-
scrollEnabled,
|
|
38
34
|
initialScrollViewScrollEnabled,
|
|
39
35
|
scrollable,
|
|
40
36
|
outerScrollGesture,
|
|
37
|
+
cellAnimations,
|
|
38
|
+
shouldUpdateActiveItem,
|
|
39
|
+
panEnabled = true,
|
|
40
|
+
panActivateAfterLongPress,
|
|
41
41
|
...rest
|
|
42
42
|
}, ref) => {
|
|
43
43
|
const {
|
|
@@ -61,7 +61,7 @@ const ReorderableListCore = ({
|
|
|
61
61
|
dragReorderThreshold,
|
|
62
62
|
onLayout,
|
|
63
63
|
onReorder,
|
|
64
|
-
|
|
64
|
+
onDragStart,
|
|
65
65
|
onDragEnd,
|
|
66
66
|
scrollViewContainerRef,
|
|
67
67
|
scrollViewHeightY,
|
|
@@ -69,9 +69,13 @@ const ReorderableListCore = ({
|
|
|
69
69
|
scrollViewScrollEnabled,
|
|
70
70
|
// flatlist will default to true if we pass explicitly undefined,
|
|
71
71
|
// but internally we would treat it as false, so we force true
|
|
72
|
-
initialScrollEnabled: typeof scrollEnabled === 'undefined' ? true : scrollEnabled,
|
|
72
|
+
initialScrollEnabled: typeof rest.scrollEnabled === 'undefined' ? true : rest.scrollEnabled,
|
|
73
73
|
initialScrollViewScrollEnabled: typeof initialScrollViewScrollEnabled === 'undefined' ? true : initialScrollViewScrollEnabled,
|
|
74
|
-
nestedScrollable: scrollable
|
|
74
|
+
nestedScrollable: scrollable,
|
|
75
|
+
cellAnimations,
|
|
76
|
+
shouldUpdateActiveItem,
|
|
77
|
+
panEnabled,
|
|
78
|
+
panActivateAfterLongPress
|
|
75
79
|
});
|
|
76
80
|
const combinedGesture = (0, _react.useMemo)(() => {
|
|
77
81
|
// android is able to handle nested scroll view, but not the full height ones like iOS
|
|
@@ -80,6 +84,7 @@ const ReorderableListCore = ({
|
|
|
80
84
|
}
|
|
81
85
|
return gestureHandler;
|
|
82
86
|
}, [scrollable, outerScrollGesture, gestureHandler]);
|
|
87
|
+
const composedScrollHandler = (0, _reactNativeReanimated.useComposedEventHandler)([handleScroll, onScroll || null]);
|
|
83
88
|
const renderAnimatedCell = (0, _react.useCallback)(({
|
|
84
89
|
cellKey,
|
|
85
90
|
...props
|
|
@@ -99,17 +104,13 @@ const ReorderableListCore = ({
|
|
|
99
104
|
gesture: combinedGesture
|
|
100
105
|
}, /*#__PURE__*/_react.default.createElement(AnimatedFlatList, _extends({}, rest, {
|
|
101
106
|
ref: handleRef,
|
|
102
|
-
data: data,
|
|
103
107
|
CellRendererComponent: renderAnimatedCell,
|
|
104
108
|
onLayout: handleFlatListLayout,
|
|
105
|
-
onScroll:
|
|
109
|
+
onScroll: composedScrollHandler,
|
|
106
110
|
scrollEventThrottle: 1,
|
|
107
111
|
horizontal: false,
|
|
108
112
|
removeClippedSubviews: false,
|
|
109
|
-
|
|
110
|
-
extraData: extraData,
|
|
111
|
-
numColumns: 1,
|
|
112
|
-
scrollEnabled: scrollEnabled
|
|
113
|
+
numColumns: 1
|
|
113
114
|
}))));
|
|
114
115
|
};
|
|
115
116
|
const MemoizedReorderableListCore = exports.ReorderableListCore = /*#__PURE__*/_react.default.memo(/*#__PURE__*/_react.default.forwardRef(ReorderableListCore));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeGestureHandler","_reactNativeReanimated","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeGestureHandler","_reactNativeReanimated","_autoscrollConfig","_useReorderableListCore","_contexts","_ReorderableListCell","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_extends","assign","bind","arguments","length","apply","AnimatedFlatList","Animated","createAnimatedComponent","FlatList","ReorderableListCore","autoscrollThreshold","autoscrollSpeedScale","autoscrollDelay","AUTOSCROLL_CONFIG","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","useReorderableListCore","initialScrollEnabled","scrollEnabled","nestedScrollable","combinedGesture","useMemo","Platform","OS","Gesture","Simultaneous","composedScrollHandler","useComposedEventHandler","renderAnimatedCell","useCallback","cellKey","props","createElement","ReorderableListCell","key","index","ReorderableListContext","Provider","value","GestureDetector","gesture","CellRendererComponent","scrollEventThrottle","horizontal","removeClippedSubviews","numColumns","MemoizedReorderableListCore","exports","React","memo","forwardRef"],"sourceRoot":"../../../../src","sources":["components/ReorderableListCore/ReorderableListCore.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAQA,IAAAE,0BAAA,GAAAF,OAAA;AAKA,IAAAG,sBAAA,GAAAJ,uBAAA,CAAAC,OAAA;AAKA,IAAAI,iBAAA,GAAAJ,OAAA;AACA,IAAAK,uBAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAEA,IAAAO,oBAAA,GAAAP,OAAA;AAA2D,SAAAQ,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAV,wBAAAU,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,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