react-native-drax 0.9.3 → 0.10.2
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/CHANGELOG.md +29 -2
- package/README.md +5 -1
- package/build/DraxContext.js +1 -1
- package/build/DraxList.js +49 -45
- package/build/DraxProvider.d.ts +3 -2
- package/build/DraxProvider.js +17 -13
- package/build/DraxScrollView.js +26 -22
- package/build/DraxSubprovider.js +1 -1
- package/build/DraxView.js +35 -31
- package/build/hooks/useDraxContext.js +1 -1
- package/build/hooks/useDraxId.d.ts +1 -1
- package/build/hooks/useDraxId.js +1 -1
- package/build/hooks/useDraxRegistry.d.ts +1 -1
- package/build/hooks/useDraxRegistry.js +29 -29
- package/build/hooks/useDraxState.js +13 -13
- package/build/index.js +5 -1
- package/build/transform.d.ts +4 -3
- package/build/types.d.ts +16 -29
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,30 @@ Changes marked as (BREAKING) may break your app logic. Changes marked as (BREAKI
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
- Nothing yet
|
|
11
11
|
|
|
12
|
+
## [0.10.2] - 2022-06-10
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- Allow overriding style of DraxProvider (#136)
|
|
16
|
+
|
|
17
|
+
## [0.10.1] - 2022-06-10
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
- Bump ansi-regex from 4.1.0 to 4.1.1 (dependabot)
|
|
21
|
+
- Bump async from 2.6.3 to 2.6.4 (dependabot)
|
|
22
|
+
- Bump cross-fetch from 3.1.4 to 3.1.5 (dependabot)
|
|
23
|
+
- Bump minimist from 1.2.5 to 1.2.6 (dependabot)
|
|
24
|
+
- Bump plist from 3.0.2 to 3.0.5 (dependabot)
|
|
25
|
+
- Bump simple-plist from 1.1.1 to 1.3.1 (dependabot)
|
|
26
|
+
|
|
27
|
+
## [0.10.0] - 2022-06-10
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- (BREAKING) Update requirement from RN 0.62 to RN 0.65
|
|
31
|
+
- (BREAKING-TS) Remove Animated ViewStyle types which were needed as a workaround before
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
- (BREAKING) Stop using removeListener method which was deprecated in RN 0.65 (#125)
|
|
35
|
+
|
|
12
36
|
## [0.9.3] - 2021-12-14
|
|
13
37
|
|
|
14
38
|
### Fixed
|
|
@@ -209,9 +233,12 @@ Changes marked as (BREAKING) may break your app logic. Changes marked as (BREAKI
|
|
|
209
233
|
### Fixed
|
|
210
234
|
- DraxProvider now respects parent padding (#10)
|
|
211
235
|
|
|
212
|
-
*(More history to be added later)*
|
|
236
|
+
*(More history to be added later?)*
|
|
213
237
|
|
|
214
|
-
[Unreleased]: https://github.com/nuclearpasta/react-native-drax/compare/v0.
|
|
238
|
+
[Unreleased]: https://github.com/nuclearpasta/react-native-drax/compare/v0.10.2...HEAD
|
|
239
|
+
[0.10.2]: https://github.com/nuclearpasta/react-native-drax/compare/v0.10.1...v0.10.2
|
|
240
|
+
[0.10.1]: https://github.com/nuclearpasta/react-native-drax/compare/v0.10.0...v0.10.1
|
|
241
|
+
[0.10.0]: https://github.com/nuclearpasta/react-native-drax/compare/v0.9.3...v0.10.0
|
|
215
242
|
[0.9.3]: https://github.com/nuclearpasta/react-native-drax/compare/v0.9.2...v0.9.3
|
|
216
243
|
[0.9.2]: https://github.com/nuclearpasta/react-native-drax/compare/v0.9.1...v0.9.2
|
|
217
244
|
[0.9.1]: https://github.com/nuclearpasta/react-native-drax/compare/v0.9.0...v0.9.1
|
package/README.md
CHANGED
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
|
|
12
12
|
Drax is a declarative drag-and-drop system for React Native, written in TypeScript. It is designed to be flexible and powerful with the goal of supporting many use cases, while its stock components and default settings should cover the most common scenarios with minimal configuration.
|
|
13
13
|
|
|
14
|
-
**Note: as of version 0.
|
|
14
|
+
**Note: as of version 0.10.0, React Native 0.65 or higher is required. For RN 0.62-0.64 projects, you may be able to use 0.9.3, but it will no longer be supported. For RN 0.61 projects, you may be able to use 0.6.0, but it will no longer be supported.**
|
|
15
|
+
|
|
16
|
+
*Personal note from Joe: this project is in need of additional [contributors/shepherds](#contributing). I have not been focused on React Native over the past year, and the state of the library has fallen behind the times. At a minimum, it should be updated to use the latest RNGH and take advantage of any fixes and new features in that and RN. I apologize that I do not have the availability to maintain this project to my own high standards and thank everyone who has been understanding of that.*
|
|
15
17
|
|
|
16
18
|
#### Contents
|
|
17
19
|
|
|
@@ -205,3 +207,5 @@ This software library is licensed under the [MIT License](LICENSE.md).
|
|
|
205
207
|
## Acknowledgments
|
|
206
208
|
|
|
207
209
|
The initial version of this library was written by [Joe Lafiosca](https://github.com/lafiosca) over the course of December 2019. Joe would like to give thanks to Nuclear Pasta co-founder Mark Thomas for being patient with the development process. Joe would also like to give thanks to Lena Raine, Tom Jenkinson, Rollie Pemberton, David Minnick, Tim Smith, and Danny Baranowsky for providing most of the coding background music that inspired this work.
|
|
210
|
+
|
|
211
|
+
Special thanks go to the folks who have contributed donations toward this project. (If you are a sponsor and would like your name listed here, please let me know! I do not want to make assumptions about people's privacy preferences.)
|
package/build/DraxContext.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DraxContext = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
exports.DraxContext = react_1.createContext(undefined);
|
|
5
|
+
exports.DraxContext = (0, react_1.createContext)(undefined);
|
|
6
6
|
exports.DraxContext.displayName = 'Drax';
|
package/build/DraxList.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -40,35 +44,35 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
40
44
|
// Set a sensible default for reorderable prop.
|
|
41
45
|
const reorderable = reorderableProp ?? (onItemReorder !== undefined);
|
|
42
46
|
// The unique identifer for this list's Drax view.
|
|
43
|
-
const id = hooks_1.useDraxId(idProp);
|
|
47
|
+
const id = (0, hooks_1.useDraxId)(idProp);
|
|
44
48
|
// FlatList, used for scrolling.
|
|
45
|
-
const flatListRef = react_1.useRef(null);
|
|
49
|
+
const flatListRef = (0, react_1.useRef)(null);
|
|
46
50
|
// FlatList node handle, used for measuring children.
|
|
47
|
-
const nodeHandleRef = react_1.useRef(null);
|
|
51
|
+
const nodeHandleRef = (0, react_1.useRef)(null);
|
|
48
52
|
// Container view measurements, for scrolling by percentage.
|
|
49
|
-
const containerMeasurementsRef = react_1.useRef(undefined);
|
|
53
|
+
const containerMeasurementsRef = (0, react_1.useRef)(undefined);
|
|
50
54
|
// Content size, for scrolling by percentage.
|
|
51
|
-
const contentSizeRef = react_1.useRef(undefined);
|
|
55
|
+
const contentSizeRef = (0, react_1.useRef)(undefined);
|
|
52
56
|
// Scroll position, for Drax bounds checking and auto-scrolling.
|
|
53
|
-
const scrollPositionRef = react_1.useRef({ x: 0, y: 0 });
|
|
57
|
+
const scrollPositionRef = (0, react_1.useRef)({ x: 0, y: 0 });
|
|
54
58
|
// Original index of the currently dragged list item, if any.
|
|
55
|
-
const draggedItemRef = react_1.useRef(undefined);
|
|
59
|
+
const draggedItemRef = (0, react_1.useRef)(undefined);
|
|
56
60
|
// Auto-scrolling state.
|
|
57
|
-
const scrollStateRef = react_1.useRef(types_1.AutoScrollDirection.None);
|
|
61
|
+
const scrollStateRef = (0, react_1.useRef)(types_1.AutoScrollDirection.None);
|
|
58
62
|
// Auto-scrolling interval.
|
|
59
|
-
const scrollIntervalRef = react_1.useRef(undefined);
|
|
63
|
+
const scrollIntervalRef = (0, react_1.useRef)(undefined);
|
|
60
64
|
// List item measurements, for determining shift.
|
|
61
|
-
const itemMeasurementsRef = react_1.useRef([]);
|
|
65
|
+
const itemMeasurementsRef = (0, react_1.useRef)([]);
|
|
62
66
|
// Drax view registrations, for remeasuring after reorder.
|
|
63
|
-
const registrationsRef = react_1.useRef([]);
|
|
67
|
+
const registrationsRef = (0, react_1.useRef)([]);
|
|
64
68
|
// Shift offsets.
|
|
65
|
-
const shiftsRef = react_1.useRef([]);
|
|
69
|
+
const shiftsRef = (0, react_1.useRef)([]);
|
|
66
70
|
// Maintain cache of reordered list indexes until data updates.
|
|
67
|
-
const [originalIndexes, setOriginalIndexes] = react_1.useState([]);
|
|
71
|
+
const [originalIndexes, setOriginalIndexes] = (0, react_1.useState)([]);
|
|
68
72
|
// Maintain the index the item is currently dragged to.
|
|
69
|
-
const draggedToIndex = react_1.useRef(undefined);
|
|
73
|
+
const draggedToIndex = (0, react_1.useRef)(undefined);
|
|
70
74
|
// Adjust measurements, registrations, and shift value arrays as item count changes.
|
|
71
|
-
react_1.useEffect(() => {
|
|
75
|
+
(0, react_1.useEffect)(() => {
|
|
72
76
|
const itemMeasurements = itemMeasurementsRef.current;
|
|
73
77
|
const registrations = registrationsRef.current;
|
|
74
78
|
const shifts = shiftsRef.current;
|
|
@@ -101,12 +105,12 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
101
105
|
}
|
|
102
106
|
}, [itemCount]);
|
|
103
107
|
// Clear reorders when data changes.
|
|
104
|
-
react_1.useLayoutEffect(() => {
|
|
108
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
105
109
|
// console.log('clear reorders');
|
|
106
110
|
setOriginalIndexes(data ? [...Array(data.length).keys()] : []);
|
|
107
111
|
}, [data]);
|
|
108
112
|
// Apply the reorder cache to the data.
|
|
109
|
-
const reorderedData = react_1.useMemo(() => {
|
|
113
|
+
const reorderedData = (0, react_1.useMemo)(() => {
|
|
110
114
|
// console.log('refresh sorted data');
|
|
111
115
|
if (!id || !data) {
|
|
112
116
|
return null;
|
|
@@ -117,26 +121,26 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
117
121
|
return originalIndexes.map((index) => data[index]);
|
|
118
122
|
}, [id, data, originalIndexes]);
|
|
119
123
|
// Get shift transform for list item at index.
|
|
120
|
-
const getShiftTransform = react_1.useCallback((index) => {
|
|
124
|
+
const getShiftTransform = (0, react_1.useCallback)((index) => {
|
|
121
125
|
const shift = shiftsRef.current[index]?.animatedValue ?? 0;
|
|
122
126
|
return horizontal
|
|
123
127
|
? [{ translateX: shift }]
|
|
124
128
|
: [{ translateY: shift }];
|
|
125
129
|
}, [horizontal]);
|
|
126
130
|
// Set the currently dragged list item.
|
|
127
|
-
const setDraggedItem = react_1.useCallback((originalIndex) => {
|
|
131
|
+
const setDraggedItem = (0, react_1.useCallback)((originalIndex) => {
|
|
128
132
|
draggedItemRef.current = originalIndex;
|
|
129
133
|
}, []);
|
|
130
134
|
// Clear the currently dragged list item.
|
|
131
|
-
const resetDraggedItem = react_1.useCallback(() => {
|
|
135
|
+
const resetDraggedItem = (0, react_1.useCallback)(() => {
|
|
132
136
|
draggedItemRef.current = undefined;
|
|
133
137
|
}, []);
|
|
134
138
|
// Drax view renderItem wrapper.
|
|
135
|
-
const renderItem = react_1.useCallback((info) => {
|
|
139
|
+
const renderItem = (0, react_1.useCallback)((info) => {
|
|
136
140
|
const { index, item } = info;
|
|
137
141
|
const originalIndex = originalIndexes[index];
|
|
138
142
|
const { style: itemStyle, draggingStyle = defaultStyles.draggingStyle, dragReleasedStyle = defaultStyles.dragReleasedStyle, ...otherStyleProps } = itemStyles ?? {};
|
|
139
|
-
return (react_1.default.createElement(DraxView_1.DraxView,
|
|
143
|
+
return (react_1.default.createElement(DraxView_1.DraxView, { style: [itemStyle, { transform: getShiftTransform(originalIndex) }], draggingStyle: draggingStyle, dragReleasedStyle: dragReleasedStyle, ...otherStyleProps, longPressDelay: longPressDelay, lockDragXPosition: lockItemDragsToMainAxis && !horizontal, lockDragYPosition: lockItemDragsToMainAxis && horizontal, draggable: itemsDraggable, payload: { index, originalIndex }, ...(viewPropsExtractor?.(item) ?? {}), onDragEnd: resetDraggedItem, onDragDrop: resetDraggedItem, onMeasure: (measurements) => {
|
|
140
144
|
if (originalIndex !== undefined) {
|
|
141
145
|
// console.log(`measuring [${index}, ${originalIndex}]: (${measurements?.x}, ${measurements?.y})`);
|
|
142
146
|
itemMeasurementsRef.current[originalIndex] = measurements;
|
|
@@ -148,7 +152,7 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
148
152
|
registration.measure();
|
|
149
153
|
}
|
|
150
154
|
}, renderContent: (contentProps) => renderItemContent(info, contentProps), renderHoverContent: renderItemHoverContent
|
|
151
|
-
&& ((hoverContentProps) => renderItemHoverContent(info, hoverContentProps)) }))
|
|
155
|
+
&& ((hoverContentProps) => renderItemHoverContent(info, hoverContentProps)) }));
|
|
152
156
|
}, [
|
|
153
157
|
originalIndexes,
|
|
154
158
|
itemStyles,
|
|
@@ -163,17 +167,17 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
163
167
|
horizontal,
|
|
164
168
|
]);
|
|
165
169
|
// Track the size of the container view.
|
|
166
|
-
const onMeasureContainer = react_1.useCallback((measurements) => {
|
|
170
|
+
const onMeasureContainer = (0, react_1.useCallback)((measurements) => {
|
|
167
171
|
containerMeasurementsRef.current = measurements;
|
|
168
172
|
}, []);
|
|
169
173
|
// Track the size of the content.
|
|
170
|
-
const onContentSizeChange = react_1.useCallback((width, height) => {
|
|
174
|
+
const onContentSizeChange = (0, react_1.useCallback)((width, height) => {
|
|
171
175
|
contentSizeRef.current = { x: width, y: height };
|
|
172
176
|
}, []);
|
|
173
177
|
// Set FlatList and node handle refs.
|
|
174
|
-
const setFlatListRefs = react_1.useCallback((ref) => {
|
|
178
|
+
const setFlatListRefs = (0, react_1.useCallback)((ref) => {
|
|
175
179
|
flatListRef.current = ref;
|
|
176
|
-
nodeHandleRef.current = ref && react_native_1.findNodeHandle(ref);
|
|
180
|
+
nodeHandleRef.current = ref && (0, react_native_1.findNodeHandle)(ref);
|
|
177
181
|
if (forwardedRef) {
|
|
178
182
|
if (typeof forwardedRef === 'function') {
|
|
179
183
|
forwardedRef(ref);
|
|
@@ -185,13 +189,13 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
185
189
|
}
|
|
186
190
|
}, [forwardedRef]);
|
|
187
191
|
// Update tracked scroll position when list is scrolled.
|
|
188
|
-
const onScroll = react_1.useCallback((event) => {
|
|
192
|
+
const onScroll = (0, react_1.useCallback)((event) => {
|
|
189
193
|
const { nativeEvent: { contentOffset } } = event;
|
|
190
194
|
scrollPositionRef.current = { ...contentOffset };
|
|
191
195
|
onScrollProp?.(event);
|
|
192
196
|
}, [onScrollProp]);
|
|
193
197
|
// Handle auto-scrolling on interval.
|
|
194
|
-
const doScroll = react_1.useCallback(() => {
|
|
198
|
+
const doScroll = (0, react_1.useCallback)(() => {
|
|
195
199
|
const flatList = flatListRef.current;
|
|
196
200
|
const containerMeasurements = containerMeasurementsRef.current;
|
|
197
201
|
const contentSize = contentSizeRef.current;
|
|
@@ -230,7 +234,7 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
230
234
|
}
|
|
231
235
|
}, [horizontal]);
|
|
232
236
|
// Start the auto-scrolling interval.
|
|
233
|
-
const startScroll = react_1.useCallback(() => {
|
|
237
|
+
const startScroll = (0, react_1.useCallback)(() => {
|
|
234
238
|
if (scrollIntervalRef.current) {
|
|
235
239
|
return;
|
|
236
240
|
}
|
|
@@ -238,21 +242,21 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
238
242
|
scrollIntervalRef.current = setInterval(doScroll, 250);
|
|
239
243
|
}, [doScroll]);
|
|
240
244
|
// Stop the auto-scrolling interval.
|
|
241
|
-
const stopScroll = react_1.useCallback(() => {
|
|
245
|
+
const stopScroll = (0, react_1.useCallback)(() => {
|
|
242
246
|
if (scrollIntervalRef.current) {
|
|
243
247
|
clearInterval(scrollIntervalRef.current);
|
|
244
248
|
scrollIntervalRef.current = undefined;
|
|
245
249
|
}
|
|
246
250
|
}, []);
|
|
247
251
|
// If startScroll changes, refresh our interval.
|
|
248
|
-
react_1.useEffect(() => {
|
|
252
|
+
(0, react_1.useEffect)(() => {
|
|
249
253
|
if (scrollIntervalRef.current) {
|
|
250
254
|
stopScroll();
|
|
251
255
|
startScroll();
|
|
252
256
|
}
|
|
253
257
|
}, [stopScroll, startScroll]);
|
|
254
258
|
// Reset all shift values.
|
|
255
|
-
const resetShifts = react_1.useCallback(() => {
|
|
259
|
+
const resetShifts = (0, react_1.useCallback)(() => {
|
|
256
260
|
shiftsRef.current.forEach((shift) => {
|
|
257
261
|
// eslint-disable-next-line no-param-reassign
|
|
258
262
|
shift.targetValue = 0;
|
|
@@ -260,7 +264,7 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
260
264
|
});
|
|
261
265
|
}, []);
|
|
262
266
|
// Update shift values in response to a drag.
|
|
263
|
-
const updateShifts = react_1.useCallback(({ index: fromIndex, originalIndex: fromOriginalIndex }, { index: toIndex }) => {
|
|
267
|
+
const updateShifts = (0, react_1.useCallback)(({ index: fromIndex, originalIndex: fromOriginalIndex }, { index: toIndex }) => {
|
|
264
268
|
const { width = 50, height = 50 } = itemMeasurementsRef.current[fromOriginalIndex] ?? {};
|
|
265
269
|
const offset = horizontal ? width : height;
|
|
266
270
|
originalIndexes.forEach((originalIndex, index) => {
|
|
@@ -283,7 +287,7 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
283
287
|
});
|
|
284
288
|
}, [originalIndexes, horizontal]);
|
|
285
289
|
// Calculate absolute position of list item for snapback.
|
|
286
|
-
const calculateSnapbackTarget = react_1.useCallback(({ index: fromIndex, originalIndex: fromOriginalIndex }, { index: toIndex, originalIndex: toOriginalIndex }) => {
|
|
290
|
+
const calculateSnapbackTarget = (0, react_1.useCallback)(({ index: fromIndex, originalIndex: fromOriginalIndex }, { index: toIndex, originalIndex: toOriginalIndex }) => {
|
|
287
291
|
const containerMeasurements = containerMeasurementsRef.current;
|
|
288
292
|
const itemMeasurements = itemMeasurementsRef.current;
|
|
289
293
|
if (containerMeasurements) {
|
|
@@ -333,7 +337,7 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
333
337
|
return types_1.DraxSnapbackTargetPreset.None;
|
|
334
338
|
}, [horizontal, itemCount, originalIndexes]);
|
|
335
339
|
// Stop auto-scrolling, and potentially update shifts and reorder data.
|
|
336
|
-
const handleInternalDragEnd = react_1.useCallback((eventData, totalDragEnd) => {
|
|
340
|
+
const handleInternalDragEnd = (0, react_1.useCallback)((eventData, totalDragEnd) => {
|
|
337
341
|
// Always stop auto-scroll on drag end.
|
|
338
342
|
scrollStateRef.current = types_1.AutoScrollDirection.None;
|
|
339
343
|
stopScroll();
|
|
@@ -355,7 +359,7 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
355
359
|
...eventData,
|
|
356
360
|
toIndex,
|
|
357
361
|
toItem,
|
|
358
|
-
cancelled: types_1.isWithCancelledFlag(eventData) ? eventData.cancelled : false,
|
|
362
|
+
cancelled: (0, types_1.isWithCancelledFlag)(eventData) ? eventData.cancelled : false,
|
|
359
363
|
index: fromIndex,
|
|
360
364
|
item: data?.[fromOriginalIndex],
|
|
361
365
|
});
|
|
@@ -405,7 +409,7 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
405
409
|
onItemReorder,
|
|
406
410
|
]);
|
|
407
411
|
// Monitor drag starts to handle callbacks.
|
|
408
|
-
const onMonitorDragStart = react_1.useCallback((eventData) => {
|
|
412
|
+
const onMonitorDragStart = (0, react_1.useCallback)((eventData) => {
|
|
409
413
|
const { dragged } = eventData;
|
|
410
414
|
// First, check if we need to do anything.
|
|
411
415
|
if (reorderable && dragged.parentId === id) {
|
|
@@ -426,7 +430,7 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
426
430
|
onItemDragStart,
|
|
427
431
|
]);
|
|
428
432
|
// Monitor drags to react with item shifts and auto-scrolling.
|
|
429
|
-
const onMonitorDragOver = react_1.useCallback((eventData) => {
|
|
433
|
+
const onMonitorDragOver = (0, react_1.useCallback)((eventData) => {
|
|
430
434
|
const { dragged, receiver, monitorOffsetRatio } = eventData;
|
|
431
435
|
// First, check if we need to shift items.
|
|
432
436
|
if (reorderable && dragged.parentId === id) {
|
|
@@ -477,17 +481,17 @@ const DraxListUnforwarded = (props, forwardedRef) => {
|
|
|
477
481
|
onItemDragPositionChange,
|
|
478
482
|
]);
|
|
479
483
|
// Monitor drag exits to stop scrolling, update shifts, and update draggedToIndex.
|
|
480
|
-
const onMonitorDragExit = react_1.useCallback((eventData) => handleInternalDragEnd(eventData, false), [handleInternalDragEnd]);
|
|
484
|
+
const onMonitorDragExit = (0, react_1.useCallback)((eventData) => handleInternalDragEnd(eventData, false), [handleInternalDragEnd]);
|
|
481
485
|
/*
|
|
482
486
|
* Monitor drag ends to stop scrolling, update shifts, and possibly reorder.
|
|
483
487
|
* This addresses the Android case where if we drag a list item and auto-scroll
|
|
484
488
|
* too far, the drag gets cancelled.
|
|
485
489
|
*/
|
|
486
|
-
const onMonitorDragEnd = react_1.useCallback((eventData) => handleInternalDragEnd(eventData, true), [handleInternalDragEnd]);
|
|
490
|
+
const onMonitorDragEnd = (0, react_1.useCallback)((eventData) => handleInternalDragEnd(eventData, true), [handleInternalDragEnd]);
|
|
487
491
|
// Monitor drag drops to stop scrolling, update shifts, and possibly reorder.
|
|
488
|
-
const onMonitorDragDrop = react_1.useCallback((eventData) => handleInternalDragEnd(eventData, true), [handleInternalDragEnd]);
|
|
492
|
+
const onMonitorDragDrop = (0, react_1.useCallback)((eventData) => handleInternalDragEnd(eventData, true), [handleInternalDragEnd]);
|
|
489
493
|
return (react_1.default.createElement(DraxView_1.DraxView, { id: id, style: style, scrollPositionRef: scrollPositionRef, onMeasure: onMeasureContainer, onMonitorDragStart: onMonitorDragStart, onMonitorDragOver: onMonitorDragOver, onMonitorDragExit: onMonitorDragExit, onMonitorDragEnd: onMonitorDragEnd, onMonitorDragDrop: onMonitorDragDrop },
|
|
490
494
|
react_1.default.createElement(DraxSubprovider_1.DraxSubprovider, { parent: { id, nodeHandleRef } },
|
|
491
|
-
react_1.default.createElement(react_native_1.FlatList,
|
|
495
|
+
react_1.default.createElement(react_native_1.FlatList, { ...flatListProps, style: flatListStyle, ref: setFlatListRefs, renderItem: renderItem, onScroll: onScroll, onContentSizeChange: onContentSizeChange, data: reorderedData }))));
|
|
492
496
|
};
|
|
493
|
-
exports.DraxList = react_1.forwardRef(DraxListUnforwarded);
|
|
497
|
+
exports.DraxList = (0, react_1.forwardRef)(DraxListUnforwarded);
|
package/build/DraxProvider.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/// <reference types="react" />
|
|
2
3
|
import { DraxProviderProps } from './types';
|
|
3
|
-
export declare const DraxProvider:
|
|
4
|
+
export declare const DraxProvider: ({ debug, style, children, }: DraxProviderProps) => JSX.Element;
|
package/build/DraxProvider.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -27,11 +31,11 @@ const hooks_1 = require("./hooks");
|
|
|
27
31
|
const DraxContext_1 = require("./DraxContext");
|
|
28
32
|
const types_1 = require("./types");
|
|
29
33
|
const math_1 = require("./math");
|
|
30
|
-
const DraxProvider = ({ debug = false, children }) => {
|
|
31
|
-
const { getViewState, getTrackingStatus, dispatch, } = hooks_1.useDraxState();
|
|
32
|
-
const { getAbsoluteViewData, getTrackingDragged, getTrackingReceiver, getTrackingMonitorIds, getTrackingMonitors, getDragPositionData, findMonitorsAndReceiver, getHoverItems, registerView, updateViewProtocol, updateViewMeasurements, resetReceiver, resetDrag, startDrag, updateDragPosition, updateReceiver, setMonitorIds, unregisterView, } = hooks_1.useDraxRegistry(dispatch);
|
|
33
|
-
const rootNodeHandleRef = react_1.useRef(null);
|
|
34
|
-
const handleGestureStateChange = react_1.useCallback((id, event) => {
|
|
34
|
+
const DraxProvider = ({ debug = false, style = styles.provider, children, }) => {
|
|
35
|
+
const { getViewState, getTrackingStatus, dispatch, } = (0, hooks_1.useDraxState)();
|
|
36
|
+
const { getAbsoluteViewData, getTrackingDragged, getTrackingReceiver, getTrackingMonitorIds, getTrackingMonitors, getDragPositionData, findMonitorsAndReceiver, getHoverItems, registerView, updateViewProtocol, updateViewMeasurements, resetReceiver, resetDrag, startDrag, updateDragPosition, updateReceiver, setMonitorIds, unregisterView, } = (0, hooks_1.useDraxRegistry)(dispatch);
|
|
37
|
+
const rootNodeHandleRef = (0, react_1.useRef)(null);
|
|
38
|
+
const handleGestureStateChange = (0, react_1.useCallback)((id, event) => {
|
|
35
39
|
if (debug) {
|
|
36
40
|
console.log(`handleGestureStateChange(${id}, ${JSON.stringify(event, null, 2)})`);
|
|
37
41
|
}
|
|
@@ -199,7 +203,7 @@ const DraxProvider = ({ debug = false, children }) => {
|
|
|
199
203
|
if (monitors.length > 0) {
|
|
200
204
|
monitors.forEach(({ data: monitorData }) => {
|
|
201
205
|
if (monitorData) {
|
|
202
|
-
const { relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio, } = math_1.getRelativePosition(dragAbsolutePosition, monitorData.absoluteMeasurements);
|
|
206
|
+
const { relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio, } = (0, math_1.getRelativePosition)(dragAbsolutePosition, monitorData.absoluteMeasurements);
|
|
203
207
|
response = monitorData.protocol.onMonitorDragDrop?.({
|
|
204
208
|
...eventData,
|
|
205
209
|
monitorOffset,
|
|
@@ -249,7 +253,7 @@ const DraxProvider = ({ debug = false, children }) => {
|
|
|
249
253
|
receiver: eventReceiverData,
|
|
250
254
|
};
|
|
251
255
|
monitors.forEach(({ data: monitorData }) => {
|
|
252
|
-
const { relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio, } = math_1.getRelativePosition(dragAbsolutePosition, monitorData.absoluteMeasurements);
|
|
256
|
+
const { relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio, } = (0, math_1.getRelativePosition)(dragAbsolutePosition, monitorData.absoluteMeasurements);
|
|
253
257
|
response = monitorData.protocol.onMonitorDragEnd?.({
|
|
254
258
|
...monitorEventData,
|
|
255
259
|
monitorOffset,
|
|
@@ -373,7 +377,7 @@ const DraxProvider = ({ debug = false, children }) => {
|
|
|
373
377
|
setMonitorIds,
|
|
374
378
|
debug,
|
|
375
379
|
]);
|
|
376
|
-
const handleGestureEvent = react_1.useCallback((id, event) => {
|
|
380
|
+
const handleGestureEvent = (0, react_1.useCallback)((id, event) => {
|
|
377
381
|
if (debug) {
|
|
378
382
|
console.log(`handleGestureEvent(${id}, ${JSON.stringify(event, null, 2)})`);
|
|
379
383
|
}
|
|
@@ -570,7 +574,7 @@ const DraxProvider = ({ debug = false, children }) => {
|
|
|
570
574
|
// Drag has exited monitor.
|
|
571
575
|
const monitorData = getAbsoluteViewData(monitorId);
|
|
572
576
|
if (monitorData) {
|
|
573
|
-
const { relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio, } = math_1.getRelativePosition(dragAbsolutePosition, monitorData.absoluteMeasurements);
|
|
577
|
+
const { relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio, } = (0, math_1.getRelativePosition)(dragAbsolutePosition, monitorData.absoluteMeasurements);
|
|
574
578
|
monitorData.protocol.onMonitorDragExit?.({
|
|
575
579
|
...monitorEventDataStub,
|
|
576
580
|
monitorOffset,
|
|
@@ -621,11 +625,11 @@ const DraxProvider = ({ debug = false, children }) => {
|
|
|
621
625
|
}
|
|
622
626
|
}
|
|
623
627
|
});
|
|
624
|
-
const setRootNodeHandleRef = react_1.useCallback((ref) => {
|
|
625
|
-
rootNodeHandleRef.current = ref && react_native_1.findNodeHandle(ref);
|
|
628
|
+
const setRootNodeHandleRef = (0, react_1.useCallback)((ref) => {
|
|
629
|
+
rootNodeHandleRef.current = ref && (0, react_native_1.findNodeHandle)(ref);
|
|
626
630
|
}, []);
|
|
627
631
|
return (react_1.default.createElement(DraxContext_1.DraxContext.Provider, { value: contextValue },
|
|
628
|
-
react_1.default.createElement(react_native_1.View, { style:
|
|
632
|
+
react_1.default.createElement(react_native_1.View, { style: style, ref: setRootNodeHandleRef },
|
|
629
633
|
children,
|
|
630
634
|
react_1.default.createElement(react_native_1.View, { style: react_native_1.StyleSheet.absoluteFill, pointerEvents: "none" }, hoverViews))));
|
|
631
635
|
};
|
package/build/DraxScrollView.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -30,26 +34,26 @@ const params_1 = require("./params");
|
|
|
30
34
|
const DraxScrollViewUnforwarded = (props, forwardedRef) => {
|
|
31
35
|
const { children, style, onScroll: onScrollProp, onContentSizeChange: onContentSizeChangeProp, scrollEventThrottle = params_1.defaultScrollEventThrottle, autoScrollIntervalLength = params_1.defaultAutoScrollIntervalLength, autoScrollJumpRatio = params_1.defaultAutoScrollJumpRatio, autoScrollBackThreshold = params_1.defaultAutoScrollBackThreshold, autoScrollForwardThreshold = params_1.defaultAutoScrollForwardThreshold, id: idProp, ...scrollViewProps } = props;
|
|
32
36
|
// The unique identifer for this view.
|
|
33
|
-
const id = hooks_1.useDraxId(idProp);
|
|
37
|
+
const id = (0, hooks_1.useDraxId)(idProp);
|
|
34
38
|
// Scrollable view, used for scrolling.
|
|
35
|
-
const scrollRef = react_1.useRef(null);
|
|
39
|
+
const scrollRef = (0, react_1.useRef)(null);
|
|
36
40
|
// ScrollView node handle, used for measuring children.
|
|
37
|
-
const nodeHandleRef = react_1.useRef(null);
|
|
41
|
+
const nodeHandleRef = (0, react_1.useRef)(null);
|
|
38
42
|
// Container view measurements, for scrolling by percentage.
|
|
39
|
-
const containerMeasurementsRef = react_1.useRef(undefined);
|
|
43
|
+
const containerMeasurementsRef = (0, react_1.useRef)(undefined);
|
|
40
44
|
// Content size, for scrolling by percentage.
|
|
41
|
-
const contentSizeRef = react_1.useRef(undefined);
|
|
45
|
+
const contentSizeRef = (0, react_1.useRef)(undefined);
|
|
42
46
|
// Scroll position, for Drax bounds checking and auto-scrolling.
|
|
43
|
-
const scrollPositionRef = react_1.useRef({ x: 0, y: 0 });
|
|
47
|
+
const scrollPositionRef = (0, react_1.useRef)({ x: 0, y: 0 });
|
|
44
48
|
// Auto-scroll state.
|
|
45
|
-
const autoScrollStateRef = react_1.useRef({
|
|
49
|
+
const autoScrollStateRef = (0, react_1.useRef)({
|
|
46
50
|
x: types_1.AutoScrollDirection.None,
|
|
47
51
|
y: types_1.AutoScrollDirection.None,
|
|
48
52
|
});
|
|
49
53
|
// Auto-scroll interval.
|
|
50
|
-
const autoScrollIntervalRef = react_1.useRef(undefined);
|
|
54
|
+
const autoScrollIntervalRef = (0, react_1.useRef)(undefined);
|
|
51
55
|
// Handle auto-scrolling on interval.
|
|
52
|
-
const doScroll = react_1.useCallback(() => {
|
|
56
|
+
const doScroll = (0, react_1.useCallback)(() => {
|
|
53
57
|
const scroll = scrollRef.current;
|
|
54
58
|
const containerMeasurements = containerMeasurementsRef.current;
|
|
55
59
|
const contentSize = contentSizeRef.current;
|
|
@@ -95,7 +99,7 @@ const DraxScrollViewUnforwarded = (props, forwardedRef) => {
|
|
|
95
99
|
}
|
|
96
100
|
}, [autoScrollJumpRatio]);
|
|
97
101
|
// Start the auto-scrolling interval.
|
|
98
|
-
const startScroll = react_1.useCallback(() => {
|
|
102
|
+
const startScroll = (0, react_1.useCallback)(() => {
|
|
99
103
|
if (autoScrollIntervalRef.current) {
|
|
100
104
|
return;
|
|
101
105
|
}
|
|
@@ -103,32 +107,32 @@ const DraxScrollViewUnforwarded = (props, forwardedRef) => {
|
|
|
103
107
|
autoScrollIntervalRef.current = setInterval(doScroll, autoScrollIntervalLength);
|
|
104
108
|
}, [doScroll, autoScrollIntervalLength]);
|
|
105
109
|
// Stop the auto-scrolling interval.
|
|
106
|
-
const stopScroll = react_1.useCallback(() => {
|
|
110
|
+
const stopScroll = (0, react_1.useCallback)(() => {
|
|
107
111
|
if (autoScrollIntervalRef.current) {
|
|
108
112
|
clearInterval(autoScrollIntervalRef.current);
|
|
109
113
|
autoScrollIntervalRef.current = undefined;
|
|
110
114
|
}
|
|
111
115
|
}, []);
|
|
112
116
|
// If startScroll changes, refresh our interval.
|
|
113
|
-
react_1.useEffect(() => {
|
|
117
|
+
(0, react_1.useEffect)(() => {
|
|
114
118
|
if (autoScrollIntervalRef.current) {
|
|
115
119
|
stopScroll();
|
|
116
120
|
startScroll();
|
|
117
121
|
}
|
|
118
122
|
}, [stopScroll, startScroll]);
|
|
119
123
|
// Clear auto-scroll direction and stop the auto-scrolling interval.
|
|
120
|
-
const resetScroll = react_1.useCallback(() => {
|
|
124
|
+
const resetScroll = (0, react_1.useCallback)(() => {
|
|
121
125
|
const autoScrollState = autoScrollStateRef.current;
|
|
122
126
|
autoScrollState.x = types_1.AutoScrollDirection.None;
|
|
123
127
|
autoScrollState.y = types_1.AutoScrollDirection.None;
|
|
124
128
|
stopScroll();
|
|
125
129
|
}, [stopScroll]);
|
|
126
130
|
// Track the size of the container view.
|
|
127
|
-
const onMeasureContainer = react_1.useCallback((measurements) => {
|
|
131
|
+
const onMeasureContainer = (0, react_1.useCallback)((measurements) => {
|
|
128
132
|
containerMeasurementsRef.current = measurements;
|
|
129
133
|
}, []);
|
|
130
134
|
// Monitor drag-over events to react with auto-scrolling.
|
|
131
|
-
const onMonitorDragOver = react_1.useCallback((event) => {
|
|
135
|
+
const onMonitorDragOver = (0, react_1.useCallback)((event) => {
|
|
132
136
|
const { monitorOffsetRatio } = event;
|
|
133
137
|
const autoScrollState = autoScrollStateRef.current;
|
|
134
138
|
if (monitorOffsetRatio.x >= autoScrollForwardThreshold) {
|
|
@@ -162,9 +166,9 @@ const DraxScrollViewUnforwarded = (props, forwardedRef) => {
|
|
|
162
166
|
autoScrollForwardThreshold,
|
|
163
167
|
]);
|
|
164
168
|
// Set the ScrollView and node handle refs.
|
|
165
|
-
const setScrollViewRefs = react_1.useCallback((ref) => {
|
|
169
|
+
const setScrollViewRefs = (0, react_1.useCallback)((ref) => {
|
|
166
170
|
scrollRef.current = ref;
|
|
167
|
-
nodeHandleRef.current = ref && react_native_1.findNodeHandle(ref);
|
|
171
|
+
nodeHandleRef.current = ref && (0, react_native_1.findNodeHandle)(ref);
|
|
168
172
|
if (forwardedRef) {
|
|
169
173
|
if (typeof forwardedRef === 'function') {
|
|
170
174
|
forwardedRef(ref);
|
|
@@ -176,18 +180,18 @@ const DraxScrollViewUnforwarded = (props, forwardedRef) => {
|
|
|
176
180
|
}
|
|
177
181
|
}, [forwardedRef]);
|
|
178
182
|
// Track content size.
|
|
179
|
-
const onContentSizeChange = react_1.useCallback((width, height) => {
|
|
183
|
+
const onContentSizeChange = (0, react_1.useCallback)((width, height) => {
|
|
180
184
|
contentSizeRef.current = { x: width, y: height };
|
|
181
185
|
return onContentSizeChangeProp?.(width, height);
|
|
182
186
|
}, [onContentSizeChangeProp]);
|
|
183
187
|
// Update tracked scroll position when list is scrolled.
|
|
184
|
-
const onScroll = react_1.useCallback((event) => {
|
|
188
|
+
const onScroll = (0, react_1.useCallback)((event) => {
|
|
185
189
|
const { nativeEvent: { contentOffset } } = event;
|
|
186
190
|
scrollPositionRef.current = { ...contentOffset };
|
|
187
191
|
return onScrollProp?.(event);
|
|
188
192
|
}, [onScrollProp]);
|
|
189
193
|
return id ? (react_1.default.createElement(DraxView_1.DraxView, { id: id, style: style, scrollPositionRef: scrollPositionRef, onMeasure: onMeasureContainer, onMonitorDragOver: onMonitorDragOver, onMonitorDragExit: resetScroll, onMonitorDragEnd: resetScroll, onMonitorDragDrop: resetScroll },
|
|
190
194
|
react_1.default.createElement(DraxSubprovider_1.DraxSubprovider, { parent: { id, nodeHandleRef } },
|
|
191
|
-
react_1.default.createElement(react_native_1.ScrollView,
|
|
195
|
+
react_1.default.createElement(react_native_1.ScrollView, { ...scrollViewProps, ref: setScrollViewRefs, onContentSizeChange: onContentSizeChange, onScroll: onScroll, scrollEventThrottle: scrollEventThrottle }, children)))) : null;
|
|
192
196
|
};
|
|
193
|
-
exports.DraxScrollView = react_1.forwardRef(DraxScrollViewUnforwarded);
|
|
197
|
+
exports.DraxScrollView = (0, react_1.forwardRef)(DraxScrollViewUnforwarded);
|
package/build/DraxSubprovider.js
CHANGED
|
@@ -8,7 +8,7 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const DraxContext_1 = require("./DraxContext");
|
|
9
9
|
const hooks_1 = require("./hooks");
|
|
10
10
|
const DraxSubprovider = ({ parent, children }) => {
|
|
11
|
-
const contextValue = hooks_1.useDraxContext();
|
|
11
|
+
const contextValue = (0, hooks_1.useDraxContext)();
|
|
12
12
|
const subContextValue = {
|
|
13
13
|
...contextValue,
|
|
14
14
|
parent,
|
package/build/DraxView.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -57,22 +61,22 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
57
61
|
|| !!onMonitorDragEnd
|
|
58
62
|
|| !!onMonitorDragDrop);
|
|
59
63
|
// The unique identifier for this view.
|
|
60
|
-
const id = hooks_1.useDraxId(idProp);
|
|
64
|
+
const id = (0, hooks_1.useDraxId)(idProp);
|
|
61
65
|
// The underlying View, for measuring.
|
|
62
|
-
const viewRef = react_1.useRef(null);
|
|
66
|
+
const viewRef = (0, react_1.useRef)(null);
|
|
63
67
|
// The underlying View node handle, used for subprovider nesting if this is a Drax parent view.
|
|
64
|
-
const nodeHandleRef = react_1.useRef(null);
|
|
68
|
+
const nodeHandleRef = (0, react_1.useRef)(null);
|
|
65
69
|
// This view's measurements, for reference.
|
|
66
|
-
const measurementsRef = react_1.useRef(undefined);
|
|
70
|
+
const measurementsRef = (0, react_1.useRef)(undefined);
|
|
67
71
|
// Connect with Drax.
|
|
68
|
-
const { getViewState, getTrackingStatus, registerView, unregisterView, updateViewProtocol, updateViewMeasurements, handleGestureEvent, handleGestureStateChange, rootNodeHandleRef, parent: contextParent, } = hooks_1.useDraxContext();
|
|
72
|
+
const { getViewState, getTrackingStatus, registerView, unregisterView, updateViewProtocol, updateViewMeasurements, handleGestureEvent, handleGestureStateChange, rootNodeHandleRef, parent: contextParent, } = (0, hooks_1.useDraxContext)();
|
|
69
73
|
// Identify Drax parent view (if any) from context or prop override.
|
|
70
74
|
const parent = parentProp ?? contextParent;
|
|
71
75
|
const parentId = parent?.id;
|
|
72
76
|
// Identify parent node handle ref.
|
|
73
77
|
const parentNodeHandleRef = parent ? parent.nodeHandleRef : rootNodeHandleRef;
|
|
74
78
|
// Register and unregister with Drax context when necessary.
|
|
75
|
-
react_1.useEffect(() => {
|
|
79
|
+
(0, react_1.useEffect)(() => {
|
|
76
80
|
// Register with Drax context after we have an id.
|
|
77
81
|
registerView({ id, parentId, scrollPositionRef });
|
|
78
82
|
// Unregister when we unmount or id changes.
|
|
@@ -85,7 +89,7 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
85
89
|
unregisterView,
|
|
86
90
|
]);
|
|
87
91
|
// Combine hover styles for given internal render props.
|
|
88
|
-
const getCombinedHoverStyle = react_1.useCallback(({ viewState: { dragStatus }, trackingStatus: { receiving: anyReceiving }, hoverPosition, dimensions, }) => {
|
|
92
|
+
const getCombinedHoverStyle = (0, react_1.useCallback)(({ viewState: { dragStatus }, trackingStatus: { receiving: anyReceiving }, hoverPosition, dimensions, }) => {
|
|
89
93
|
// Start with base style, calculated dimensions, and hover base style.
|
|
90
94
|
const hoverStyles = [
|
|
91
95
|
style,
|
|
@@ -106,10 +110,10 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
106
110
|
hoverStyles.push(hoverDragReleasedStyle);
|
|
107
111
|
}
|
|
108
112
|
// Remove any layout styles.
|
|
109
|
-
const flattenedHoverStyle = transform_1.flattenStylesWithoutLayout(hoverStyles);
|
|
113
|
+
const flattenedHoverStyle = (0, transform_1.flattenStylesWithoutLayout)(hoverStyles);
|
|
110
114
|
// Apply hover transform.
|
|
111
115
|
const transform = hoverPosition.getTranslateTransform();
|
|
112
|
-
return transform_1.mergeStyleTransform(flattenedHoverStyle, transform);
|
|
116
|
+
return (0, transform_1.mergeStyleTransform)(flattenedHoverStyle, transform);
|
|
113
117
|
}, [
|
|
114
118
|
style,
|
|
115
119
|
hoverStyle,
|
|
@@ -119,7 +123,7 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
119
123
|
hoverDragReleasedStyle,
|
|
120
124
|
]);
|
|
121
125
|
// Internal render function for hover views, used in protocol by provider.
|
|
122
|
-
const internalRenderHoverView = react_1.useMemo(() => ((draggable && !noHover)
|
|
126
|
+
const internalRenderHoverView = (0, react_1.useMemo)(() => ((draggable && !noHover)
|
|
123
127
|
? (internalProps) => {
|
|
124
128
|
let content;
|
|
125
129
|
const render = renderHoverContent ?? renderContent;
|
|
@@ -136,7 +140,7 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
136
140
|
else {
|
|
137
141
|
content = children;
|
|
138
142
|
}
|
|
139
|
-
return (react_1.default.createElement(react_native_1.Animated.View,
|
|
143
|
+
return (react_1.default.createElement(react_native_1.Animated.View, { ...props, key: internalProps.key, style: getCombinedHoverStyle(internalProps) }, content));
|
|
140
144
|
}
|
|
141
145
|
: undefined), [
|
|
142
146
|
draggable,
|
|
@@ -148,7 +152,7 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
148
152
|
children,
|
|
149
153
|
]);
|
|
150
154
|
// Report updates to our protocol callbacks when we have an id and whenever the props change.
|
|
151
|
-
react_1.useEffect(() => {
|
|
155
|
+
(0, react_1.useEffect)(() => {
|
|
152
156
|
updateViewProtocol({
|
|
153
157
|
id,
|
|
154
158
|
protocol: {
|
|
@@ -221,17 +225,17 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
221
225
|
internalRenderHoverView,
|
|
222
226
|
]);
|
|
223
227
|
// Connect gesture state change handling into Drax context, tied to this id.
|
|
224
|
-
const onHandlerStateChange = react_1.useCallback(({ nativeEvent }) => handleGestureStateChange(id, nativeEvent), [id, handleGestureStateChange]);
|
|
228
|
+
const onHandlerStateChange = (0, react_1.useCallback)(({ nativeEvent }) => handleGestureStateChange(id, nativeEvent), [id, handleGestureStateChange]);
|
|
225
229
|
// Create throttled gesture event handler, tied to this id.
|
|
226
|
-
const throttledHandleGestureEvent = react_1.useMemo(() => lodash_throttle_1.default((event) => {
|
|
230
|
+
const throttledHandleGestureEvent = (0, react_1.useMemo)(() => (0, lodash_throttle_1.default)((event) => {
|
|
227
231
|
// Pass the event up to the Drax context.
|
|
228
232
|
handleGestureEvent(id, event);
|
|
229
233
|
}, 10), [id, handleGestureEvent]);
|
|
230
234
|
// Connect gesture event handling into Drax context, extracting nativeEvent.
|
|
231
|
-
const onGestureEvent = react_1.useCallback(({ nativeEvent }) => throttledHandleGestureEvent(nativeEvent), [throttledHandleGestureEvent]);
|
|
235
|
+
const onGestureEvent = (0, react_1.useCallback)(({ nativeEvent }) => throttledHandleGestureEvent(nativeEvent), [throttledHandleGestureEvent]);
|
|
232
236
|
// Build a callback which will report our measurements to Drax context,
|
|
233
237
|
// onMeasure, and an optional measurement handler.
|
|
234
|
-
const buildMeasureCallback = react_1.useCallback((measurementHandler) => ((x, y, width, height) => {
|
|
238
|
+
const buildMeasureCallback = (0, react_1.useCallback)((measurementHandler) => ((x, y, width, height) => {
|
|
235
239
|
/*
|
|
236
240
|
* In certain cases (on Android), all of these values can be
|
|
237
241
|
* undefined when the view is not on screen; This should not
|
|
@@ -253,10 +257,10 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
253
257
|
measurementHandler?.(measurements);
|
|
254
258
|
}), [id, updateViewMeasurements, onMeasure]);
|
|
255
259
|
// Callback which will report our measurements to Drax context and onMeasure.
|
|
256
|
-
const updateMeasurements = react_1.useMemo(() => buildMeasureCallback(), [buildMeasureCallback]);
|
|
260
|
+
const updateMeasurements = (0, react_1.useMemo)(() => buildMeasureCallback(), [buildMeasureCallback]);
|
|
257
261
|
// Measure and report our measurements to Drax context, onMeasure, and an
|
|
258
262
|
// optional measurement handler on demand.
|
|
259
|
-
const measureWithHandler = react_1.useCallback((measurementHandler) => {
|
|
263
|
+
const measureWithHandler = (0, react_1.useCallback)((measurementHandler) => {
|
|
260
264
|
const view = viewRef.current;
|
|
261
265
|
if (view) {
|
|
262
266
|
const nodeHandle = parentNodeHandleRef.current;
|
|
@@ -282,21 +286,21 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
282
286
|
updateMeasurements,
|
|
283
287
|
]);
|
|
284
288
|
// Measure and send our measurements to Drax context and onMeasure, used when this view finishes layout.
|
|
285
|
-
const onLayout = react_1.useCallback(() => {
|
|
289
|
+
const onLayout = (0, react_1.useCallback)(() => {
|
|
286
290
|
// console.log(`onLayout ${id}`);
|
|
287
291
|
measureWithHandler();
|
|
288
292
|
}, [measureWithHandler]);
|
|
289
293
|
// Establish dimensions/orientation change handler when necessary.
|
|
290
|
-
react_1.useEffect(() => {
|
|
294
|
+
(0, react_1.useEffect)(() => {
|
|
291
295
|
const handler = ( /* { screen: { width, height } }: { screen: ScaledSize } */) => {
|
|
292
296
|
// console.log(`Dimensions changed to ${width}/${height}`);
|
|
293
297
|
setTimeout(measureWithHandler, 100);
|
|
294
298
|
};
|
|
295
|
-
react_native_1.Dimensions.addEventListener('change', handler);
|
|
296
|
-
return () =>
|
|
299
|
+
const listener = react_native_1.Dimensions.addEventListener('change', handler);
|
|
300
|
+
return () => listener.remove();
|
|
297
301
|
}, [measureWithHandler]);
|
|
298
302
|
// Register and unregister externally when necessary.
|
|
299
|
-
react_1.useEffect(() => {
|
|
303
|
+
(0, react_1.useEffect)(() => {
|
|
300
304
|
if (registration) { // Register externally when registration is set.
|
|
301
305
|
registration({
|
|
302
306
|
id,
|
|
@@ -310,9 +314,9 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
310
314
|
const viewState = getViewState(id);
|
|
311
315
|
const trackingStatus = getTrackingStatus();
|
|
312
316
|
// Get full render props for non-hovering view content.
|
|
313
|
-
const getRenderContentProps = react_1.useCallback(() => {
|
|
317
|
+
const getRenderContentProps = (0, react_1.useCallback)(() => {
|
|
314
318
|
const measurements = measurementsRef.current;
|
|
315
|
-
const dimensions = measurements && math_1.extractDimensions(measurements);
|
|
319
|
+
const dimensions = measurements && (0, math_1.extractDimensions)(measurements);
|
|
316
320
|
return {
|
|
317
321
|
viewState,
|
|
318
322
|
trackingStatus,
|
|
@@ -326,7 +330,7 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
326
330
|
children,
|
|
327
331
|
]);
|
|
328
332
|
// Combined style for current render-related state.
|
|
329
|
-
const combinedStyle = react_1.useMemo(() => {
|
|
333
|
+
const combinedStyle = (0, react_1.useMemo)(() => {
|
|
330
334
|
const { dragStatus = types_1.DraxViewDragStatus.Inactive, receiveStatus = types_1.DraxViewReceiveStatus.Inactive, } = viewState ?? {};
|
|
331
335
|
const { dragging: anyDragging, receiving: anyReceiving, } = trackingStatus;
|
|
332
336
|
// Start with base style.
|
|
@@ -380,7 +384,7 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
380
384
|
otherDraggingWithoutReceiverStyle,
|
|
381
385
|
]);
|
|
382
386
|
// The rendered React children of this view.
|
|
383
|
-
const renderedChildren = react_1.useMemo(() => {
|
|
387
|
+
const renderedChildren = (0, react_1.useMemo)(() => {
|
|
384
388
|
let content;
|
|
385
389
|
if (renderContent) {
|
|
386
390
|
const renderContentProps = getRenderContentProps();
|
|
@@ -402,11 +406,11 @@ const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, on
|
|
|
402
406
|
id,
|
|
403
407
|
nodeHandleRef,
|
|
404
408
|
]);
|
|
405
|
-
const setViewRefs = react_1.useCallback((ref) => {
|
|
409
|
+
const setViewRefs = (0, react_1.useCallback)((ref) => {
|
|
406
410
|
viewRef.current = ref;
|
|
407
|
-
nodeHandleRef.current = ref && react_native_1.findNodeHandle(ref);
|
|
411
|
+
nodeHandleRef.current = ref && (0, react_native_1.findNodeHandle)(ref);
|
|
408
412
|
}, []);
|
|
409
413
|
return (react_1.default.createElement(react_native_gesture_handler_1.LongPressGestureHandler, { maxDist: Number.MAX_SAFE_INTEGER, shouldCancelWhenOutside: false, minDurationMs: longPressDelay, onHandlerStateChange: onHandlerStateChange, onGestureEvent: onGestureEvent /* Workaround incorrect typings. */, enabled: draggable },
|
|
410
|
-
react_1.default.createElement(react_native_1.Animated.View,
|
|
414
|
+
react_1.default.createElement(react_native_1.Animated.View, { ...props, style: combinedStyle, ref: setViewRefs, onLayout: onLayout, collapsable: false }, renderedChildren)));
|
|
411
415
|
};
|
|
412
416
|
exports.DraxView = DraxView;
|
|
@@ -4,7 +4,7 @@ exports.useDraxContext = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const DraxContext_1 = require("../DraxContext");
|
|
6
6
|
const useDraxContext = () => {
|
|
7
|
-
const drax = react_1.useContext(DraxContext_1.DraxContext);
|
|
7
|
+
const drax = (0, react_1.useContext)(DraxContext_1.DraxContext);
|
|
8
8
|
if (!drax) {
|
|
9
9
|
throw Error('No DraxProvider found');
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useDraxId: (explicitId?: string
|
|
1
|
+
export declare const useDraxId: (explicitId?: string) => string;
|
package/build/hooks/useDraxId.js
CHANGED
|
@@ -6,7 +6,7 @@ const math_1 = require("../math");
|
|
|
6
6
|
// Return explicitId, or a consistent randomly generated identifier if explicitId is falsy.
|
|
7
7
|
const useDraxId = (explicitId) => {
|
|
8
8
|
// A generated unique identifier for this view, for use if id prop is not specified.
|
|
9
|
-
const [randomId] = react_1.useState(math_1.generateRandomId);
|
|
9
|
+
const [randomId] = (0, react_1.useState)(math_1.generateRandomId);
|
|
10
10
|
// We use || rather than ?? for the return value in case explicitId is an empty string.
|
|
11
11
|
return explicitId || randomId;
|
|
12
12
|
};
|
|
@@ -55,7 +55,7 @@ export declare const useDraxRegistry: (stateDispatch: DraxStateDispatch) => {
|
|
|
55
55
|
updateViewProtocol: (payload: UpdateViewProtocolPayload) => void;
|
|
56
56
|
updateViewMeasurements: (payload: UpdateViewMeasurementsPayload) => void;
|
|
57
57
|
resetReceiver: () => void;
|
|
58
|
-
resetDrag: (snapbackTarget?: DraxSnapbackTarget
|
|
58
|
+
resetDrag: (snapbackTarget?: DraxSnapbackTarget) => void;
|
|
59
59
|
startDrag: (payload: StartDragPayload) => {
|
|
60
60
|
dragAbsolutePosition: Position;
|
|
61
61
|
dragTranslation: {
|
|
@@ -57,7 +57,7 @@ const getAbsoluteMeasurementsForViewFromRegistry = (registry, { measurements, pa
|
|
|
57
57
|
x: parentX + x - offsetX,
|
|
58
58
|
y: parentY + y - offsetY,
|
|
59
59
|
};
|
|
60
|
-
return clipped ? math_1.clipMeasurements(abs, parentMeasurements) : abs;
|
|
60
|
+
return clipped ? (0, math_1.clipMeasurements)(abs, parentMeasurements) : abs;
|
|
61
61
|
};
|
|
62
62
|
/** Get data, including absolute measurements, for a registered view by its id. */
|
|
63
63
|
const getAbsoluteViewDataFromRegistry = (registry, id) => {
|
|
@@ -119,7 +119,7 @@ const findMonitorsAndReceiverInRegistry = (registry, absolutePosition, excludeVi
|
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
121
|
// console.log(`absolute measurements: ${JSON.stringify(absoluteMeasurements, null, 2)}`);
|
|
122
|
-
if (math_1.isPointInside(absolutePosition, absoluteMeasurements)) {
|
|
122
|
+
if ((0, math_1.isPointInside)(absolutePosition, absoluteMeasurements)) {
|
|
123
123
|
// Drag point is within this target.
|
|
124
124
|
const foundView = {
|
|
125
125
|
id: targetId,
|
|
@@ -128,7 +128,7 @@ const findMonitorsAndReceiverInRegistry = (registry, absolutePosition, excludeVi
|
|
|
128
128
|
measurements: target.measurements,
|
|
129
129
|
absoluteMeasurements,
|
|
130
130
|
},
|
|
131
|
-
...math_1.getRelativePosition(absolutePosition, absoluteMeasurements),
|
|
131
|
+
...(0, math_1.getRelativePosition)(absolutePosition, absoluteMeasurements),
|
|
132
132
|
};
|
|
133
133
|
if (monitoring) {
|
|
134
134
|
// Add it to the list of monitors.
|
|
@@ -199,7 +199,7 @@ const getHoverItemsFromRegistry = (registry) => {
|
|
|
199
199
|
internalRenderHoverView,
|
|
200
200
|
key: releaseId,
|
|
201
201
|
id: viewId,
|
|
202
|
-
dimensions: math_1.extractDimensions(measurements),
|
|
202
|
+
dimensions: (0, math_1.extractDimensions)(measurements),
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -215,7 +215,7 @@ const getHoverItemsFromRegistry = (registry) => {
|
|
|
215
215
|
key: `dragged-hover-${draggedId}`,
|
|
216
216
|
id: draggedId,
|
|
217
217
|
hoverPosition: registry.drag.hoverPosition,
|
|
218
|
-
dimensions: math_1.extractDimensions(measurements),
|
|
218
|
+
dimensions: (0, math_1.extractDimensions)(measurements),
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
221
|
}
|
|
@@ -317,7 +317,7 @@ const resetReceiverInRegistry = ({ drag, stateDispatch }) => {
|
|
|
317
317
|
};
|
|
318
318
|
/** Track a new release, returning its unique identifier. */
|
|
319
319
|
const createReleaseInRegistry = (registry, release) => {
|
|
320
|
-
const releaseId = math_1.generateRandomId();
|
|
320
|
+
const releaseId = (0, math_1.generateRandomId)();
|
|
321
321
|
registry.releaseIds.push(releaseId);
|
|
322
322
|
registry.releaseById[releaseId] = release;
|
|
323
323
|
return releaseId;
|
|
@@ -345,7 +345,7 @@ const resetDragInRegistry = (registry, snapbackTarget = types_1.DraxSnapbackTarg
|
|
|
345
345
|
const { internalRenderHoverView, onSnapbackEnd, snapbackAnimator, animateSnapback = true, snapbackDelay = params_1.defaultSnapbackDelay, snapbackDuration = params_1.defaultSnapbackDuration, } = draggedData.protocol;
|
|
346
346
|
if (internalRenderHoverView && animateSnapback) {
|
|
347
347
|
let toValue;
|
|
348
|
-
if (types_1.isPosition(snapbackTarget)) {
|
|
348
|
+
if ((0, types_1.isPosition)(snapbackTarget)) {
|
|
349
349
|
// Snapback to specified target.
|
|
350
350
|
toValue = snapbackTarget;
|
|
351
351
|
}
|
|
@@ -590,9 +590,9 @@ const unregisterViewInRegistry = (registry, { id }) => {
|
|
|
590
590
|
/** Create a Drax registry and wire up all of the methods. */
|
|
591
591
|
const useDraxRegistry = (stateDispatch) => {
|
|
592
592
|
/** Registry for tracking views and drags. */
|
|
593
|
-
const registryRef = react_1.useRef(createInitialRegistry(stateDispatch));
|
|
593
|
+
const registryRef = (0, react_1.useRef)(createInitialRegistry(stateDispatch));
|
|
594
594
|
/** Ensure that the registry has the latest version of state dispatch, although it should never change. */
|
|
595
|
-
react_1.useEffect(() => {
|
|
595
|
+
(0, react_1.useEffect)(() => {
|
|
596
596
|
registryRef.current.stateDispatch = stateDispatch;
|
|
597
597
|
}, [stateDispatch]);
|
|
598
598
|
/**
|
|
@@ -601,61 +601,61 @@ const useDraxRegistry = (stateDispatch) => {
|
|
|
601
601
|
*
|
|
602
602
|
*/
|
|
603
603
|
/** Get data for a registered view by its id. */
|
|
604
|
-
const getViewData = react_1.useCallback((id) => getViewDataFromRegistry(registryRef.current, id), []);
|
|
604
|
+
const getViewData = (0, react_1.useCallback)((id) => getViewDataFromRegistry(registryRef.current, id), []);
|
|
605
605
|
/** Get data, including absolute measurements, for a registered view by its id. */
|
|
606
|
-
const getAbsoluteViewData = react_1.useCallback((id) => getAbsoluteViewDataFromRegistry(registryRef.current, id), []);
|
|
606
|
+
const getAbsoluteViewData = (0, react_1.useCallback)((id) => getAbsoluteViewDataFromRegistry(registryRef.current, id), []);
|
|
607
607
|
/** Get id and data for the currently dragged view, if any. */
|
|
608
|
-
const getTrackingDragged = react_1.useCallback(() => getTrackingDraggedFromRegistry(registryRef.current), []);
|
|
608
|
+
const getTrackingDragged = (0, react_1.useCallback)(() => getTrackingDraggedFromRegistry(registryRef.current), []);
|
|
609
609
|
/** Get id and data for the currently receiving view, if any. */
|
|
610
|
-
const getTrackingReceiver = react_1.useCallback(() => getTrackingReceiverFromRegistry(registryRef.current), []);
|
|
610
|
+
const getTrackingReceiver = (0, react_1.useCallback)(() => getTrackingReceiverFromRegistry(registryRef.current), []);
|
|
611
611
|
/** Get ids for all currently monitoring views. */
|
|
612
|
-
const getTrackingMonitorIds = react_1.useCallback(() => getTrackingMonitorIdsFromRegistry(registryRef.current), []);
|
|
612
|
+
const getTrackingMonitorIds = (0, react_1.useCallback)(() => getTrackingMonitorIdsFromRegistry(registryRef.current), []);
|
|
613
613
|
/** Get id and data for all currently monitoring views. */
|
|
614
|
-
const getTrackingMonitors = react_1.useCallback(() => getTrackingMonitorsFromRegistry(registryRef.current), []);
|
|
614
|
+
const getTrackingMonitors = (0, react_1.useCallback)(() => getTrackingMonitorsFromRegistry(registryRef.current), []);
|
|
615
615
|
/**
|
|
616
616
|
* Get the absolute position of a drag already in progress from touch
|
|
617
617
|
* coordinates within the immediate parent view of the dragged view.
|
|
618
618
|
*/
|
|
619
|
-
const getDragPositionData = react_1.useCallback((params) => (getDragPositionDataFromRegistry(registryRef.current, params)), []);
|
|
619
|
+
const getDragPositionData = (0, react_1.useCallback)((params) => (getDragPositionDataFromRegistry(registryRef.current, params)), []);
|
|
620
620
|
/**
|
|
621
621
|
* Find all monitoring views and the latest receptive view that
|
|
622
622
|
* contain the touch coordinates, excluding the specified view.
|
|
623
623
|
*/
|
|
624
|
-
const findMonitorsAndReceiver = react_1.useCallback((absolutePosition, excludeViewId) => (findMonitorsAndReceiverInRegistry(registryRef.current, absolutePosition, excludeViewId)), []);
|
|
624
|
+
const findMonitorsAndReceiver = (0, react_1.useCallback)((absolutePosition, excludeViewId) => (findMonitorsAndReceiverInRegistry(registryRef.current, absolutePosition, excludeViewId)), []);
|
|
625
625
|
/** Get the array of hover items for dragged and released views */
|
|
626
|
-
const getHoverItems = react_1.useCallback(() => getHoverItemsFromRegistry(registryRef.current), []);
|
|
626
|
+
const getHoverItems = (0, react_1.useCallback)(() => getHoverItemsFromRegistry(registryRef.current), []);
|
|
627
627
|
/**
|
|
628
628
|
*
|
|
629
629
|
* Imperative methods without state reactions (data management only).
|
|
630
630
|
*
|
|
631
631
|
*/
|
|
632
632
|
/** Update a view's protocol callbacks/data. */
|
|
633
|
-
const updateViewProtocol = react_1.useCallback((payload) => updateViewProtocolInRegistry(registryRef.current, payload), []);
|
|
633
|
+
const updateViewProtocol = (0, react_1.useCallback)((payload) => updateViewProtocolInRegistry(registryRef.current, payload), []);
|
|
634
634
|
/** Update a view's measurements. */
|
|
635
|
-
const updateViewMeasurements = react_1.useCallback((payload) => updateViewMeasurementsInRegistry(registryRef.current, payload), []);
|
|
635
|
+
const updateViewMeasurements = (0, react_1.useCallback)((payload) => updateViewMeasurementsInRegistry(registryRef.current, payload), []);
|
|
636
636
|
/**
|
|
637
637
|
*
|
|
638
638
|
* Imperative methods with potential state reactions.
|
|
639
639
|
*
|
|
640
640
|
*/
|
|
641
641
|
/** Register a Drax view. */
|
|
642
|
-
const registerView = react_1.useCallback((payload) => registerViewInRegistry(registryRef.current, payload), []);
|
|
642
|
+
const registerView = (0, react_1.useCallback)((payload) => registerViewInRegistry(registryRef.current, payload), []);
|
|
643
643
|
/** Reset the receiver in drag tracking, if any. */
|
|
644
|
-
const resetReceiver = react_1.useCallback(() => resetReceiverInRegistry(registryRef.current), []);
|
|
644
|
+
const resetReceiver = (0, react_1.useCallback)(() => resetReceiverInRegistry(registryRef.current), []);
|
|
645
645
|
/** Reset drag tracking, if any. */
|
|
646
|
-
const resetDrag = react_1.useCallback((snapbackTarget) => resetDragInRegistry(registryRef.current, snapbackTarget), []);
|
|
646
|
+
const resetDrag = (0, react_1.useCallback)((snapbackTarget) => resetDragInRegistry(registryRef.current, snapbackTarget), []);
|
|
647
647
|
/** Start tracking a drag. */
|
|
648
|
-
const startDrag = react_1.useCallback((payload) => startDragInRegistry(registryRef.current, payload), []);
|
|
648
|
+
const startDrag = (0, react_1.useCallback)((payload) => startDragInRegistry(registryRef.current, payload), []);
|
|
649
649
|
/** Update drag position. */
|
|
650
|
-
const updateDragPosition = react_1.useCallback((dragAbsolutePosition) => (updateDragPositionInRegistry(registryRef.current, dragAbsolutePosition)), []);
|
|
650
|
+
const updateDragPosition = (0, react_1.useCallback)((dragAbsolutePosition) => (updateDragPositionInRegistry(registryRef.current, dragAbsolutePosition)), []);
|
|
651
651
|
/** Update the receiver for a drag. */
|
|
652
|
-
const updateReceiver = react_1.useCallback((receiver, dragged) => (updateReceiverInRegistry(registryRef.current, receiver, dragged)), []);
|
|
652
|
+
const updateReceiver = (0, react_1.useCallback)((receiver, dragged) => (updateReceiverInRegistry(registryRef.current, receiver, dragged)), []);
|
|
653
653
|
/** Set the monitors for a drag. */
|
|
654
|
-
const setMonitorIds = react_1.useCallback((monitorIds) => setMonitorIdsInRegistry(registryRef.current, monitorIds), []);
|
|
654
|
+
const setMonitorIds = (0, react_1.useCallback)((monitorIds) => setMonitorIdsInRegistry(registryRef.current, monitorIds), []);
|
|
655
655
|
/** Unregister a Drax view. */
|
|
656
|
-
const unregisterView = react_1.useCallback((payload) => unregisterViewInRegistry(registryRef.current, payload), []);
|
|
656
|
+
const unregisterView = (0, react_1.useCallback)((payload) => unregisterViewInRegistry(registryRef.current, payload), []);
|
|
657
657
|
/** Create the Drax registry object for return, only replacing reference when necessary. */
|
|
658
|
-
const draxRegistry = react_1.useMemo(() => ({
|
|
658
|
+
const draxRegistry = (0, react_1.useMemo)(() => ({
|
|
659
659
|
getViewData,
|
|
660
660
|
getAbsoluteViewData,
|
|
661
661
|
getTrackingDragged,
|
|
@@ -35,15 +35,15 @@ const selectViewState = (state, id) => (id === undefined ? undefined : state.vie
|
|
|
35
35
|
const selectTrackingStatus = (state) => state.trackingStatus;
|
|
36
36
|
/** Collection of Drax action creators */
|
|
37
37
|
exports.actions = {
|
|
38
|
-
createViewState: typesafe_actions_1.createAction('createViewState')(),
|
|
39
|
-
updateViewState: typesafe_actions_1.createAction('updateViewState')(),
|
|
40
|
-
deleteViewState: typesafe_actions_1.createAction('deleteViewState')(),
|
|
41
|
-
updateTrackingStatus: typesafe_actions_1.createAction('updateTrackingStatus')(),
|
|
38
|
+
createViewState: (0, typesafe_actions_1.createAction)('createViewState')(),
|
|
39
|
+
updateViewState: (0, typesafe_actions_1.createAction)('updateViewState')(),
|
|
40
|
+
deleteViewState: (0, typesafe_actions_1.createAction)('deleteViewState')(),
|
|
41
|
+
updateTrackingStatus: (0, typesafe_actions_1.createAction)('updateTrackingStatus')(),
|
|
42
42
|
};
|
|
43
43
|
/** The DraxState reducer. */
|
|
44
44
|
const reducer = (state, action) => {
|
|
45
45
|
switch (action.type) {
|
|
46
|
-
case typesafe_actions_1.getType(exports.actions.createViewState): {
|
|
46
|
+
case (0, typesafe_actions_1.getType)(exports.actions.createViewState): {
|
|
47
47
|
const { id } = action.payload;
|
|
48
48
|
const viewState = selectViewState(state, id);
|
|
49
49
|
if (viewState) {
|
|
@@ -57,7 +57,7 @@ const reducer = (state, action) => {
|
|
|
57
57
|
},
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
case typesafe_actions_1.getType(exports.actions.updateViewState): {
|
|
60
|
+
case (0, typesafe_actions_1.getType)(exports.actions.updateViewState): {
|
|
61
61
|
const { id, viewStateUpdate } = action.payload;
|
|
62
62
|
const viewState = selectViewState(state, id);
|
|
63
63
|
if (viewState) {
|
|
@@ -65,7 +65,7 @@ const reducer = (state, action) => {
|
|
|
65
65
|
...viewState,
|
|
66
66
|
...viewStateUpdate,
|
|
67
67
|
};
|
|
68
|
-
if (lodash_isequal_1.default(viewState, newViewState)) {
|
|
68
|
+
if ((0, lodash_isequal_1.default)(viewState, newViewState)) {
|
|
69
69
|
return state;
|
|
70
70
|
}
|
|
71
71
|
return {
|
|
@@ -78,7 +78,7 @@ const reducer = (state, action) => {
|
|
|
78
78
|
}
|
|
79
79
|
return state;
|
|
80
80
|
}
|
|
81
|
-
case typesafe_actions_1.getType(exports.actions.deleteViewState): {
|
|
81
|
+
case (0, typesafe_actions_1.getType)(exports.actions.deleteViewState): {
|
|
82
82
|
const { id } = action.payload;
|
|
83
83
|
const { [id]: removed, ...viewStateById } = state.viewStateById;
|
|
84
84
|
if (removed) {
|
|
@@ -89,7 +89,7 @@ const reducer = (state, action) => {
|
|
|
89
89
|
}
|
|
90
90
|
return state;
|
|
91
91
|
}
|
|
92
|
-
case typesafe_actions_1.getType(exports.actions.updateTrackingStatus): {
|
|
92
|
+
case (0, typesafe_actions_1.getType)(exports.actions.updateTrackingStatus): {
|
|
93
93
|
return {
|
|
94
94
|
...state,
|
|
95
95
|
trackingStatus: {
|
|
@@ -105,13 +105,13 @@ const reducer = (state, action) => {
|
|
|
105
105
|
/** Create a Drax state and wire up its methods. */
|
|
106
106
|
const useDraxState = () => {
|
|
107
107
|
/** Reducer for storing view states and tracking status. */
|
|
108
|
-
const [state, dispatch] = react_1.useReducer(reducer, undefined, createInitialState);
|
|
108
|
+
const [state, dispatch] = (0, react_1.useReducer)(reducer, undefined, createInitialState);
|
|
109
109
|
/** Get state for a view by its id. */
|
|
110
|
-
const getViewState = react_1.useCallback((id) => selectViewState(state, id), [state]);
|
|
110
|
+
const getViewState = (0, react_1.useCallback)((id) => selectViewState(state, id), [state]);
|
|
111
111
|
/** Get the current tracking status. */
|
|
112
|
-
const getTrackingStatus = react_1.useCallback(() => selectTrackingStatus(state), [state]);
|
|
112
|
+
const getTrackingStatus = (0, react_1.useCallback)(() => selectTrackingStatus(state), [state]);
|
|
113
113
|
/** Create the Drax state object for return, only replacing reference when necessary. */
|
|
114
|
-
const draxState = react_1.useMemo(() => ({
|
|
114
|
+
const draxState = (0, react_1.useMemo)(() => ({
|
|
115
115
|
getViewState,
|
|
116
116
|
getTrackingStatus,
|
|
117
117
|
dispatch,
|
package/build/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/build/transform.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
1
|
+
import { Animated, StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
import { AnimatedViewStyleWithoutLayout } from './types';
|
|
3
|
+
export declare const flattenStylesWithoutLayout: (styles: StyleProp<Animated.WithAnimatedValue<ViewStyle>>[]) => AnimatedViewStyleWithoutLayout;
|
|
4
|
+
export declare const mergeStyleTransform: (style: AnimatedViewStyleWithoutLayout, transform: Animated.WithAnimatedValue<ViewStyle['transform']>) => AnimatedViewStyleWithoutLayout;
|
package/build/types.d.ts
CHANGED
|
@@ -463,7 +463,9 @@ export interface DraxContextValue {
|
|
|
463
463
|
}
|
|
464
464
|
/** Optional props that can be passed to a DraxProvider to modify its behavior */
|
|
465
465
|
export interface DraxProviderProps {
|
|
466
|
+
style?: StyleProp<ViewStyle>;
|
|
466
467
|
debug?: boolean;
|
|
468
|
+
children?: ReactNode;
|
|
467
469
|
}
|
|
468
470
|
/** Props that are passed to a DraxSubprovider, used internally for nesting views */
|
|
469
471
|
export interface DraxSubproviderProps {
|
|
@@ -482,44 +484,30 @@ export interface DraxParentView {
|
|
|
482
484
|
/** Ref to node handle of the parent, for measuring relative to */
|
|
483
485
|
nodeHandleRef: RefObject<number | null>;
|
|
484
486
|
}
|
|
485
|
-
/** Type augmentation to allow an animated value */
|
|
486
|
-
declare type MaybeAnimated<T> = T | Animated.Value;
|
|
487
|
-
/** Scalar type that can be replaced by an animated value */
|
|
488
|
-
declare type AnimatedScalar = string | number;
|
|
489
|
-
/** Type augmentation to allow a style to support animated values */
|
|
490
|
-
export declare type AnimatedStyle<T> = {
|
|
491
|
-
[Key in keyof T]: T[Key] extends AnimatedScalar ? MaybeAnimated<T[Key]> : T[Key] extends Array<infer U> ? Array<AnimatedStyle<U>> : AnimatedStyle<T[Key]>;
|
|
492
|
-
};
|
|
493
|
-
/** Style for an Animated.View */
|
|
494
|
-
export declare type AnimatedViewStyle = AnimatedStyle<ViewStyle>;
|
|
495
|
-
/** Style prop for an Animated.View */
|
|
496
|
-
export declare type AnimatedViewStyleProp = StyleProp<AnimatedViewStyle>;
|
|
497
|
-
/** Helper type for coercing the output of Animated.ValueXY.getTranslateTransform() */
|
|
498
|
-
export declare type AnimatedTransform = AnimatedStyle<ViewStyle['transform']>;
|
|
499
487
|
/** Function that receives a Drax view measurement */
|
|
500
488
|
export interface DraxViewMeasurementHandler {
|
|
501
489
|
(measurements: DraxViewMeasurements | undefined): void;
|
|
502
490
|
}
|
|
503
491
|
/** Layout-related style keys that are omitted from hover view styles */
|
|
504
492
|
export declare type LayoutStyleKey = ('margin' | 'marginHorizontal' | 'marginVertical' | 'marginLeft' | 'marginRight' | 'marginTop' | 'marginBottom' | 'marginStart' | 'marginEnd' | 'left' | 'right' | 'top' | 'bottom' | 'flex' | 'flexBasis' | 'flexDirection' | 'flexGrow' | 'flexShrink');
|
|
505
|
-
/** Style for
|
|
506
|
-
export declare type AnimatedViewStyleWithoutLayout = Omit<
|
|
507
|
-
/** Style prop for
|
|
493
|
+
/** Style for a Animated.View used for a hover view */
|
|
494
|
+
export declare type AnimatedViewStyleWithoutLayout = Omit<Animated.WithAnimatedValue<ViewStyle>, LayoutStyleKey>;
|
|
495
|
+
/** Style prop for a Animated.View used for a hover view */
|
|
508
496
|
export declare type AnimatedViewStylePropWithoutLayout = StyleProp<AnimatedViewStyleWithoutLayout>;
|
|
509
497
|
/** Style-related props for a Drax view */
|
|
510
498
|
export interface DraxViewStyleProps {
|
|
511
499
|
/** Custom style prop to allow animated values */
|
|
512
|
-
style?:
|
|
500
|
+
style?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
513
501
|
/** Additional view style applied while this view is not being dragged or released */
|
|
514
|
-
dragInactiveStyle?:
|
|
502
|
+
dragInactiveStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
515
503
|
/** Additional view style applied while this view is being dragged */
|
|
516
|
-
draggingStyle?:
|
|
504
|
+
draggingStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
517
505
|
/** Additional view style applied while this view is being dragged over a receiver */
|
|
518
|
-
draggingWithReceiverStyle?:
|
|
506
|
+
draggingWithReceiverStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
519
507
|
/** Additional view style applied while this view is being dragged NOT over a receiver */
|
|
520
|
-
draggingWithoutReceiverStyle?:
|
|
508
|
+
draggingWithoutReceiverStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
521
509
|
/** Additional view style applied while this view has just been released from a drag */
|
|
522
|
-
dragReleasedStyle?:
|
|
510
|
+
dragReleasedStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
523
511
|
/** Additional view style applied to the hovering copy of this view during drag/release */
|
|
524
512
|
hoverStyle?: AnimatedViewStylePropWithoutLayout;
|
|
525
513
|
/** Additional view style applied to the hovering copy of this view while dragging */
|
|
@@ -531,15 +519,15 @@ export interface DraxViewStyleProps {
|
|
|
531
519
|
/** Additional view style applied to the hovering copy of this view when just released */
|
|
532
520
|
hoverDragReleasedStyle?: AnimatedViewStylePropWithoutLayout;
|
|
533
521
|
/** Additional view style applied while this view is not receiving a drag */
|
|
534
|
-
receiverInactiveStyle?:
|
|
522
|
+
receiverInactiveStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
535
523
|
/** Additional view style applied while this view is receiving a drag */
|
|
536
|
-
receivingStyle?:
|
|
524
|
+
receivingStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
537
525
|
/** Additional view style applied to this view while any other view is being dragged */
|
|
538
|
-
otherDraggingStyle?:
|
|
526
|
+
otherDraggingStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
539
527
|
/** Additional view style applied to this view while any other view is being dragged over a receiver */
|
|
540
|
-
otherDraggingWithReceiverStyle?:
|
|
528
|
+
otherDraggingWithReceiverStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
541
529
|
/** Additional view style applied to this view while any other view is being dragged NOT over a receiver */
|
|
542
|
-
otherDraggingWithoutReceiverStyle?:
|
|
530
|
+
otherDraggingWithoutReceiverStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
|
|
543
531
|
}
|
|
544
532
|
/** Custom render function for content of a DraxView */
|
|
545
533
|
export interface DraxViewRenderContent {
|
|
@@ -666,4 +654,3 @@ export interface DraxListProps<TItem> extends Omit<FlatListProps<TItem>, 'render
|
|
|
666
654
|
/** Function that receives an item and returns a list of DraxViewProps to apply to that item's DraxView */
|
|
667
655
|
viewPropsExtractor?: (item: TItem) => Partial<DraxViewProps>;
|
|
668
656
|
}
|
|
669
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-drax",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "A drag-and-drop system for React Native",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "*",
|
|
25
|
-
"react-native": ">=0.
|
|
25
|
+
"react-native": ">=0.65.0",
|
|
26
26
|
"react-native-gesture-handler": ">=1.8.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/lodash.isequal": "^4.5.5",
|
|
30
30
|
"@types/lodash.throttle": "^4.1.6",
|
|
31
31
|
"@types/node": "^14.14.43",
|
|
32
|
-
"@types/react-native": "^0.
|
|
32
|
+
"@types/react-native": "^0.65.22",
|
|
33
33
|
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
|
34
34
|
"@typescript-eslint/parser": "^4.22.0",
|
|
35
35
|
"eslint": "^7.25.0",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
41
41
|
"eslint-plugin-react-native": "^3.10.0",
|
|
42
42
|
"react": "^17.0.2",
|
|
43
|
-
"react-native": "^0.
|
|
43
|
+
"react-native": "^0.65.2",
|
|
44
44
|
"react-native-gesture-handler": "^1.8.0",
|
|
45
|
-
"typescript": "^4.
|
|
45
|
+
"typescript": "^4.7.3"
|
|
46
46
|
}
|
|
47
47
|
}
|