react-native-drax 0.10.3 → 0.11.0-alpha.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.
Files changed (47) hide show
  1. package/.eslintrc.js +2 -73
  2. package/.prettierrc +16 -0
  3. package/README.md +81 -1
  4. package/build/AllHoverViews.d.ts +0 -0
  5. package/build/AllHoverViews.js +30 -0
  6. package/build/DraxContext.d.ts +0 -1
  7. package/build/DraxList.d.ts +3 -3
  8. package/build/DraxList.js +231 -216
  9. package/build/DraxListItem.d.ts +7 -0
  10. package/build/DraxListItem.js +121 -0
  11. package/build/DraxProvider.d.ts +1 -3
  12. package/build/DraxProvider.js +322 -259
  13. package/build/DraxScrollView.d.ts +1 -1
  14. package/build/DraxScrollView.js +29 -90
  15. package/build/DraxSubprovider.d.ts +2 -2
  16. package/build/DraxSubprovider.js +1 -1
  17. package/build/DraxView.d.ts +7 -2
  18. package/build/DraxView.js +60 -383
  19. package/build/HoverView.d.ts +8 -0
  20. package/build/HoverView.js +40 -0
  21. package/build/PanGestureDetector.d.ts +3 -0
  22. package/build/PanGestureDetector.js +49 -0
  23. package/build/hooks/useContent.d.ts +23 -0
  24. package/build/hooks/useContent.js +212 -0
  25. package/build/hooks/useDraxProtocol.d.ts +5 -0
  26. package/build/hooks/useDraxProtocol.js +32 -0
  27. package/build/hooks/useDraxRegistry.d.ts +21 -20
  28. package/build/hooks/useDraxRegistry.js +195 -182
  29. package/build/hooks/useDraxScrollHandler.d.ts +25 -0
  30. package/build/hooks/useDraxScrollHandler.js +89 -0
  31. package/build/hooks/useDraxState.d.ts +1 -1
  32. package/build/hooks/useDraxState.js +9 -6
  33. package/build/hooks/useMeasurements.d.ts +9 -0
  34. package/build/hooks/useMeasurements.js +119 -0
  35. package/build/hooks/useStatus.d.ts +11 -0
  36. package/build/hooks/useStatus.js +96 -0
  37. package/build/index.d.ts +2 -0
  38. package/build/index.js +4 -1
  39. package/build/math.d.ts +2 -2
  40. package/build/math.js +10 -6
  41. package/build/params.d.ts +9 -0
  42. package/build/params.js +7 -1
  43. package/build/transform.d.ts +11 -4
  44. package/build/transform.js +50 -8
  45. package/build/types.d.ts +238 -87
  46. package/build/types.js +10 -7
  47. package/package.json +43 -45
package/build/DraxView.js CHANGED
@@ -22,395 +22,72 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.DraxView = void 0;
26
+ exports.DraxReanimatedView = exports.DraxView = void 0;
30
27
  const react_1 = __importStar(require("react"));
31
- const react_native_1 = require("react-native");
32
- const react_native_gesture_handler_1 = require("react-native-gesture-handler");
33
- const lodash_throttle_1 = __importDefault(require("lodash.throttle"));
28
+ const react_native_reanimated_1 = __importStar(require("react-native-reanimated"));
29
+ const PanGestureDetector_1 = require("./PanGestureDetector");
34
30
  const hooks_1 = require("./hooks");
35
- const types_1 = require("./types");
36
- const params_1 = require("./params");
31
+ const useContent_1 = require("./hooks/useContent");
32
+ const useDraxProtocol_1 = require("./hooks/useDraxProtocol");
33
+ const useMeasurements_1 = require("./hooks/useMeasurements");
37
34
  const math_1 = require("./math");
38
- const DraxSubprovider_1 = require("./DraxSubprovider");
39
- const transform_1 = require("./transform");
40
- const DraxView = ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, onDragEnd, onDragDrop, onSnapbackEnd, onReceiveDragEnter, onReceiveDragOver, onReceiveDragExit, onReceiveDragDrop, onMonitorDragStart, onMonitorDragEnter, onMonitorDragOver, onMonitorDragExit, onMonitorDragEnd, onMonitorDragDrop, animateSnapback, snapbackDelay, snapbackDuration, snapbackAnimator, payload, dragPayload, receiverPayload, style, dragInactiveStyle, draggingStyle, draggingWithReceiverStyle, draggingWithoutReceiverStyle, dragReleasedStyle, hoverStyle, hoverDraggingStyle, hoverDraggingWithReceiverStyle, hoverDraggingWithoutReceiverStyle, hoverDragReleasedStyle, receiverInactiveStyle, receivingStyle, otherDraggingStyle, otherDraggingWithReceiverStyle, otherDraggingWithoutReceiverStyle, renderContent, renderHoverContent, registration, onMeasure, scrollPositionRef, lockDragXPosition, lockDragYPosition, children, noHover = false, isParent = false, longPressDelay = params_1.defaultLongPressDelay, id: idProp, parent: parentProp, draggable: draggableProp, receptive: receptiveProp, monitoring: monitoringProp, ...props }) => {
35
+ const params_1 = require("./params");
36
+ exports.DraxView = (0, react_1.memo)((props) => {
41
37
  // Coalesce protocol props into capabilities.
42
- const draggable = draggableProp ?? (dragPayload !== undefined
43
- || payload !== undefined
44
- || !!onDrag
45
- || !!onDragEnd
46
- || !!onDragEnter
47
- || !!onDragExit
48
- || !!onDragOver
49
- || !!onDragStart
50
- || !!onDragDrop);
51
- const receptive = receptiveProp ?? (receiverPayload !== undefined
52
- || payload !== undefined
53
- || !!onReceiveDragEnter
54
- || !!onReceiveDragExit
55
- || !!onReceiveDragOver
56
- || !!onReceiveDragDrop);
57
- const monitoring = monitoringProp ?? (!!onMonitorDragStart
58
- || !!onMonitorDragEnter
59
- || !!onMonitorDragOver
60
- || !!onMonitorDragExit
61
- || !!onMonitorDragEnd
62
- || !!onMonitorDragDrop);
38
+ const draggable = props.draggable ??
39
+ (props.dragPayload !== undefined ||
40
+ props.payload !== undefined ||
41
+ !!props.onDrag ||
42
+ !!props.onDragEnd ||
43
+ !!props.onDragEnter ||
44
+ !!props.onDragExit ||
45
+ !!props.onDragOver ||
46
+ !!props.onDragStart ||
47
+ !!props.onDragDrop);
48
+ const receptive = props.receptive ??
49
+ (props.receiverPayload !== undefined ||
50
+ props.payload !== undefined ||
51
+ !!props.onReceiveDragEnter ||
52
+ !!props.onReceiveDragExit ||
53
+ !!props.onReceiveDragOver ||
54
+ !!props.onReceiveDragDrop);
55
+ const monitoring = props.monitoring ??
56
+ (!!props.onMonitorDragStart ||
57
+ !!props.onMonitorDragEnter ||
58
+ !!props.onMonitorDragOver ||
59
+ !!props.onMonitorDragExit ||
60
+ !!props.onMonitorDragEnd ||
61
+ !!props.onMonitorDragDrop);
63
62
  // The unique identifier for this view.
64
- const id = (0, hooks_1.useDraxId)(idProp);
65
- // The underlying View, for measuring.
66
- const viewRef = (0, react_1.useRef)(null);
67
- // The underlying View node handle, used for subprovider nesting if this is a Drax parent view.
68
- const nodeHandleRef = (0, react_1.useRef)(null);
69
- // This view's measurements, for reference.
70
- const measurementsRef = (0, react_1.useRef)(undefined);
71
- // Connect with Drax.
72
- const { getViewState, getTrackingStatus, registerView, unregisterView, updateViewProtocol, updateViewMeasurements, handleGestureEvent, handleGestureStateChange, rootNodeHandleRef, parent: contextParent, } = (0, hooks_1.useDraxContext)();
73
- // Identify Drax parent view (if any) from context or prop override.
74
- const parent = parentProp ?? contextParent;
75
- const parentId = parent?.id;
76
- // Identify parent node handle ref.
77
- const parentNodeHandleRef = parent ? parent.nodeHandleRef : rootNodeHandleRef;
78
- // Register and unregister with Drax context when necessary.
63
+ const id = (0, hooks_1.useDraxId)(props.id);
64
+ return (react_1.default.createElement(PanGestureDetector_1.PanGestureDetector, { id: id, draggable: draggable, longPressDelay: props.longPressDelay ?? params_1.defaultLongPressDelay },
65
+ react_1.default.createElement(exports.DraxReanimatedView, { id: id, ...props, draggable: draggable, receptive: receptive, monitoring: monitoring })));
66
+ });
67
+ exports.DraxReanimatedView = (0, react_1.memo)((props) => {
68
+ const hoverPosition = (0, react_native_reanimated_1.useSharedValue)({ x: 0, y: 0 });
69
+ const updateViewProtocol = (0, useDraxProtocol_1.useDraxProtocol)(props, hoverPosition);
70
+ const { registerView, unregisterView } = (0, hooks_1.useDraxContext)();
71
+ const { onLayout, viewRef, measureWithHandler } = (0, useMeasurements_1.useMeasurements)(props);
72
+ const { combinedStyle, renderedChildren } = (0, useContent_1.useContent)({
73
+ draxViewProps: { ...props, hoverPosition },
74
+ viewRef,
75
+ });
79
76
  (0, react_1.useEffect)(() => {
80
- // Register with Drax context after we have an id.
81
- registerView({ id, parentId, scrollPositionRef });
82
- // Unregister when we unmount or id changes.
83
- return () => unregisterView({ id });
84
- }, [
85
- id,
86
- parentId,
87
- scrollPositionRef,
88
- registerView,
89
- unregisterView,
90
- ]);
91
- // Combine hover styles for given internal render props.
92
- const getCombinedHoverStyle = (0, react_1.useCallback)(({ viewState: { dragStatus }, trackingStatus: { receiving: anyReceiving }, hoverPosition, dimensions, }) => {
93
- // Start with base style, calculated dimensions, and hover base style.
94
- const hoverStyles = [
95
- style,
96
- dimensions,
97
- hoverStyle,
98
- ];
99
- // Apply style style overrides based on state.
100
- if (dragStatus === types_1.DraxViewDragStatus.Dragging) {
101
- hoverStyles.push(hoverDraggingStyle);
102
- if (anyReceiving) {
103
- hoverStyles.push(hoverDraggingWithReceiverStyle);
104
- }
105
- else {
106
- hoverStyles.push(hoverDraggingWithoutReceiverStyle);
107
- }
108
- }
109
- else if (dragStatus === types_1.DraxViewDragStatus.Released) {
110
- hoverStyles.push(hoverDragReleasedStyle);
111
- }
112
- // Remove any layout styles.
113
- const flattenedHoverStyle = (0, transform_1.flattenStylesWithoutLayout)(hoverStyles);
114
- // Apply hover transform.
115
- const transform = hoverPosition.getTranslateTransform();
116
- return (0, transform_1.mergeStyleTransform)(flattenedHoverStyle, transform);
117
- }, [
118
- style,
119
- hoverStyle,
120
- hoverDraggingStyle,
121
- hoverDraggingWithReceiverStyle,
122
- hoverDraggingWithoutReceiverStyle,
123
- hoverDragReleasedStyle,
124
- ]);
125
- // Internal render function for hover views, used in protocol by provider.
126
- const internalRenderHoverView = (0, react_1.useMemo)(() => ((draggable && !noHover)
127
- ? (internalProps) => {
128
- let content;
129
- const render = renderHoverContent ?? renderContent;
130
- if (render) {
131
- const renderProps = {
132
- children,
133
- hover: true,
134
- viewState: internalProps.viewState,
135
- trackingStatus: internalProps.trackingStatus,
136
- dimensions: internalProps.dimensions,
137
- };
138
- content = render(renderProps);
139
- }
140
- else {
141
- content = children;
142
- }
143
- return (react_1.default.createElement(react_native_1.Animated.View, { ...props, key: internalProps.key, style: getCombinedHoverStyle(internalProps) }, content));
144
- }
145
- : undefined), [
146
- draggable,
147
- noHover,
148
- renderHoverContent,
149
- renderContent,
150
- getCombinedHoverStyle,
151
- props,
152
- children,
153
- ]);
154
- // Report updates to our protocol callbacks when we have an id and whenever the props change.
77
+ /** @todo 🪲BUG:
78
+ * For some reason, the Staging zone from the ColorDragDrop example loses its measurements,
79
+ * and we need to force refresh on them */
80
+ measureWithHandler?.();
81
+ }, [combinedStyle]);
155
82
  (0, react_1.useEffect)(() => {
156
- updateViewProtocol({
157
- id,
158
- protocol: {
159
- onDragStart,
160
- onDrag,
161
- onDragEnter,
162
- onDragOver,
163
- onDragExit,
164
- onDragEnd,
165
- onDragDrop,
166
- onSnapbackEnd,
167
- onReceiveDragEnter,
168
- onReceiveDragOver,
169
- onReceiveDragExit,
170
- onReceiveDragDrop,
171
- onMonitorDragStart,
172
- onMonitorDragEnter,
173
- onMonitorDragOver,
174
- onMonitorDragExit,
175
- onMonitorDragEnd,
176
- onMonitorDragDrop,
177
- animateSnapback,
178
- snapbackDelay,
179
- snapbackDuration,
180
- snapbackAnimator,
181
- internalRenderHoverView,
182
- draggable,
183
- receptive,
184
- monitoring,
185
- lockDragXPosition,
186
- lockDragYPosition,
187
- dragPayload: dragPayload ?? payload,
188
- receiverPayload: receiverPayload ?? payload,
189
- },
190
- });
191
- }, [
192
- id,
193
- updateViewProtocol,
194
- children,
195
- onDragStart,
196
- onDrag,
197
- onDragEnter,
198
- onDragOver,
199
- onDragExit,
200
- onDragEnd,
201
- onDragDrop,
202
- onSnapbackEnd,
203
- onReceiveDragEnter,
204
- onReceiveDragOver,
205
- onReceiveDragExit,
206
- onReceiveDragDrop,
207
- onMonitorDragStart,
208
- onMonitorDragEnter,
209
- onMonitorDragOver,
210
- onMonitorDragExit,
211
- onMonitorDragEnd,
212
- onMonitorDragDrop,
213
- animateSnapback,
214
- snapbackDelay,
215
- snapbackDuration,
216
- snapbackAnimator,
217
- payload,
218
- dragPayload,
219
- receiverPayload,
220
- draggable,
221
- receptive,
222
- monitoring,
223
- lockDragXPosition,
224
- lockDragYPosition,
225
- internalRenderHoverView,
226
- ]);
227
- // Connect gesture state change handling into Drax context, tied to this id.
228
- const onHandlerStateChange = (0, react_1.useCallback)(({ nativeEvent }) => handleGestureStateChange(id, nativeEvent), [id, handleGestureStateChange]);
229
- // Create throttled gesture event handler, tied to this id.
230
- const throttledHandleGestureEvent = (0, react_1.useMemo)(() => (0, lodash_throttle_1.default)((event) => {
231
- // Pass the event up to the Drax context.
232
- handleGestureEvent(id, event);
233
- }, 10), [id, handleGestureEvent]);
234
- // Connect gesture event handling into Drax context, extracting nativeEvent.
235
- const onGestureEvent = (0, react_1.useCallback)(({ nativeEvent }) => throttledHandleGestureEvent(nativeEvent), [throttledHandleGestureEvent]);
236
- // Build a callback which will report our measurements to Drax context,
237
- // onMeasure, and an optional measurement handler.
238
- const buildMeasureCallback = (0, react_1.useCallback)((measurementHandler) => ((x, y, width, height) => {
239
- /*
240
- * In certain cases (on Android), all of these values can be
241
- * undefined when the view is not on screen; This should not
242
- * happen with the measurement functions we're using, but just
243
- * for the sake of paranoia, we'll check and use undefined
244
- * for the entire measurements object.
83
+ /** @todo 🪲BUG:
84
+ * Ugly hack to update hover views.
85
+ * Mostly useful when their props change and we need a forced refresh
245
86
  */
246
- const measurements = (height === undefined
247
- ? undefined
248
- : {
249
- height,
250
- x: x,
251
- y: y,
252
- width: width,
253
- });
254
- measurementsRef.current = measurements;
255
- updateViewMeasurements({ id, measurements });
256
- onMeasure?.(measurements);
257
- measurementHandler?.(measurements);
258
- }), [id, updateViewMeasurements, onMeasure]);
259
- // Callback which will report our measurements to Drax context and onMeasure.
260
- const updateMeasurements = (0, react_1.useMemo)(() => buildMeasureCallback(), [buildMeasureCallback]);
261
- // Measure and report our measurements to Drax context, onMeasure, and an
262
- // optional measurement handler on demand.
263
- const measureWithHandler = (0, react_1.useCallback)((measurementHandler) => {
264
- const view = viewRef.current;
265
- if (view) {
266
- const nodeHandle = parentNodeHandleRef.current;
267
- if (nodeHandle) {
268
- const measureCallback = measurementHandler
269
- ? buildMeasureCallback(measurementHandler)
270
- : updateMeasurements;
271
- // console.log('definitely measuring in reference to something');
272
- view.measureLayout(nodeHandle, measureCallback, () => {
273
- // console.log('Failed to measure Drax view in relation to parent nodeHandle');
274
- });
275
- }
276
- else {
277
- // console.log('No parent nodeHandle to measure Drax view in relation to');
278
- }
279
- }
280
- else {
281
- // console.log('No view to measure');
282
- }
283
- }, [
284
- parentNodeHandleRef,
285
- buildMeasureCallback,
286
- updateMeasurements,
287
- ]);
288
- // Measure and send our measurements to Drax context and onMeasure, used when this view finishes layout.
289
- const onLayout = (0, react_1.useCallback)(() => {
290
- // console.log(`onLayout ${id}`);
291
- measureWithHandler();
292
- }, [measureWithHandler]);
293
- // Establish dimensions/orientation change handler when necessary.
294
- (0, react_1.useEffect)(() => {
295
- const handler = ( /* { screen: { width, height } }: { screen: ScaledSize } */) => {
296
- // console.log(`Dimensions changed to ${width}/${height}`);
297
- setTimeout(measureWithHandler, 100);
298
- };
299
- const listener = react_native_1.Dimensions.addEventListener('change', handler);
300
- return () => listener.remove();
301
- }, [measureWithHandler]);
302
- // Register and unregister externally when necessary.
303
- (0, react_1.useEffect)(() => {
304
- if (registration) { // Register externally when registration is set.
305
- registration({
306
- id,
307
- measure: measureWithHandler,
308
- });
309
- return () => registration(undefined); // Unregister when we unmount or registration changes.
310
- }
311
- return undefined;
312
- }, [id, registration, measureWithHandler]);
313
- // Get the render-related state for rendering.
314
- const viewState = getViewState(id);
315
- const trackingStatus = getTrackingStatus();
316
- // Get full render props for non-hovering view content.
317
- const getRenderContentProps = (0, react_1.useCallback)(() => {
318
- const measurements = measurementsRef.current;
319
- const dimensions = measurements && (0, math_1.extractDimensions)(measurements);
320
- return {
321
- viewState,
322
- trackingStatus,
323
- children,
324
- dimensions,
325
- hover: false,
326
- };
327
- }, [
328
- viewState,
329
- trackingStatus,
330
- children,
331
- ]);
332
- // Combined style for current render-related state.
333
- const combinedStyle = (0, react_1.useMemo)(() => {
334
- const { dragStatus = types_1.DraxViewDragStatus.Inactive, receiveStatus = types_1.DraxViewReceiveStatus.Inactive, } = viewState ?? {};
335
- const { dragging: anyDragging, receiving: anyReceiving, } = trackingStatus;
336
- // Start with base style.
337
- const styles = [style];
338
- // Apply style overrides for drag state.
339
- if (dragStatus === types_1.DraxViewDragStatus.Dragging) {
340
- styles.push(draggingStyle);
341
- if (anyReceiving) {
342
- styles.push(draggingWithReceiverStyle);
343
- }
344
- else {
345
- styles.push(draggingWithoutReceiverStyle);
346
- }
347
- }
348
- else if (dragStatus === types_1.DraxViewDragStatus.Released) {
349
- styles.push(dragReleasedStyle);
350
- }
351
- else {
352
- styles.push(dragInactiveStyle);
353
- if (anyDragging) {
354
- styles.push(otherDraggingStyle);
355
- if (anyReceiving) {
356
- styles.push(otherDraggingWithReceiverStyle);
357
- }
358
- else {
359
- styles.push(otherDraggingWithoutReceiverStyle);
360
- }
361
- }
362
- }
363
- // Apply style overrides for receiving state.
364
- if (receiveStatus === types_1.DraxViewReceiveStatus.Receiving) {
365
- styles.push(receivingStyle);
366
- }
367
- else {
368
- styles.push(receiverInactiveStyle);
369
- }
370
- return react_native_1.StyleSheet.flatten(styles);
371
- }, [
372
- viewState,
373
- trackingStatus,
374
- style,
375
- dragInactiveStyle,
376
- draggingStyle,
377
- draggingWithReceiverStyle,
378
- draggingWithoutReceiverStyle,
379
- dragReleasedStyle,
380
- receivingStyle,
381
- receiverInactiveStyle,
382
- otherDraggingStyle,
383
- otherDraggingWithReceiverStyle,
384
- otherDraggingWithoutReceiverStyle,
385
- ]);
386
- // The rendered React children of this view.
387
- const renderedChildren = (0, react_1.useMemo)(() => {
388
- let content;
389
- if (renderContent) {
390
- const renderContentProps = getRenderContentProps();
391
- content = renderContent(renderContentProps);
392
- }
393
- else {
394
- content = children;
395
- }
396
- if (isParent) {
397
- // This is a Drax parent, so wrap children in subprovider.
398
- content = (react_1.default.createElement(DraxSubprovider_1.DraxSubprovider, { parent: { id, nodeHandleRef } }, content));
399
- }
400
- return content;
401
- }, [
402
- renderContent,
403
- getRenderContentProps,
404
- children,
405
- isParent,
406
- id,
407
- nodeHandleRef,
408
- ]);
409
- const setViewRefs = (0, react_1.useCallback)((ref) => {
410
- viewRef.current = ref;
411
- nodeHandleRef.current = ref && (0, react_native_1.findNodeHandle)(ref);
412
- }, []);
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 },
414
- react_1.default.createElement(react_native_1.Animated.View, { ...props, style: combinedStyle, ref: setViewRefs, onLayout: onLayout, collapsable: false }, renderedChildren)));
415
- };
416
- exports.DraxView = DraxView;
87
+ updateViewProtocol();
88
+ const fakeId = (0, math_1.generateRandomId)();
89
+ registerView({ id: fakeId });
90
+ unregisterView({ id: fakeId });
91
+ }, [updateViewProtocol, registerView, unregisterView]);
92
+ return (react_1.default.createElement(react_native_reanimated_1.default.View, { ...props, style: combinedStyle, ref: viewRef, onLayout: onLayout, collapsable: false }, renderedChildren));
93
+ });
@@ -0,0 +1,8 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { SharedValue } from 'react-native-reanimated';
3
+ import { TReanimatedHoverViewProps, Position } from './types';
4
+ export declare const HoverView: ({ children, hoverPosition, renderHoverContent, renderContent, scrollPosition, ...props }: Omit<PropsWithChildren<TReanimatedHoverViewProps>, "internalProps"> & {
5
+ id: string;
6
+ hoverPosition: SharedValue<Position>;
7
+ scrollPositionOffset?: Position;
8
+ }) => React.JSX.Element | null;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HoverView = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const react_native_1 = require("react-native");
9
+ const react_native_reanimated_1 = __importDefault(require("react-native-reanimated"));
10
+ const hooks_1 = require("./hooks");
11
+ const useContent_1 = require("./hooks/useContent");
12
+ const types_1 = require("./types");
13
+ const HoverView = ({ children, hoverPosition, renderHoverContent, renderContent, scrollPosition, ...props }) => {
14
+ const { updateHoverViewMeasurements } = (0, hooks_1.useDraxContext)();
15
+ const { combinedStyle, animatedHoverStyle, renderedChildren, dragStatus } = (0, useContent_1.useContent)({
16
+ draxViewProps: {
17
+ children,
18
+ hoverPosition,
19
+ renderHoverContent,
20
+ renderContent,
21
+ scrollPosition,
22
+ ...props,
23
+ },
24
+ });
25
+ if (!(props.draggable && !props.noHover)) {
26
+ return null;
27
+ }
28
+ if (dragStatus === types_1.DraxViewDragStatus.Inactive || typeof dragStatus === 'undefined') {
29
+ return null;
30
+ }
31
+ return (react_1.default.createElement(react_native_reanimated_1.default.View, { style: [react_native_1.StyleSheet.absoluteFill, animatedHoverStyle], pointerEvents: "none" },
32
+ react_1.default.createElement(react_native_1.View, { pointerEvents: "none", onLayout: measurements => {
33
+ !props?.disableHoverViewMeasurementsOnLayout &&
34
+ updateHoverViewMeasurements({
35
+ id: props.id,
36
+ measurements: { ...measurements.nativeEvent.layout },
37
+ });
38
+ }, style: [react_native_1.StyleSheet.absoluteFill, combinedStyle] }, renderedChildren)));
39
+ };
40
+ exports.HoverView = HoverView;
@@ -0,0 +1,3 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { TPanGestureDetectorProps } from './types';
3
+ export declare const PanGestureDetector: React.MemoExoticComponent<({ id, children, longPressDelay, draggable }: PropsWithChildren<TPanGestureDetectorProps>) => React.JSX.Element>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.PanGestureDetector = void 0;
27
+ const react_1 = __importStar(require("react"));
28
+ const react_native_gesture_handler_1 = require("react-native-gesture-handler");
29
+ const react_native_reanimated_1 = require("react-native-reanimated");
30
+ const hooks_1 = require("./hooks");
31
+ exports.PanGestureDetector = (0, react_1.memo)(({ id, children, longPressDelay, draggable }) => {
32
+ // Connect with Drax.
33
+ const { handleGestureEvent, handleGestureStateChange } = (0, hooks_1.useDraxContext)();
34
+ const gesture = (0, react_1.useMemo)(() => draggable &&
35
+ react_native_gesture_handler_1.Gesture.Pan()
36
+ .onBegin(handleGestureStateChange(id))
37
+ .onStart(handleGestureStateChange(id))
38
+ .onUpdate(event => (0, react_native_reanimated_1.runOnUI)(handleGestureEvent)(id, event))
39
+ .onEnd(handleGestureStateChange(id))
40
+ .shouldCancelWhenOutside(false)
41
+ .activateAfterLongPress(longPressDelay)
42
+ .enabled(draggable)
43
+ .maxPointers(1)
44
+ .runOnJS(true), [handleGestureStateChange, id, longPressDelay, draggable, handleGestureEvent]);
45
+ if (!draggable || !gesture) {
46
+ return react_1.default.createElement(react_1.default.Fragment, null, children);
47
+ }
48
+ return react_1.default.createElement(react_native_gesture_handler_1.GestureDetector, { gesture: gesture }, children);
49
+ });
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import Reanimated, { AnimatedRef, SharedValue } from 'react-native-reanimated';
3
+ import { DraxViewDragStatus, DraxViewProps, Position } from '../types';
4
+ export declare const useContent: ({ draxViewProps: { id, style, dragInactiveStyle, draggingStyle, draggingWithReceiverStyle, draggingWithoutReceiverStyle, dragReleasedStyle, otherDraggingStyle, otherDraggingWithReceiverStyle, otherDraggingWithoutReceiverStyle, receiverInactiveStyle, receivingStyle, children, renderContent, renderHoverContent, isParent, scrollPositionOffset, ...props }, viewRef, }: {
5
+ draxViewProps: DraxViewProps & {
6
+ id: string;
7
+ hoverPosition: SharedValue<Position>;
8
+ scrollPositionOffset?: Position;
9
+ };
10
+ /** The ref of the view being dragged. If it's a HoverView, this will be undefined */
11
+ viewRef?: AnimatedRef<Reanimated.View>;
12
+ }) => {
13
+ renderedChildren: React.ReactNode;
14
+ combinedStyle: import("../types").AnimatedViewStyleWithoutLayout;
15
+ animatedHoverStyle: {
16
+ opacity?: undefined;
17
+ transform?: undefined;
18
+ } | {
19
+ opacity: number;
20
+ transform: any[];
21
+ };
22
+ dragStatus: DraxViewDragStatus;
23
+ };