react-native-drax 0.11.0-alpha.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +390 -227
- package/lib/module/DebugOverlay.js +121 -0
- package/lib/module/DebugOverlay.js.map +1 -0
- package/lib/module/Drax.js +36 -0
- package/lib/module/Drax.js.map +1 -0
- package/lib/module/DraxContext.js +6 -0
- package/lib/module/DraxContext.js.map +1 -0
- package/lib/module/DraxHandle.js +47 -0
- package/lib/module/DraxHandle.js.map +1 -0
- package/lib/module/DraxHandleContext.js +11 -0
- package/lib/module/DraxHandleContext.js.map +1 -0
- package/lib/module/DraxList.js +108 -0
- package/lib/module/DraxList.js.map +1 -0
- package/lib/module/DraxProvider.js +203 -0
- package/lib/module/DraxProvider.js.map +1 -0
- package/lib/module/DraxScrollView.js +167 -0
- package/lib/module/DraxScrollView.js.map +1 -0
- package/lib/module/DraxSubprovider.js +21 -0
- package/lib/module/DraxSubprovider.js.map +1 -0
- package/lib/module/DraxView.js +348 -0
- package/lib/module/DraxView.js.map +1 -0
- package/lib/module/HoverLayer.js +152 -0
- package/lib/module/HoverLayer.js.map +1 -0
- package/lib/module/SortableBoardContainer.js +386 -0
- package/lib/module/SortableBoardContainer.js.map +1 -0
- package/lib/module/SortableBoardContext.js +6 -0
- package/lib/module/SortableBoardContext.js.map +1 -0
- package/lib/module/SortableContainer.js +571 -0
- package/lib/module/SortableContainer.js.map +1 -0
- package/lib/module/SortableItem.js +226 -0
- package/lib/module/SortableItem.js.map +1 -0
- package/lib/module/SortableItemContext.js +38 -0
- package/lib/module/SortableItemContext.js.map +1 -0
- package/lib/module/compat/detectVersion.js +19 -0
- package/lib/module/compat/detectVersion.js.map +1 -0
- package/lib/module/compat/index.js +5 -0
- package/lib/module/compat/index.js.map +1 -0
- package/lib/module/compat/types.js +4 -0
- package/lib/module/compat/types.js.map +1 -0
- package/lib/module/compat/useDraxPanGesture.js +94 -0
- package/lib/module/compat/useDraxPanGesture.js.map +1 -0
- package/lib/module/hooks/index.js +5 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useCallbackDispatch.js +688 -0
- package/lib/module/hooks/useCallbackDispatch.js.map +1 -0
- package/lib/module/hooks/useDragGesture.js +240 -0
- package/lib/module/hooks/useDragGesture.js.map +1 -0
- package/lib/module/hooks/useDraxContext.js +12 -0
- package/lib/module/hooks/useDraxContext.js.map +1 -0
- package/lib/module/hooks/useDraxId.js +13 -0
- package/lib/module/hooks/useDraxId.js.map +1 -0
- package/lib/module/hooks/useDraxMethods.js +73 -0
- package/lib/module/hooks/useDraxMethods.js.map +1 -0
- package/lib/module/hooks/useDraxScrollHandler.js +97 -0
- package/lib/module/hooks/useDraxScrollHandler.js.map +1 -0
- package/lib/module/hooks/useSortableBoard.js +37 -0
- package/lib/module/hooks/useSortableBoard.js.map +1 -0
- package/lib/module/hooks/useSortableList.js +988 -0
- package/lib/module/hooks/useSortableList.js.map +1 -0
- package/lib/module/hooks/useSpatialIndex.js +283 -0
- package/lib/module/hooks/useSpatialIndex.js.map +1 -0
- package/lib/module/hooks/useViewStyles.js +158 -0
- package/lib/module/hooks/useViewStyles.js.map +1 -0
- package/lib/module/hooks/useWebScrollFreeze.js +52 -0
- package/lib/module/hooks/useWebScrollFreeze.js.map +1 -0
- package/lib/module/index.js +37 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/math.js +294 -0
- package/lib/module/math.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/params.js +88 -0
- package/lib/module/params.js.map +1 -0
- package/lib/module/types.js +215 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/DebugOverlay.d.ts +17 -0
- package/lib/typescript/src/DebugOverlay.d.ts.map +1 -0
- package/lib/typescript/src/Drax.d.ts +28 -0
- package/lib/typescript/src/Drax.d.ts.map +1 -0
- package/lib/typescript/src/DraxContext.d.ts +3 -0
- package/lib/typescript/src/DraxContext.d.ts.map +1 -0
- package/lib/typescript/src/DraxHandle.d.ts +25 -0
- package/lib/typescript/src/DraxHandle.d.ts.map +1 -0
- package/lib/typescript/src/DraxHandleContext.d.ts +12 -0
- package/lib/typescript/src/DraxHandleContext.d.ts.map +1 -0
- package/lib/typescript/src/DraxList.d.ts +66 -0
- package/lib/typescript/src/DraxList.d.ts.map +1 -0
- package/lib/typescript/src/DraxProvider.d.ts +4 -0
- package/lib/typescript/src/DraxProvider.d.ts.map +1 -0
- package/lib/typescript/src/DraxScrollView.d.ts +7 -0
- package/lib/typescript/src/DraxScrollView.d.ts.map +1 -0
- package/lib/typescript/src/DraxSubprovider.d.ts +4 -0
- package/lib/typescript/src/DraxSubprovider.d.ts.map +1 -0
- package/lib/typescript/src/DraxView.d.ts +4 -0
- package/lib/typescript/src/DraxView.d.ts.map +1 -0
- package/lib/typescript/src/HoverLayer.d.ts +38 -0
- package/lib/typescript/src/HoverLayer.d.ts.map +1 -0
- package/lib/typescript/src/SortableBoardContainer.d.ts +11 -0
- package/lib/typescript/src/SortableBoardContainer.d.ts.map +1 -0
- package/lib/typescript/src/SortableBoardContext.d.ts +4 -0
- package/lib/typescript/src/SortableBoardContext.d.ts.map +1 -0
- package/lib/typescript/src/SortableContainer.d.ts +13 -0
- package/lib/typescript/src/SortableContainer.d.ts.map +1 -0
- package/lib/typescript/src/SortableItem.d.ts +14 -0
- package/lib/typescript/src/SortableItem.d.ts.map +1 -0
- package/lib/typescript/src/SortableItemContext.d.ts +37 -0
- package/lib/typescript/src/SortableItemContext.d.ts.map +1 -0
- package/lib/typescript/src/compat/detectVersion.d.ts +2 -0
- package/lib/typescript/src/compat/detectVersion.d.ts.map +1 -0
- package/lib/typescript/src/compat/index.d.ts +4 -0
- package/lib/typescript/src/compat/index.d.ts.map +1 -0
- package/lib/typescript/src/compat/types.d.ts +33 -0
- package/lib/typescript/src/compat/types.d.ts.map +1 -0
- package/lib/typescript/src/compat/useDraxPanGesture.d.ts +8 -0
- package/lib/typescript/src/compat/useDraxPanGesture.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +3 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCallbackDispatch.d.ts +40 -0
- package/lib/typescript/src/hooks/useCallbackDispatch.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDragGesture.d.ts +17 -0
- package/lib/typescript/src/hooks/useDragGesture.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDraxContext.d.ts +2 -0
- package/lib/typescript/src/hooks/useDraxContext.d.ts.map +1 -0
- package/{build → lib/typescript/src}/hooks/useDraxId.d.ts +1 -0
- package/lib/typescript/src/hooks/useDraxId.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDraxMethods.d.ts +13 -0
- package/lib/typescript/src/hooks/useDraxMethods.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDraxScrollHandler.d.ts +27 -0
- package/lib/typescript/src/hooks/useDraxScrollHandler.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSortableBoard.d.ts +10 -0
- package/lib/typescript/src/hooks/useSortableBoard.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSortableList.d.ts +11 -0
- package/lib/typescript/src/hooks/useSortableList.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSpatialIndex.d.ts +22 -0
- package/lib/typescript/src/hooks/useSpatialIndex.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useViewStyles.d.ts +183 -0
- package/lib/typescript/src/hooks/useViewStyles.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useWebScrollFreeze.d.ts +14 -0
- package/lib/typescript/src/hooks/useWebScrollFreeze.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +25 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/math.d.ts +76 -0
- package/lib/typescript/src/math.d.ts.map +1 -0
- package/{build → lib/typescript/src}/params.d.ts +13 -9
- package/lib/typescript/src/params.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +756 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +164 -34
- package/src/DebugOverlay.tsx +140 -0
- package/src/Drax.ts +33 -0
- package/src/DraxContext.ts +8 -0
- package/src/DraxHandle.tsx +52 -0
- package/src/DraxHandleContext.ts +15 -0
- package/src/DraxList.tsx +181 -0
- package/src/DraxProvider.tsx +224 -0
- package/src/DraxScrollView.tsx +180 -0
- package/src/DraxSubprovider.tsx +22 -0
- package/src/DraxView.tsx +430 -0
- package/src/HoverLayer.tsx +167 -0
- package/src/SortableBoardContainer.tsx +439 -0
- package/src/SortableBoardContext.ts +6 -0
- package/src/SortableContainer.tsx +650 -0
- package/src/SortableItem.tsx +264 -0
- package/src/SortableItemContext.ts +46 -0
- package/src/compat/detectVersion.ts +17 -0
- package/src/compat/index.ts +7 -0
- package/src/compat/types.ts +35 -0
- package/src/compat/useDraxPanGesture.ts +112 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useCallbackDispatch.tsx +830 -0
- package/src/hooks/useDragGesture.ts +273 -0
- package/src/hooks/useDraxContext.ts +11 -0
- package/src/hooks/useDraxId.ts +11 -0
- package/src/hooks/useDraxMethods.ts +71 -0
- package/src/hooks/useDraxScrollHandler.ts +121 -0
- package/src/hooks/useSortableBoard.ts +44 -0
- package/src/hooks/useSortableList.ts +1063 -0
- package/src/hooks/useSpatialIndex.ts +336 -0
- package/src/hooks/useViewStyles.ts +180 -0
- package/src/hooks/useWebScrollFreeze.ts +60 -0
- package/src/index.ts +111 -0
- package/src/math.ts +333 -0
- package/src/params.ts +74 -0
- package/src/types.ts +933 -0
- package/.editorconfig +0 -15
- package/.eslintrc.js +0 -4
- package/.prettierrc +0 -16
- package/CHANGELOG.md +0 -270
- package/CODE-OF-CONDUCT.md +0 -85
- package/CONTRIBUTING.md +0 -15
- package/FUNDING.yml +0 -4
- package/build/AllHoverViews.d.ts +0 -0
- package/build/AllHoverViews.js +0 -30
- package/build/DraxContext.d.ts +0 -2
- package/build/DraxContext.js +0 -6
- package/build/DraxList.d.ts +0 -8
- package/build/DraxList.js +0 -512
- package/build/DraxListItem.d.ts +0 -7
- package/build/DraxListItem.js +0 -121
- package/build/DraxProvider.d.ts +0 -2
- package/build/DraxProvider.js +0 -704
- package/build/DraxScrollView.d.ts +0 -6
- package/build/DraxScrollView.js +0 -136
- package/build/DraxSubprovider.d.ts +0 -3
- package/build/DraxSubprovider.js +0 -18
- package/build/DraxView.d.ts +0 -8
- package/build/DraxView.js +0 -93
- package/build/HoverView.d.ts +0 -8
- package/build/HoverView.js +0 -40
- package/build/PanGestureDetector.d.ts +0 -3
- package/build/PanGestureDetector.js +0 -49
- package/build/hooks/index.d.ts +0 -4
- package/build/hooks/index.js +0 -11
- package/build/hooks/useContent.d.ts +0 -23
- package/build/hooks/useContent.js +0 -212
- package/build/hooks/useDraxContext.d.ts +0 -1
- package/build/hooks/useDraxContext.js +0 -13
- package/build/hooks/useDraxId.js +0 -13
- package/build/hooks/useDraxProtocol.d.ts +0 -5
- package/build/hooks/useDraxProtocol.js +0 -32
- package/build/hooks/useDraxRegistry.d.ts +0 -78
- package/build/hooks/useDraxRegistry.js +0 -714
- package/build/hooks/useDraxScrollHandler.d.ts +0 -25
- package/build/hooks/useDraxScrollHandler.js +0 -89
- package/build/hooks/useDraxState.d.ts +0 -10
- package/build/hooks/useDraxState.js +0 -132
- package/build/hooks/useMeasurements.d.ts +0 -9
- package/build/hooks/useMeasurements.js +0 -119
- package/build/hooks/useStatus.d.ts +0 -11
- package/build/hooks/useStatus.js +0 -96
- package/build/index.d.ts +0 -9
- package/build/index.js +0 -33
- package/build/math.d.ts +0 -22
- package/build/math.js +0 -68
- package/build/params.js +0 -27
- package/build/transform.d.ts +0 -11
- package/build/transform.js +0 -59
- package/build/types.d.ts +0 -807
- package/build/types.js +0 -46
- package/docs/concept.md +0 -79
- package/docs/images/color-drag-drop.gif +0 -0
- package/docs/images/deck-cards.gif +0 -0
- package/docs/images/drag-drop-events.jpg +0 -0
- package/docs/images/knight-moves.gif +0 -0
- package/docs/images/reorderable-list.gif +0 -0
package/build/DraxProvider.js
DELETED
|
@@ -1,704 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.DraxProvider = void 0;
|
|
30
|
-
const lodash_throttle_1 = __importDefault(require("lodash.throttle"));
|
|
31
|
-
const react_1 = __importStar(require("react"));
|
|
32
|
-
const react_native_1 = require("react-native");
|
|
33
|
-
const react_native_gesture_handler_1 = require("react-native-gesture-handler");
|
|
34
|
-
const react_native_reanimated_1 = require("react-native-reanimated");
|
|
35
|
-
const DraxContext_1 = require("./DraxContext");
|
|
36
|
-
const HoverView_1 = require("./HoverView");
|
|
37
|
-
const hooks_1 = require("./hooks");
|
|
38
|
-
const math_1 = require("./math");
|
|
39
|
-
const types_1 = require("./types");
|
|
40
|
-
const startPositionInitialValue = {
|
|
41
|
-
parent: { x: 0, y: 0 },
|
|
42
|
-
grab: { x: 0, y: 0 },
|
|
43
|
-
};
|
|
44
|
-
const DraxProvider = ({ debug = false, style = styles.provider, children }) => {
|
|
45
|
-
const { getViewState, getTrackingStatus, getAllViewIds, dispatch } = (0, hooks_1.useDraxState)();
|
|
46
|
-
const { getAbsoluteViewData, getTrackingDragged, getTrackingReceiver, getTrackingMonitorIds, getTrackingMonitors, getDragPositionData, findMonitorsAndReceiver, getHoverItems, registerView, updateViewProtocol, updateViewMeasurements, updateHoverViewMeasurements, resetReceiver, resetDrag, startDrag, updateDragPosition, updateReceiver, setMonitorIds, unregisterView, getReleaseViews, } = (0, hooks_1.useDraxRegistry)(dispatch);
|
|
47
|
-
const rootViewRef = (0, react_1.useRef)(null);
|
|
48
|
-
const dragPositionDataSV = (0, react_native_reanimated_1.useSharedValue)(undefined);
|
|
49
|
-
const startPosition = (0, react_native_reanimated_1.useSharedValue)(startPositionInitialValue);
|
|
50
|
-
const parentPosition = (0, react_native_reanimated_1.useSharedValue)({ x: 0, y: 0 });
|
|
51
|
-
const checkForReceiver = (0, react_1.useCallback)((dragPositionData) => {
|
|
52
|
-
// Find which monitors and receiver this drag is over.
|
|
53
|
-
const dragged = getTrackingDragged();
|
|
54
|
-
if (dragged && dragPositionData) {
|
|
55
|
-
const { dragAbsolutePosition, dragTranslationRatio, dragTranslation } = dragPositionData;
|
|
56
|
-
const { monitors, receiver } = findMonitorsAndReceiver(dragAbsolutePosition, dragged.id);
|
|
57
|
-
// Get the previous receiver, if any.
|
|
58
|
-
const oldReceiver = getTrackingReceiver();
|
|
59
|
-
/*
|
|
60
|
-
* Consider the following cases for new and old receiver ids:
|
|
61
|
-
* Case 1: new exists, old exists, new is the same as old
|
|
62
|
-
* Case 2: new exists, old exists, new is different from old
|
|
63
|
-
* Case 3: new exists, old does not exist
|
|
64
|
-
* Case 4: new does not exist, old exists
|
|
65
|
-
* Case 5: new does not exist, old does not exist
|
|
66
|
-
*/
|
|
67
|
-
const draggedProtocol = dragged.data.protocol;
|
|
68
|
-
// Prepare event data for dragged view.
|
|
69
|
-
const eventDataDragged = {
|
|
70
|
-
dragTranslationRatio,
|
|
71
|
-
id: dragged.id,
|
|
72
|
-
parentId: dragged.data.parentId,
|
|
73
|
-
payload: dragged.data.protocol.dragPayload,
|
|
74
|
-
dragOffset: dragged.tracking.dragOffset,
|
|
75
|
-
grabOffset: dragged.tracking.grabOffset,
|
|
76
|
-
grabOffsetRatio: dragged.tracking.grabOffsetRatio,
|
|
77
|
-
hoverPosition: dragged.tracking.hoverPosition.value,
|
|
78
|
-
data: dragged.data,
|
|
79
|
-
};
|
|
80
|
-
// Prepare base drag event data.
|
|
81
|
-
const dragEventData = {
|
|
82
|
-
dragAbsolutePosition,
|
|
83
|
-
dragTranslation,
|
|
84
|
-
dragged: eventDataDragged,
|
|
85
|
-
};
|
|
86
|
-
// Prepare event data stub for monitor updates later so we can optionally add receiver.
|
|
87
|
-
const monitorEventDataStub = {
|
|
88
|
-
...dragEventData,
|
|
89
|
-
};
|
|
90
|
-
if (receiver) {
|
|
91
|
-
// New receiver exists.
|
|
92
|
-
const receiverProtocol = receiver.data.protocol;
|
|
93
|
-
// Update the receiver.
|
|
94
|
-
const trackingReceiver = updateReceiver(receiver, dragged);
|
|
95
|
-
if (trackingReceiver === undefined) {
|
|
96
|
-
// This should never happen, but just in case.
|
|
97
|
-
// if (debug) {
|
|
98
|
-
// console.log('Failed to update tracking receiver');
|
|
99
|
-
// }
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
// Prepare event data for receiver view.
|
|
103
|
-
const eventDataReceiver = {
|
|
104
|
-
id: receiver.id,
|
|
105
|
-
parentId: receiver.data.parentId,
|
|
106
|
-
payload: receiver.data.protocol.receiverPayload,
|
|
107
|
-
receiveOffset: trackingReceiver.receiveOffset,
|
|
108
|
-
receiveOffsetRatio: trackingReceiver.receiveOffsetRatio,
|
|
109
|
-
data: receiver.data,
|
|
110
|
-
};
|
|
111
|
-
// Add receiver data to monitor event stub.
|
|
112
|
-
monitorEventDataStub.receiver = eventDataReceiver;
|
|
113
|
-
// Prepare event data for callbacks.
|
|
114
|
-
const eventData = {
|
|
115
|
-
...dragEventData,
|
|
116
|
-
receiver: eventDataReceiver,
|
|
117
|
-
};
|
|
118
|
-
if (oldReceiver) {
|
|
119
|
-
if (receiver.id === oldReceiver.id) {
|
|
120
|
-
// Case 1: new exists, old exists, new is the same as old
|
|
121
|
-
// Call the protocol event callbacks for dragging over the receiver.
|
|
122
|
-
draggedProtocol.onDragOver?.(eventData);
|
|
123
|
-
receiverProtocol.onReceiveDragOver?.(eventData);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
// Case 2: new exists, old exists, new is different from old
|
|
127
|
-
// Prepare event data with old receiver.
|
|
128
|
-
const eventDataOldReceiver = {
|
|
129
|
-
...dragEventData,
|
|
130
|
-
receiver: {
|
|
131
|
-
id: oldReceiver.id,
|
|
132
|
-
parentId: oldReceiver.data.parentId,
|
|
133
|
-
payload: oldReceiver.data.protocol.receiverPayload,
|
|
134
|
-
receiveOffset: oldReceiver.tracking.receiveOffset,
|
|
135
|
-
receiveOffsetRatio: oldReceiver.tracking.receiveOffsetRatio,
|
|
136
|
-
data: oldReceiver.data,
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
// Call the protocol event callbacks for exiting the old receiver...
|
|
140
|
-
draggedProtocol.onDragExit?.(eventDataOldReceiver);
|
|
141
|
-
const endEventDataOldReceiver = {
|
|
142
|
-
...eventDataOldReceiver,
|
|
143
|
-
cancelled: false,
|
|
144
|
-
};
|
|
145
|
-
oldReceiver.data.protocol.onReceiveDragExit?.(endEventDataOldReceiver);
|
|
146
|
-
// ...and entering the new receiver.
|
|
147
|
-
draggedProtocol.onDragEnter?.(eventData);
|
|
148
|
-
receiverProtocol.onReceiveDragEnter?.(eventData);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
// Case 3: new exists, old does not exist
|
|
153
|
-
// Call the protocol event callbacks for entering the new receiver.
|
|
154
|
-
draggedProtocol.onDragEnter?.(eventData);
|
|
155
|
-
receiverProtocol.onReceiveDragEnter?.(eventData);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else if (oldReceiver) {
|
|
159
|
-
// Case 4: new does not exist, old exists
|
|
160
|
-
// Reset the old receiver.
|
|
161
|
-
resetReceiver();
|
|
162
|
-
// Prepare event data with old receiver.
|
|
163
|
-
const eventData = {
|
|
164
|
-
...dragEventData,
|
|
165
|
-
receiver: {
|
|
166
|
-
id: oldReceiver.id,
|
|
167
|
-
parentId: oldReceiver.data.parentId,
|
|
168
|
-
payload: oldReceiver.data.protocol.receiverPayload,
|
|
169
|
-
receiveOffset: oldReceiver.tracking.receiveOffset,
|
|
170
|
-
receiveOffsetRatio: oldReceiver.tracking.receiveOffsetRatio,
|
|
171
|
-
data: oldReceiver.data,
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
// Call the protocol event callbacks for exiting the old receiver.
|
|
175
|
-
draggedProtocol.onDragExit?.(eventData);
|
|
176
|
-
const receiveEventData = {
|
|
177
|
-
...eventData,
|
|
178
|
-
cancelled: false,
|
|
179
|
-
};
|
|
180
|
-
oldReceiver.data.protocol.onReceiveDragExit?.(receiveEventData);
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
// Case 5: new does not exist, old does not exist
|
|
184
|
-
// Call the protocol event callback for dragging.
|
|
185
|
-
draggedProtocol.onDrag?.(dragEventData);
|
|
186
|
-
}
|
|
187
|
-
// Notify monitors and update monitor tracking, if necessary.
|
|
188
|
-
const prevMonitorIds = getTrackingMonitorIds();
|
|
189
|
-
if (monitors.length > 0 || prevMonitorIds.length > 0) {
|
|
190
|
-
const newMonitorIds = monitors.map(({ id: monitorId, data: monitorData, relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio, }) => {
|
|
191
|
-
const monitorEventData = {
|
|
192
|
-
...monitorEventDataStub,
|
|
193
|
-
monitorOffset,
|
|
194
|
-
monitorOffsetRatio,
|
|
195
|
-
};
|
|
196
|
-
if (prevMonitorIds.includes(monitorId)) {
|
|
197
|
-
// Drag was already over this monitor.
|
|
198
|
-
monitorData.protocol.onMonitorDragOver?.(monitorEventData);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
// Drag is entering monitor.
|
|
202
|
-
monitorData.protocol.onMonitorDragEnter?.(monitorEventData);
|
|
203
|
-
}
|
|
204
|
-
return monitorId;
|
|
205
|
-
});
|
|
206
|
-
prevMonitorIds
|
|
207
|
-
.filter(monitorId => !newMonitorIds.includes(monitorId))
|
|
208
|
-
.forEach(monitorId => {
|
|
209
|
-
// Drag has exited monitor.
|
|
210
|
-
const monitorData = getAbsoluteViewData(monitorId);
|
|
211
|
-
if (monitorData) {
|
|
212
|
-
const { relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio } = (0, math_1.getRelativePosition)(dragAbsolutePosition, monitorData.absoluteMeasurements);
|
|
213
|
-
monitorData.protocol.onMonitorDragExit?.({
|
|
214
|
-
...monitorEventDataStub,
|
|
215
|
-
monitorOffset,
|
|
216
|
-
monitorOffsetRatio,
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
setMonitorIds(newMonitorIds);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}, [
|
|
224
|
-
findMonitorsAndReceiver,
|
|
225
|
-
getAbsoluteViewData,
|
|
226
|
-
getTrackingDragged,
|
|
227
|
-
getTrackingMonitorIds,
|
|
228
|
-
getTrackingReceiver,
|
|
229
|
-
resetReceiver,
|
|
230
|
-
setMonitorIds,
|
|
231
|
-
updateReceiver,
|
|
232
|
-
]);
|
|
233
|
-
const updateDragAbsolutePosition = (0, react_1.useCallback)((position) => {
|
|
234
|
-
const dragged = getTrackingDragged();
|
|
235
|
-
if (dragged && position) {
|
|
236
|
-
// Get the absolute position data for the drag touch.
|
|
237
|
-
const dragPositionData = getDragPositionData({
|
|
238
|
-
parentPosition: position,
|
|
239
|
-
draggedMeasurements: dragged.data.absoluteMeasurements,
|
|
240
|
-
lockXPosition: dragged.data.protocol.lockDragXPosition,
|
|
241
|
-
lockYPosition: dragged.data.protocol.lockDragYPosition,
|
|
242
|
-
});
|
|
243
|
-
if (!dragPositionData) {
|
|
244
|
-
// Failed to get drag position data. This should never happen.
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const { dragAbsolutePosition, dragTranslation, dragTranslationRatio } = dragPositionData;
|
|
248
|
-
dragPositionDataSV.value = {
|
|
249
|
-
dragAbsolutePosition,
|
|
250
|
-
dragTranslation,
|
|
251
|
-
dragTranslationRatio,
|
|
252
|
-
};
|
|
253
|
-
// if (debug) {
|
|
254
|
-
// console.log(`Drag at absolute coordinates (${dragAbsolutePosition.x}, ${dragAbsolutePosition.y})\n`);
|
|
255
|
-
// console.log(`Drag translation (${dragTranslation.x}, ${dragTranslation.y})`);
|
|
256
|
-
// console.log(`Drag translation ratio (${dragTranslationRatio.x}, ${dragTranslationRatio.y})`);
|
|
257
|
-
// }
|
|
258
|
-
// Always update the drag position.
|
|
259
|
-
updateDragPosition(dragAbsolutePosition);
|
|
260
|
-
}
|
|
261
|
-
}, [dragPositionDataSV, getDragPositionData, getTrackingDragged, updateDragPosition]);
|
|
262
|
-
// // Create throttled gesture event handler, tied to this id.
|
|
263
|
-
const throttledHandleGestureEvent = (0, react_1.useMemo)(() => (0, lodash_throttle_1.default)((position) => {
|
|
264
|
-
// Pass the event up to the Drax context.
|
|
265
|
-
updateDragAbsolutePosition(position);
|
|
266
|
-
}, 20), [updateDragAbsolutePosition]);
|
|
267
|
-
(0, react_native_reanimated_1.useAnimatedReaction)(() => dragPositionDataSV.value, position => {
|
|
268
|
-
(0, react_native_reanimated_1.runOnJS)(checkForReceiver)(position);
|
|
269
|
-
});
|
|
270
|
-
const handleGestureStateChange = (0, react_1.useCallback)((id) => (event) => {
|
|
271
|
-
if (debug) {
|
|
272
|
-
console.log(`handleGestureStateChange(${id}, ${JSON.stringify(event, null, 2)})`);
|
|
273
|
-
}
|
|
274
|
-
// Get info on the currently dragged view, if any.
|
|
275
|
-
const dragged = getTrackingDragged();
|
|
276
|
-
/*
|
|
277
|
-
* Case 1: We're already dragging a different view.
|
|
278
|
-
* Case 2: This view can't be found/measured.
|
|
279
|
-
* Case 3: This is the view we're already dragging.
|
|
280
|
-
* Case 3a: The drag is not ending.
|
|
281
|
-
* Case 3b: The drag is ending.
|
|
282
|
-
* Case 4: We're not already dragging a view.
|
|
283
|
-
* Case 4a: This view is not draggable.
|
|
284
|
-
* Case 4b: No drag is starting.
|
|
285
|
-
* Case 4c: A drag is starting.
|
|
286
|
-
*/
|
|
287
|
-
if (dragged && dragged.id !== id) {
|
|
288
|
-
// Case 1: We're already dragging a different view.
|
|
289
|
-
if (debug) {
|
|
290
|
-
console.log(`Ignoring gesture state change because another view is being dragged: ${dragged.id}`);
|
|
291
|
-
}
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const draggedData = dragged?.data ?? getAbsoluteViewData(id);
|
|
295
|
-
if (!draggedData) {
|
|
296
|
-
// Case 2: This view can't be found/measured.
|
|
297
|
-
if (dragged?.id === id) {
|
|
298
|
-
if (debug) {
|
|
299
|
-
console.log(`Data for currently dragged view id ${id} could not be found`);
|
|
300
|
-
// TODO: reset drag and notify monitors
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
else if (debug) {
|
|
304
|
-
console.log(`Ignoring gesture for view id ${id} because view data was not found`);
|
|
305
|
-
}
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
/*
|
|
309
|
-
* Documentation on gesture handler state flow used in switches below:
|
|
310
|
-
* https://docs.swmansion.com/react-native-gesture-handler/docs/under-the-hood/state/
|
|
311
|
-
*/
|
|
312
|
-
const { state: gestureState, // Used in switch logic below; see block comment above.
|
|
313
|
-
x: grabX, // x position of touch relative to dragged view
|
|
314
|
-
y: grabY, // y position of touch relative to dragged view
|
|
315
|
-
absoluteX: parentX, // x position of touch relative to parent of dragged view
|
|
316
|
-
absoluteY: parentY, // y position of touch relative to parent of dragged view
|
|
317
|
-
} = event;
|
|
318
|
-
startPosition.value = {
|
|
319
|
-
parent: { x: parentX, y: parentY },
|
|
320
|
-
grab: { x: grabX, y: grabY },
|
|
321
|
-
};
|
|
322
|
-
/** Position of touch relative to parent of dragged view */
|
|
323
|
-
const dragParentPosition = { x: parentX, y: parentY };
|
|
324
|
-
const { x: absoluteX, // absolute x position of dragged view within DraxProvider
|
|
325
|
-
y: absoluteY, // absolute y position of dragged view within DraxProvider
|
|
326
|
-
width, // width of dragged view
|
|
327
|
-
height, // height of dragged view
|
|
328
|
-
} = draggedData.absoluteMeasurements;
|
|
329
|
-
if (dragged) {
|
|
330
|
-
// Case 3: This is the view we're already dragging.
|
|
331
|
-
let endDrag = false;
|
|
332
|
-
let cancelled = false;
|
|
333
|
-
let shouldDrop = false;
|
|
334
|
-
switch (gestureState) {
|
|
335
|
-
case react_native_gesture_handler_1.State.BEGAN:
|
|
336
|
-
// This should never happen, but we'll do nothing.
|
|
337
|
-
if (debug) {
|
|
338
|
-
console.log(`Received unexpected BEGAN event for dragged view id ${id}`);
|
|
339
|
-
}
|
|
340
|
-
break;
|
|
341
|
-
case react_native_gesture_handler_1.State.ACTIVE:
|
|
342
|
-
// This should also never happen, but we'll do nothing.
|
|
343
|
-
if (debug) {
|
|
344
|
-
console.log(`Received unexpected ACTIVE event for dragged view id ${id}`);
|
|
345
|
-
}
|
|
346
|
-
break;
|
|
347
|
-
case react_native_gesture_handler_1.State.CANCELLED:
|
|
348
|
-
// The gesture handler system has cancelled, so end the drag without dropping.
|
|
349
|
-
if (debug) {
|
|
350
|
-
console.log(`Stop dragging view id ${id} (CANCELLED)`);
|
|
351
|
-
}
|
|
352
|
-
endDrag = true;
|
|
353
|
-
cancelled = true;
|
|
354
|
-
break;
|
|
355
|
-
case react_native_gesture_handler_1.State.FAILED:
|
|
356
|
-
// This should never happen, but let's end the drag without dropping.
|
|
357
|
-
if (debug) {
|
|
358
|
-
console.log(`Received unexpected FAILED event for dragged view id ${id}`);
|
|
359
|
-
}
|
|
360
|
-
endDrag = true;
|
|
361
|
-
cancelled = true;
|
|
362
|
-
break;
|
|
363
|
-
case react_native_gesture_handler_1.State.END:
|
|
364
|
-
// User has ended the gesture, so end the drag, dropping into receiver if applicable.
|
|
365
|
-
if (debug) {
|
|
366
|
-
console.log(`Stop dragging view id ${id} (END)`);
|
|
367
|
-
}
|
|
368
|
-
endDrag = true;
|
|
369
|
-
shouldDrop = true;
|
|
370
|
-
break;
|
|
371
|
-
default:
|
|
372
|
-
if (debug) {
|
|
373
|
-
console.warn(`Unrecognized gesture state ${gestureState} for dragged view`);
|
|
374
|
-
}
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
if (!endDrag) {
|
|
378
|
-
// Case 3a: The drag is not ending.
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
// Case 3b: The drag is ending.
|
|
382
|
-
// Get the absolute position data for the drag touch.
|
|
383
|
-
const dragPositionData = getDragPositionData({
|
|
384
|
-
parentPosition: dragParentPosition,
|
|
385
|
-
draggedMeasurements: draggedData.absoluteMeasurements,
|
|
386
|
-
lockXPosition: draggedData.protocol.lockDragXPosition,
|
|
387
|
-
lockYPosition: draggedData.protocol.lockDragYPosition,
|
|
388
|
-
});
|
|
389
|
-
if (!dragPositionData) {
|
|
390
|
-
// Failed to get absolute position of drag. This should never happen.
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
const { dragAbsolutePosition, dragTranslation, dragTranslationRatio } = dragPositionData;
|
|
394
|
-
dragPositionDataSV.value = {
|
|
395
|
-
dragAbsolutePosition,
|
|
396
|
-
dragTranslation,
|
|
397
|
-
dragTranslationRatio,
|
|
398
|
-
};
|
|
399
|
-
// Prepare event data for dragged view.
|
|
400
|
-
const eventDataDragged = {
|
|
401
|
-
id,
|
|
402
|
-
dragTranslationRatio,
|
|
403
|
-
parentId: draggedData.parentId,
|
|
404
|
-
payload: draggedData.protocol.dragPayload,
|
|
405
|
-
dragOffset: dragged.tracking.dragOffset,
|
|
406
|
-
grabOffset: dragged.tracking.grabOffset,
|
|
407
|
-
grabOffsetRatio: dragged.tracking.grabOffsetRatio,
|
|
408
|
-
hoverPosition: dragged.tracking.hoverPosition.value,
|
|
409
|
-
data: draggedData,
|
|
410
|
-
};
|
|
411
|
-
// Get data for receiver view (if any) before we reset.
|
|
412
|
-
const receiver = getTrackingReceiver();
|
|
413
|
-
// Get the monitors (if any) before we reset.
|
|
414
|
-
const monitors = getTrackingMonitors();
|
|
415
|
-
// Snapback target, which may be modified by responses from protocols.
|
|
416
|
-
let snapbackTarget = types_1.DraxSnapbackTargetPreset.Default;
|
|
417
|
-
if (receiver && shouldDrop) {
|
|
418
|
-
// It's a successful drop into a receiver, let them both know, and check for response.
|
|
419
|
-
let responded = false;
|
|
420
|
-
// Prepare event data for receiver view.
|
|
421
|
-
const eventDataReceiver = {
|
|
422
|
-
id: receiver.id,
|
|
423
|
-
parentId: receiver.data.parentId,
|
|
424
|
-
payload: receiver.data.protocol.receiverPayload,
|
|
425
|
-
...receiver.tracking,
|
|
426
|
-
data: receiver.data,
|
|
427
|
-
};
|
|
428
|
-
const eventData = {
|
|
429
|
-
dragAbsolutePosition,
|
|
430
|
-
dragTranslation,
|
|
431
|
-
dragged: eventDataDragged,
|
|
432
|
-
receiver: eventDataReceiver,
|
|
433
|
-
};
|
|
434
|
-
let response = draggedData.protocol.onDragDrop?.(eventData);
|
|
435
|
-
if (response !== undefined) {
|
|
436
|
-
snapbackTarget = response;
|
|
437
|
-
responded = true;
|
|
438
|
-
}
|
|
439
|
-
response = receiver.data.protocol.onReceiveDragDrop?.(eventData);
|
|
440
|
-
if (!responded && response !== undefined) {
|
|
441
|
-
snapbackTarget = response;
|
|
442
|
-
responded = true;
|
|
443
|
-
}
|
|
444
|
-
// And let any active monitors know too.
|
|
445
|
-
if (monitors.length > 0) {
|
|
446
|
-
monitors.forEach(({ data: monitorData }) => {
|
|
447
|
-
if (monitorData) {
|
|
448
|
-
const { relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio } = (0, math_1.getRelativePosition)(dragAbsolutePosition, monitorData.absoluteMeasurements);
|
|
449
|
-
const monitorEventData = {
|
|
450
|
-
...eventData,
|
|
451
|
-
monitorOffset,
|
|
452
|
-
monitorOffsetRatio,
|
|
453
|
-
};
|
|
454
|
-
response = monitorData.protocol.onMonitorDragDrop?.(monitorEventData);
|
|
455
|
-
}
|
|
456
|
-
if (!responded && response !== undefined) {
|
|
457
|
-
snapbackTarget = response;
|
|
458
|
-
responded = true;
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
// There is no receiver, or the drag was cancelled.
|
|
465
|
-
// Prepare common event data.
|
|
466
|
-
const eventData = {
|
|
467
|
-
dragAbsolutePosition,
|
|
468
|
-
dragTranslation,
|
|
469
|
-
cancelled,
|
|
470
|
-
dragged: eventDataDragged,
|
|
471
|
-
};
|
|
472
|
-
// Let the dragged item know the drag ended, and capture any response.
|
|
473
|
-
let responded = false;
|
|
474
|
-
let response = draggedData.protocol.onDragEnd?.(eventData);
|
|
475
|
-
if (response !== undefined) {
|
|
476
|
-
snapbackTarget = response;
|
|
477
|
-
responded = true;
|
|
478
|
-
}
|
|
479
|
-
// Prepare receiver event data, or undefined if no receiver.
|
|
480
|
-
const eventReceiverData = receiver && {
|
|
481
|
-
id: receiver.id,
|
|
482
|
-
parentId: receiver.data.parentId,
|
|
483
|
-
payload: receiver.data.protocol.receiverPayload,
|
|
484
|
-
receiveOffset: receiver.tracking.receiveOffset,
|
|
485
|
-
receiveOffsetRatio: receiver.tracking.receiveOffsetRatio,
|
|
486
|
-
data: receiver.data,
|
|
487
|
-
};
|
|
488
|
-
const receivedDragExitEventData = {
|
|
489
|
-
...eventData,
|
|
490
|
-
receiver: eventReceiverData,
|
|
491
|
-
};
|
|
492
|
-
// If there is a receiver but drag was cancelled, let it know the drag exited it.
|
|
493
|
-
receiver?.data.protocol.onReceiveDragExit?.(receivedDragExitEventData);
|
|
494
|
-
// And let any active monitors know too.
|
|
495
|
-
if (monitors.length > 0) {
|
|
496
|
-
const monitorEventData = {
|
|
497
|
-
...eventData,
|
|
498
|
-
receiver: eventReceiverData,
|
|
499
|
-
};
|
|
500
|
-
monitors.forEach(({ data: monitorData }) => {
|
|
501
|
-
const { relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio } = (0, math_1.getRelativePosition)(dragAbsolutePosition, monitorData.absoluteMeasurements);
|
|
502
|
-
response = monitorData.protocol.onMonitorDragEnd?.({
|
|
503
|
-
...monitorEventData,
|
|
504
|
-
monitorOffset,
|
|
505
|
-
monitorOffsetRatio,
|
|
506
|
-
cancelled,
|
|
507
|
-
});
|
|
508
|
-
if (!responded && response !== undefined) {
|
|
509
|
-
snapbackTarget = response;
|
|
510
|
-
responded = true;
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
// Reset the drag.
|
|
516
|
-
resetDrag(snapbackTarget);
|
|
517
|
-
if (startPosition.value) {
|
|
518
|
-
startPosition.value = startPositionInitialValue;
|
|
519
|
-
parentPosition.value = { x: 0, y: 0 };
|
|
520
|
-
}
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
// Case 4: We're not already dragging a view.
|
|
524
|
-
if (!draggedData.protocol.draggable) {
|
|
525
|
-
// Case 4a: This view is not draggable.
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
let shouldStartDrag = false;
|
|
529
|
-
switch (gestureState) {
|
|
530
|
-
case react_native_gesture_handler_1.State.ACTIVE:
|
|
531
|
-
shouldStartDrag = true;
|
|
532
|
-
break;
|
|
533
|
-
case react_native_gesture_handler_1.State.BEGAN:
|
|
534
|
-
// Do nothing until the gesture becomes active.
|
|
535
|
-
break;
|
|
536
|
-
case react_native_gesture_handler_1.State.CANCELLED:
|
|
537
|
-
case react_native_gesture_handler_1.State.FAILED:
|
|
538
|
-
case react_native_gesture_handler_1.State.END:
|
|
539
|
-
// Do nothing because we weren't tracking this gesture.
|
|
540
|
-
break;
|
|
541
|
-
default:
|
|
542
|
-
if (debug) {
|
|
543
|
-
console.warn(`Unrecognized gesture state ${gestureState} for non-dragged view id ${id}`);
|
|
544
|
-
}
|
|
545
|
-
break;
|
|
546
|
-
}
|
|
547
|
-
if (!shouldStartDrag) {
|
|
548
|
-
// Case 4b: No drag is starting.
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
// Case 4c: A drag is starting.
|
|
552
|
-
/*
|
|
553
|
-
* First, verify that the touch is still within the dragged view.
|
|
554
|
-
* Because we are using a LongPressGestureHandler with unlimited
|
|
555
|
-
* distance to handle the drag, it could be out of bounds before
|
|
556
|
-
* it even starts. (For some reason, LongPressGestureHandler does
|
|
557
|
-
* not provide us with a BEGAN state change event in iOS.)
|
|
558
|
-
*/
|
|
559
|
-
if (grabX >= 0 && grabY >= 0 && grabX < width && grabY < height) {
|
|
560
|
-
/*
|
|
561
|
-
* To determine drag start position in absolute coordinates, we add:
|
|
562
|
-
* absolute coordinates of dragged view
|
|
563
|
-
* + relative coordinates of touch within view
|
|
564
|
-
*
|
|
565
|
-
* NOTE: if view is transformed, these will be wrong.
|
|
566
|
-
*/
|
|
567
|
-
const dragAbsolutePosition = {
|
|
568
|
-
x: absoluteX + grabX,
|
|
569
|
-
y: absoluteY + grabY,
|
|
570
|
-
};
|
|
571
|
-
const grabOffset = { x: grabX, y: grabY };
|
|
572
|
-
const grabOffsetRatio = {
|
|
573
|
-
x: grabX / width,
|
|
574
|
-
y: grabY / height,
|
|
575
|
-
};
|
|
576
|
-
const { dragOffset, dragTranslation, dragTranslationRatio, hoverPosition } = startDrag({
|
|
577
|
-
grabOffset,
|
|
578
|
-
grabOffsetRatio,
|
|
579
|
-
dragAbsolutePosition,
|
|
580
|
-
dragParentPosition,
|
|
581
|
-
draggedId: id,
|
|
582
|
-
});
|
|
583
|
-
dragPositionDataSV.value = {
|
|
584
|
-
dragAbsolutePosition,
|
|
585
|
-
dragTranslation,
|
|
586
|
-
dragTranslationRatio,
|
|
587
|
-
};
|
|
588
|
-
if (debug) {
|
|
589
|
-
console.log(`Start dragging view id ${id} at absolute position (${dragAbsolutePosition.x}, ${dragAbsolutePosition.y})`);
|
|
590
|
-
}
|
|
591
|
-
const eventData = {
|
|
592
|
-
dragAbsolutePosition,
|
|
593
|
-
dragTranslation,
|
|
594
|
-
dragged: {
|
|
595
|
-
id,
|
|
596
|
-
dragOffset,
|
|
597
|
-
grabOffset,
|
|
598
|
-
grabOffsetRatio,
|
|
599
|
-
hoverPosition: hoverPosition.value,
|
|
600
|
-
dragTranslationRatio,
|
|
601
|
-
parentId: draggedData.parentId,
|
|
602
|
-
payload: draggedData.protocol.dragPayload,
|
|
603
|
-
data: draggedData,
|
|
604
|
-
},
|
|
605
|
-
};
|
|
606
|
-
draggedData.protocol.onDragStart?.(eventData);
|
|
607
|
-
// Find which monitors and receiver this drag is over.
|
|
608
|
-
const { monitors } = findMonitorsAndReceiver(dragAbsolutePosition, id);
|
|
609
|
-
// Notify monitors and update monitor tracking.
|
|
610
|
-
if (monitors.length > 0) {
|
|
611
|
-
const newMonitorIds = monitors.map(({ id: monitorId, data: monitorData, relativePosition: monitorOffset, relativePositionRatio: monitorOffsetRatio, }) => {
|
|
612
|
-
const monitorEventData = {
|
|
613
|
-
...eventData,
|
|
614
|
-
monitorOffset,
|
|
615
|
-
monitorOffsetRatio,
|
|
616
|
-
};
|
|
617
|
-
monitorData.protocol.onMonitorDragStart?.(monitorEventData);
|
|
618
|
-
return monitorId;
|
|
619
|
-
});
|
|
620
|
-
setMonitorIds(newMonitorIds);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}, [
|
|
624
|
-
debug,
|
|
625
|
-
getTrackingDragged,
|
|
626
|
-
getAbsoluteViewData,
|
|
627
|
-
startPosition,
|
|
628
|
-
getDragPositionData,
|
|
629
|
-
dragPositionDataSV,
|
|
630
|
-
getTrackingReceiver,
|
|
631
|
-
getTrackingMonitors,
|
|
632
|
-
resetDrag,
|
|
633
|
-
parentPosition,
|
|
634
|
-
startDrag,
|
|
635
|
-
findMonitorsAndReceiver,
|
|
636
|
-
setMonitorIds,
|
|
637
|
-
]);
|
|
638
|
-
const handleGestureEvent = (0, react_1.useCallback)((id, event) => {
|
|
639
|
-
'worklet';
|
|
640
|
-
// if (debug) {
|
|
641
|
-
// console.log(`handleGestureEvent(${id}, ${JSON.stringify(event, null, 2)})`);
|
|
642
|
-
// }
|
|
643
|
-
// if (dragged === undefined) {
|
|
644
|
-
// // We're not tracking any gesture yet.
|
|
645
|
-
// if (debug) {
|
|
646
|
-
// console.log('Ignoring gesture event because we have not initialized a drag');
|
|
647
|
-
// }
|
|
648
|
-
// return;
|
|
649
|
-
// }
|
|
650
|
-
// if (dragged.id !== id) {
|
|
651
|
-
// // This is not a gesture we're tracking. We don't support multiple simultaneous drags.
|
|
652
|
-
// if (debug) {
|
|
653
|
-
// console.log('Ignoring gesture event because this is not the view being dragged');
|
|
654
|
-
// }
|
|
655
|
-
// return;
|
|
656
|
-
// }
|
|
657
|
-
const { absoluteX: parentX, // x position of touch relative to parent of dragged view
|
|
658
|
-
absoluteY: parentY, // y position of touch relative to parent of dragged view
|
|
659
|
-
} = event;
|
|
660
|
-
// if (debug) {
|
|
661
|
-
// console.log(`Dragged item absolute coordinates (${dragged.data.absoluteMeasurements.x}, ${dragged.data.absoluteMeasurements.y})`);
|
|
662
|
-
// console.log(`Native event in-view touch coordinates: (${event.x}, ${event.y})`);
|
|
663
|
-
// }
|
|
664
|
-
/** Position of touch relative to parent of dragged view */
|
|
665
|
-
parentPosition.value = { x: parentX, y: parentY };
|
|
666
|
-
(0, react_native_reanimated_1.runOnJS)(throttledHandleGestureEvent)({ x: parentX, y: parentY });
|
|
667
|
-
}, [parentPosition, throttledHandleGestureEvent]);
|
|
668
|
-
const contextValue = {
|
|
669
|
-
getReleaseViews,
|
|
670
|
-
dragPositionDataSV,
|
|
671
|
-
startPosition,
|
|
672
|
-
parentPosition,
|
|
673
|
-
getTrackingDragged,
|
|
674
|
-
getTrackingReceiver,
|
|
675
|
-
updateReceiver,
|
|
676
|
-
resetReceiver,
|
|
677
|
-
getTrackingMonitorIds,
|
|
678
|
-
getAbsoluteViewData,
|
|
679
|
-
setMonitorIds,
|
|
680
|
-
findMonitorsAndReceiver,
|
|
681
|
-
getViewState,
|
|
682
|
-
getTrackingStatus,
|
|
683
|
-
registerView,
|
|
684
|
-
unregisterView,
|
|
685
|
-
updateViewProtocol,
|
|
686
|
-
updateViewMeasurements,
|
|
687
|
-
updateHoverViewMeasurements,
|
|
688
|
-
handleGestureEvent,
|
|
689
|
-
handleGestureStateChange,
|
|
690
|
-
rootViewRef,
|
|
691
|
-
};
|
|
692
|
-
const allViewStates = (0, react_1.useMemo)(() => getAllViewIds(), [getAllViewIds]);
|
|
693
|
-
const hoverViews = (0, react_1.useMemo)(() => getHoverItems(allViewStates).map((viewData, index) => viewData && (react_1.default.createElement(HoverView_1.HoverView, { key: viewData.id || index, ...(viewData?.protocol || {}), id: viewData.id, scrollPosition: viewData?.scrollPosition, scrollPositionOffset: viewData?.scrollPositionOffset }))), [allViewStates, getHoverItems]);
|
|
694
|
-
return (react_1.default.createElement(DraxContext_1.DraxContext.Provider, { value: contextValue },
|
|
695
|
-
react_1.default.createElement(react_native_1.View, { style: style, ref: rootViewRef },
|
|
696
|
-
children,
|
|
697
|
-
hoverViews)));
|
|
698
|
-
};
|
|
699
|
-
exports.DraxProvider = DraxProvider;
|
|
700
|
-
const styles = react_native_1.StyleSheet.create({
|
|
701
|
-
provider: {
|
|
702
|
-
flex: 1,
|
|
703
|
-
},
|
|
704
|
-
});
|