cpk-ui 0.8.0-beta.2 → 0.8.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -1
- package/components/modals/AlertDialog/AlertDialog.d.ts +7 -0
- package/components/modals/AlertDialog/AlertDialog.d.ts.map +1 -1
- package/components/modals/AlertDialog/AlertDialog.js +34 -19
- package/components/uis/EditText/EditText.d.ts.map +1 -1
- package/components/uis/EditText/EditText.js +1 -1
- package/components/uis/PageIndicator/PageIndicator.d.ts +24 -0
- package/components/uis/PageIndicator/PageIndicator.d.ts.map +1 -0
- package/components/uis/PageIndicator/PageIndicator.js +57 -0
- package/components/uis/ReorderableList/ReorderableList.d.ts +37 -0
- package/components/uis/ReorderableList/ReorderableList.d.ts.map +1 -0
- package/components/uis/ReorderableList/ReorderableList.js +87 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +2 -0
- package/node_modules/react-native-drax/LICENSE.md +21 -0
- package/node_modules/react-native-drax/README.md +454 -0
- package/node_modules/react-native-drax/lib/module/DebugOverlay.js +121 -0
- package/node_modules/react-native-drax/lib/module/DebugOverlay.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/Drax.js +36 -0
- package/node_modules/react-native-drax/lib/module/Drax.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/DraxContext.js +6 -0
- package/node_modules/react-native-drax/lib/module/DraxContext.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/DraxHandle.js +47 -0
- package/node_modules/react-native-drax/lib/module/DraxHandle.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/DraxHandleContext.js +11 -0
- package/node_modules/react-native-drax/lib/module/DraxHandleContext.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/DraxList.js +108 -0
- package/node_modules/react-native-drax/lib/module/DraxList.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/DraxProvider.js +203 -0
- package/node_modules/react-native-drax/lib/module/DraxProvider.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/DraxScrollView.js +167 -0
- package/node_modules/react-native-drax/lib/module/DraxScrollView.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/DraxSubprovider.js +21 -0
- package/node_modules/react-native-drax/lib/module/DraxSubprovider.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/DraxView.js +348 -0
- package/node_modules/react-native-drax/lib/module/DraxView.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/HoverLayer.js +152 -0
- package/node_modules/react-native-drax/lib/module/HoverLayer.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/SortableBoardContainer.js +386 -0
- package/node_modules/react-native-drax/lib/module/SortableBoardContainer.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/SortableBoardContext.js +6 -0
- package/node_modules/react-native-drax/lib/module/SortableBoardContext.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/SortableContainer.js +571 -0
- package/node_modules/react-native-drax/lib/module/SortableContainer.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/SortableItem.js +225 -0
- package/node_modules/react-native-drax/lib/module/SortableItem.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/SortableItemContext.js +38 -0
- package/node_modules/react-native-drax/lib/module/SortableItemContext.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/compat/detectVersion.js +19 -0
- package/node_modules/react-native-drax/lib/module/compat/detectVersion.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/compat/index.js +5 -0
- package/node_modules/react-native-drax/lib/module/compat/index.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/compat/types.js +4 -0
- package/node_modules/react-native-drax/lib/module/compat/types.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/compat/useDraxPanGesture.js +95 -0
- package/node_modules/react-native-drax/lib/module/compat/useDraxPanGesture.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/index.js +5 -0
- package/node_modules/react-native-drax/lib/module/hooks/index.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useCallbackDispatch.js +688 -0
- package/node_modules/react-native-drax/lib/module/hooks/useCallbackDispatch.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useDragGesture.js +240 -0
- package/node_modules/react-native-drax/lib/module/hooks/useDragGesture.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useDraxContext.js +12 -0
- package/node_modules/react-native-drax/lib/module/hooks/useDraxContext.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useDraxId.js +13 -0
- package/node_modules/react-native-drax/lib/module/hooks/useDraxId.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useDraxMethods.js +73 -0
- package/node_modules/react-native-drax/lib/module/hooks/useDraxMethods.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useDraxScrollHandler.js +97 -0
- package/node_modules/react-native-drax/lib/module/hooks/useDraxScrollHandler.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useSortableBoard.js +37 -0
- package/node_modules/react-native-drax/lib/module/hooks/useSortableBoard.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useSortableList.js +1025 -0
- package/node_modules/react-native-drax/lib/module/hooks/useSortableList.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useSpatialIndex.js +283 -0
- package/node_modules/react-native-drax/lib/module/hooks/useSpatialIndex.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useViewStyles.js +158 -0
- package/node_modules/react-native-drax/lib/module/hooks/useViewStyles.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/hooks/useWebScrollFreeze.js +52 -0
- package/node_modules/react-native-drax/lib/module/hooks/useWebScrollFreeze.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/index.js +37 -0
- package/node_modules/react-native-drax/lib/module/index.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/math.js +294 -0
- package/node_modules/react-native-drax/lib/module/math.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/package.json +1 -0
- package/node_modules/react-native-drax/lib/module/params.js +88 -0
- package/node_modules/react-native-drax/lib/module/params.js.map +1 -0
- package/node_modules/react-native-drax/lib/module/types.js +215 -0
- package/node_modules/react-native-drax/lib/module/types.js.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/package.json +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/DebugOverlay.d.ts +17 -0
- package/node_modules/react-native-drax/lib/typescript/src/DebugOverlay.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/Drax.d.ts +28 -0
- package/node_modules/react-native-drax/lib/typescript/src/Drax.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxContext.d.ts +3 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxContext.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxHandle.d.ts +25 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxHandle.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxHandleContext.d.ts +12 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxHandleContext.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxList.d.ts +66 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxList.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxProvider.d.ts +4 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxProvider.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxScrollView.d.ts +7 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxScrollView.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxSubprovider.d.ts +4 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxSubprovider.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxView.d.ts +4 -0
- package/node_modules/react-native-drax/lib/typescript/src/DraxView.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/HoverLayer.d.ts +38 -0
- package/node_modules/react-native-drax/lib/typescript/src/HoverLayer.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/SortableBoardContainer.d.ts +11 -0
- package/node_modules/react-native-drax/lib/typescript/src/SortableBoardContainer.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/SortableBoardContext.d.ts +4 -0
- package/node_modules/react-native-drax/lib/typescript/src/SortableBoardContext.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/SortableContainer.d.ts +13 -0
- package/node_modules/react-native-drax/lib/typescript/src/SortableContainer.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/SortableItem.d.ts +14 -0
- package/node_modules/react-native-drax/lib/typescript/src/SortableItem.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/SortableItemContext.d.ts +37 -0
- package/node_modules/react-native-drax/lib/typescript/src/SortableItemContext.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/compat/detectVersion.d.ts +2 -0
- package/node_modules/react-native-drax/lib/typescript/src/compat/detectVersion.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/compat/index.d.ts +4 -0
- package/node_modules/react-native-drax/lib/typescript/src/compat/index.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/compat/types.d.ts +33 -0
- package/node_modules/react-native-drax/lib/typescript/src/compat/types.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/compat/useDraxPanGesture.d.ts +8 -0
- package/node_modules/react-native-drax/lib/typescript/src/compat/useDraxPanGesture.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/index.d.ts +3 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useCallbackDispatch.d.ts +40 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useCallbackDispatch.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useDragGesture.d.ts +17 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useDragGesture.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useDraxContext.d.ts +2 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useDraxContext.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useDraxId.d.ts +2 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useDraxId.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useDraxMethods.d.ts +13 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useDraxMethods.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useDraxScrollHandler.d.ts +27 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useDraxScrollHandler.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useSortableBoard.d.ts +10 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useSortableBoard.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useSortableList.d.ts +11 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useSortableList.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useSpatialIndex.d.ts +22 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useSpatialIndex.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useViewStyles.d.ts +183 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useViewStyles.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useWebScrollFreeze.d.ts +14 -0
- package/node_modules/react-native-drax/lib/typescript/src/hooks/useWebScrollFreeze.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/index.d.ts +25 -0
- package/node_modules/react-native-drax/lib/typescript/src/index.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/math.d.ts +76 -0
- package/node_modules/react-native-drax/lib/typescript/src/math.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/params.d.ts +31 -0
- package/node_modules/react-native-drax/lib/typescript/src/params.d.ts.map +1 -0
- package/node_modules/react-native-drax/lib/typescript/src/types.d.ts +756 -0
- package/node_modules/react-native-drax/lib/typescript/src/types.d.ts.map +1 -0
- package/node_modules/react-native-drax/package.json +175 -0
- package/node_modules/react-native-drax/src/DebugOverlay.tsx +140 -0
- package/node_modules/react-native-drax/src/Drax.ts +33 -0
- package/node_modules/react-native-drax/src/DraxContext.ts +8 -0
- package/node_modules/react-native-drax/src/DraxHandle.tsx +52 -0
- package/node_modules/react-native-drax/src/DraxHandleContext.ts +15 -0
- package/node_modules/react-native-drax/src/DraxList.tsx +181 -0
- package/node_modules/react-native-drax/src/DraxProvider.tsx +224 -0
- package/node_modules/react-native-drax/src/DraxScrollView.tsx +180 -0
- package/node_modules/react-native-drax/src/DraxSubprovider.tsx +22 -0
- package/node_modules/react-native-drax/src/DraxView.tsx +430 -0
- package/node_modules/react-native-drax/src/HoverLayer.tsx +167 -0
- package/node_modules/react-native-drax/src/SortableBoardContainer.tsx +439 -0
- package/node_modules/react-native-drax/src/SortableBoardContext.ts +6 -0
- package/node_modules/react-native-drax/src/SortableContainer.tsx +650 -0
- package/node_modules/react-native-drax/src/SortableItem.tsx +263 -0
- package/node_modules/react-native-drax/src/SortableItemContext.ts +46 -0
- package/node_modules/react-native-drax/src/compat/detectVersion.ts +17 -0
- package/node_modules/react-native-drax/src/compat/index.ts +7 -0
- package/node_modules/react-native-drax/src/compat/types.ts +35 -0
- package/node_modules/react-native-drax/src/compat/useDraxPanGesture.ts +111 -0
- package/node_modules/react-native-drax/src/hooks/index.ts +2 -0
- package/node_modules/react-native-drax/src/hooks/useCallbackDispatch.tsx +830 -0
- package/node_modules/react-native-drax/src/hooks/useDragGesture.ts +273 -0
- package/node_modules/react-native-drax/src/hooks/useDraxContext.ts +11 -0
- package/node_modules/react-native-drax/src/hooks/useDraxId.ts +11 -0
- package/node_modules/react-native-drax/src/hooks/useDraxMethods.ts +71 -0
- package/node_modules/react-native-drax/src/hooks/useDraxScrollHandler.ts +121 -0
- package/node_modules/react-native-drax/src/hooks/useSortableBoard.ts +44 -0
- package/node_modules/react-native-drax/src/hooks/useSortableList.ts +1102 -0
- package/node_modules/react-native-drax/src/hooks/useSpatialIndex.ts +336 -0
- package/node_modules/react-native-drax/src/hooks/useViewStyles.ts +180 -0
- package/node_modules/react-native-drax/src/hooks/useWebScrollFreeze.ts +60 -0
- package/node_modules/react-native-drax/src/index.ts +111 -0
- package/node_modules/react-native-drax/src/math.ts +333 -0
- package/node_modules/react-native-drax/src/params.ts +74 -0
- package/node_modules/react-native-drax/src/types.ts +933 -0
- package/package.json +11 -5
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
# react-native-drax
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
[](https://reactnative.dev/)
|
|
5
|
+
[](https://expo.dev/)
|
|
6
|
+
[](https://necolas.github.io/react-native-web/)
|
|
7
|
+
[](https://github.com/nuclearpasta/react-native-drax/search?l=typescript)
|
|
8
|
+
[](https://github.com/nuclearpasta/react-native-drax/actions/workflows/ci.yml)
|
|
9
|
+
[](https://github.com/nuclearpasta/react-native-drax/blob/main/LICENSE.md)
|
|
10
|
+
[](https://www.npmjs.com/package/react-native-drax)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
📚 [**Visit the official documentation**](https://nuclearpasta.com/react-native-drax)
|
|
15
|
+
|
|
16
|
+
🎮 [**See the live example**](https://nuclearpasta.com/react-native-drax/example)
|
|
17
|
+
|
|
18
|
+
## 📖 Overview
|
|
19
|
+
|
|
20
|
+
Drax is a declarative drag-and-drop framework for React Native, written in TypeScript. It supports free-form drag-and-drop, sortable lists and grids, cross-list reorder, drag handles, collision algorithms, and more.
|
|
21
|
+
|
|
22
|
+
Built on [Reanimated 4](https://docs.swmansion.com/react-native-reanimated/) and [Gesture Handler 3](https://docs.swmansion.com/react-native-gesture-handler/) with a UI-thread-first architecture for smooth 60fps interactions.
|
|
23
|
+
|
|
24
|
+
**Platforms:** iOS, Android, Web
|
|
25
|
+
|
|
26
|
+
### ✨ Highlights
|
|
27
|
+
|
|
28
|
+
- 📋 **List-agnostic sortable** — works with FlatList, FlashList, LegendList, or any list component
|
|
29
|
+
- 🔀 **Cross-container drag** — move items between lists (cross-list reorder)
|
|
30
|
+
- ⚡ **UI-thread hit-testing** — spatial index worklet for fast receiver detection
|
|
31
|
+
- ✊ **Drag handles** — only the handle starts a drag, the rest scrolls
|
|
32
|
+
- 💥 **Collision algorithms** — center, intersect, or contain
|
|
33
|
+
- 📐 **Drag bounds** — constrain drags within a view
|
|
34
|
+
- 🎨 **Hover styles** — conditional styles based on drag phase and receiver state
|
|
35
|
+
- 🚫 **Drop zone acceptance** — accept or reject drops with `acceptsDrag`
|
|
36
|
+
- 🎬 **Animation presets** — default, spring, gentle, snappy, none — or custom config
|
|
37
|
+
- 🧲 **Snap alignment** — snap to 9-point alignment within receivers
|
|
38
|
+
- ♿ **Accessibility** — auto-generated labels, reduced motion support
|
|
39
|
+
- 📡 **19 callback events** — full drag lifecycle control
|
|
40
|
+
- 🏗️ **New Architecture** compatible (Fabric)
|
|
41
|
+
|
|
42
|
+
### 🤔 Why Drax?
|
|
43
|
+
|
|
44
|
+
| Feature | Drax | reanimated-dnd | sortables |
|
|
45
|
+
|---|:---:|:---:|:---:|
|
|
46
|
+
| Free-form drag & drop | ✅ | ✅ | ➖ |
|
|
47
|
+
| Sortable list / grid | ✅ | ✅ | ✅ |
|
|
48
|
+
| Mixed-size grid (non-uniform spans) | ✅ | ➖ | ➖ |
|
|
49
|
+
| Cross-container / cross-list reorder | ⚠️ Experimental | ➖ | ➖ |
|
|
50
|
+
| List-agnostic (FlatList, FlashList, LegendList) | ✅ | ➖ | ➖ |
|
|
51
|
+
| Drag handles | ✅ | ✅ | ✅ |
|
|
52
|
+
| Drag state styling | 15 props + inactive | onStateChange | 5 props + hook |
|
|
53
|
+
| Drop indicator | ✅ | ➖ | Grid only |
|
|
54
|
+
| UI-thread DnD collision | ✅ | ➖ | ➖ |
|
|
55
|
+
| Event callbacks | 19 types | ~12 types | ~10 types |
|
|
56
|
+
| Accessibility + reduced motion | ✅ | Manual | Manual |
|
|
57
|
+
| Web support | ✅ | ➖ | Partial |
|
|
58
|
+
| Reanimated | ≥ 4 | ≥ 4.2 | ≥ 3 |
|
|
59
|
+
| Gesture Handler | ≥ 2 | ≥ 2.28 | ≥ 2 |
|
|
60
|
+
|
|
61
|
+
[See full comparison →](https://nuclearpasta.com/react-native-drax#comparison)
|
|
62
|
+
|
|
63
|
+
## 📦 Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install react-native-drax
|
|
67
|
+
# or
|
|
68
|
+
yarn add react-native-drax
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 🔗 Peer Dependencies
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm install react-native-reanimated react-native-gesture-handler
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
| Peer Dependency | Version |
|
|
78
|
+
|---|---|
|
|
79
|
+
| `react` | >= 18 |
|
|
80
|
+
| `react-native` | >= 0.68 |
|
|
81
|
+
| `react-native-reanimated` | ^4.0.0 |
|
|
82
|
+
| `react-native-gesture-handler` | >= 2.0.0 (v3 recommended) |
|
|
83
|
+
|
|
84
|
+
## 🚀 Quick Start
|
|
85
|
+
|
|
86
|
+
### 👋 Basic Drag-and-Drop
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { DraxProvider, DraxView } from 'react-native-drax';
|
|
90
|
+
|
|
91
|
+
function App() {
|
|
92
|
+
return (
|
|
93
|
+
<DraxProvider>
|
|
94
|
+
<DraxView
|
|
95
|
+
style={{ width: 100, height: 100, backgroundColor: 'blue' }}
|
|
96
|
+
onDragStart={() => console.log('dragging')}
|
|
97
|
+
payload="hello"
|
|
98
|
+
/>
|
|
99
|
+
<DraxView
|
|
100
|
+
style={{ width: 100, height: 100, backgroundColor: 'green' }}
|
|
101
|
+
onReceiveDragDrop={({ dragged: { payload } }) => {
|
|
102
|
+
console.log(`received: ${payload}`);
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
</DraxProvider>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 📋 Sortable List
|
|
111
|
+
|
|
112
|
+
The simplest way to make a reorderable list:
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import { useState } from 'react';
|
|
116
|
+
import { Text, View } from 'react-native';
|
|
117
|
+
import { DraxProvider, DraxList } from 'react-native-drax';
|
|
118
|
+
|
|
119
|
+
function App() {
|
|
120
|
+
const [items, setItems] = useState(['A', 'B', 'C', 'D', 'E']);
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<DraxProvider>
|
|
124
|
+
<DraxList
|
|
125
|
+
data={items}
|
|
126
|
+
keyExtractor={(item) => item}
|
|
127
|
+
onReorder={({ data }) => setItems(data)}
|
|
128
|
+
renderItem={({ item }) => (
|
|
129
|
+
<View style={{ padding: 16, backgroundColor: '#eee', margin: 4 }}>
|
|
130
|
+
<Text>{item}</Text>
|
|
131
|
+
</View>
|
|
132
|
+
)}
|
|
133
|
+
/>
|
|
134
|
+
</DraxProvider>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`DraxList` is list-agnostic — pass any list component via the `component` prop:
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
import { FlashList } from '@shopify/flash-list';
|
|
143
|
+
|
|
144
|
+
<DraxList
|
|
145
|
+
component={FlashList}
|
|
146
|
+
data={items}
|
|
147
|
+
keyExtractor={(item) => item.id}
|
|
148
|
+
onReorder={({ data }) => setItems(data)}
|
|
149
|
+
renderItem={({ item }) => <ItemCard item={item} />}
|
|
150
|
+
estimatedItemSize={60}
|
|
151
|
+
/>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 🧱 Composable API
|
|
155
|
+
|
|
156
|
+
For full control, use the composable primitives directly:
|
|
157
|
+
|
|
158
|
+
```tsx
|
|
159
|
+
import {
|
|
160
|
+
DraxProvider,
|
|
161
|
+
useSortableList,
|
|
162
|
+
SortableContainer,
|
|
163
|
+
SortableItem,
|
|
164
|
+
} from 'react-native-drax';
|
|
165
|
+
import { FlatList } from 'react-native';
|
|
166
|
+
|
|
167
|
+
function App() {
|
|
168
|
+
const [items, setItems] = useState(['A', 'B', 'C', 'D', 'E']);
|
|
169
|
+
const listRef = useRef<FlatList>(null);
|
|
170
|
+
|
|
171
|
+
const sortable = useSortableList({
|
|
172
|
+
data: items,
|
|
173
|
+
keyExtractor: (item) => item,
|
|
174
|
+
onReorder: ({ data }) => setItems(data),
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<DraxProvider>
|
|
179
|
+
<SortableContainer sortable={sortable} scrollRef={listRef}>
|
|
180
|
+
<FlatList
|
|
181
|
+
ref={listRef}
|
|
182
|
+
data={sortable.data}
|
|
183
|
+
keyExtractor={sortable.stableKeyExtractor}
|
|
184
|
+
onScroll={sortable.onScroll}
|
|
185
|
+
onContentSizeChange={sortable.onContentSizeChange}
|
|
186
|
+
renderItem={({ item, index }) => (
|
|
187
|
+
<SortableItem sortable={sortable} index={index}>
|
|
188
|
+
<Text>{item}</Text>
|
|
189
|
+
</SortableItem>
|
|
190
|
+
)}
|
|
191
|
+
/>
|
|
192
|
+
</SortableContainer>
|
|
193
|
+
</DraxProvider>
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
This pattern works with any list component — FlatList, FlashList, LegendList, ScrollView, etc.
|
|
199
|
+
|
|
200
|
+
## 🎛 Features
|
|
201
|
+
|
|
202
|
+
### ✊ Drag Handles
|
|
203
|
+
|
|
204
|
+
Only the handle area starts a drag — the rest of the view scrolls normally:
|
|
205
|
+
|
|
206
|
+
```tsx
|
|
207
|
+
import { DraxView, DraxHandle } from 'react-native-drax';
|
|
208
|
+
|
|
209
|
+
<DraxView dragHandle>
|
|
210
|
+
<Text>This content scrolls normally</Text>
|
|
211
|
+
<DraxHandle>
|
|
212
|
+
<GripIcon /> {/* Only this starts a drag */}
|
|
213
|
+
</DraxHandle>
|
|
214
|
+
</DraxView>
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 📐 Drag Bounds
|
|
218
|
+
|
|
219
|
+
Constrain a dragged view within a boundary:
|
|
220
|
+
|
|
221
|
+
```tsx
|
|
222
|
+
const boundsRef = useRef<View>(null);
|
|
223
|
+
|
|
224
|
+
<View ref={boundsRef} style={{ flex: 1 }}>
|
|
225
|
+
<DraxView dragBoundsRef={boundsRef}>
|
|
226
|
+
<Text>I can only be dragged within the parent</Text>
|
|
227
|
+
</DraxView>
|
|
228
|
+
</View>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### 💥 Collision Algorithms
|
|
232
|
+
|
|
233
|
+
Control how receiver detection works:
|
|
234
|
+
|
|
235
|
+
```tsx
|
|
236
|
+
<DraxView collisionAlgorithm="center" /> {/* hover center inside receiver (default) */}
|
|
237
|
+
<DraxView collisionAlgorithm="intersect" /> {/* any overlap triggers receiving */}
|
|
238
|
+
<DraxView collisionAlgorithm="contain" /> {/* dragged view must be fully inside */}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### 🚫 Drop Zone Acceptance
|
|
242
|
+
|
|
243
|
+
Accept or reject drops conditionally:
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
<DraxView
|
|
247
|
+
acceptsDrag={(draggedPayload) => items.length < 5}
|
|
248
|
+
onReceiveDragDrop={({ dragged }) => addItem(dragged.payload)}
|
|
249
|
+
/>
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### 🎨 Hover Styles
|
|
253
|
+
|
|
254
|
+
Style the hover layer based on drag state:
|
|
255
|
+
|
|
256
|
+
```tsx
|
|
257
|
+
<DraxView
|
|
258
|
+
hoverStyle={{ opacity: 0.8 }}
|
|
259
|
+
hoverDraggingWithReceiverStyle={{ borderColor: 'green', borderWidth: 2 }}
|
|
260
|
+
hoverDraggingWithoutReceiverStyle={{ opacity: 0.5 }}
|
|
261
|
+
hoverDragReleasedStyle={{ opacity: 0.3 }}
|
|
262
|
+
/>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### 🧲 Snap Alignment
|
|
266
|
+
|
|
267
|
+
Snap dropped items to specific positions within a receiver:
|
|
268
|
+
|
|
269
|
+
```tsx
|
|
270
|
+
import { snapToAlignment } from 'react-native-drax';
|
|
271
|
+
|
|
272
|
+
<DraxView
|
|
273
|
+
onReceiveDragDrop={({ dragged, receiver }) =>
|
|
274
|
+
snapToAlignment(receiver, dragged, 'top-left', { x: 8, y: 8 })
|
|
275
|
+
}
|
|
276
|
+
/>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Alignments: `center`, `top-left`, `top-center`, `top-right`, `center-left`, `center-right`, `bottom-left`, `bottom-center`, `bottom-right`
|
|
280
|
+
|
|
281
|
+
### 🎬 Animation Presets
|
|
282
|
+
|
|
283
|
+
```tsx
|
|
284
|
+
<DraxList animationConfig="spring" /> {/* spring physics */}
|
|
285
|
+
<DraxList animationConfig="gentle" /> {/* soft spring */}
|
|
286
|
+
<DraxList animationConfig="snappy" /> {/* fast spring */}
|
|
287
|
+
<DraxList animationConfig="none" /> {/* instant */}
|
|
288
|
+
|
|
289
|
+
{/* Or custom: */}
|
|
290
|
+
<DraxList animationConfig={{
|
|
291
|
+
useSpring: true,
|
|
292
|
+
springDamping: 15,
|
|
293
|
+
springStiffness: 150,
|
|
294
|
+
springMass: 1,
|
|
295
|
+
}} />
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Device reduced motion settings are respected automatically.
|
|
299
|
+
|
|
300
|
+
### 📡 Continuous Drag Callbacks
|
|
301
|
+
|
|
302
|
+
```tsx
|
|
303
|
+
<DraxView
|
|
304
|
+
onDrag={(data) => { /* fires every frame while dragging over empty space */ }}
|
|
305
|
+
onDragOver={(data) => { /* fires every frame while over the same receiver */ }}
|
|
306
|
+
/>
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### 🔀 Cross-Container Sortable (Experimental)
|
|
310
|
+
|
|
311
|
+
Move items between lists (cross-list reorder):
|
|
312
|
+
|
|
313
|
+
```tsx
|
|
314
|
+
import {
|
|
315
|
+
useSortableBoard,
|
|
316
|
+
SortableBoardContainer,
|
|
317
|
+
useSortableList,
|
|
318
|
+
SortableContainer,
|
|
319
|
+
SortableItem,
|
|
320
|
+
} from 'react-native-drax';
|
|
321
|
+
|
|
322
|
+
const board = useSortableBoard({
|
|
323
|
+
onTransfer: ({ fromColumnId, toColumnId, fromIndex, toIndex, item }) => {
|
|
324
|
+
// Move item between columns
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
<SortableBoardContainer board={board}>
|
|
329
|
+
{columns.map((column) => (
|
|
330
|
+
<Column key={column.id} board={board} column={column} />
|
|
331
|
+
))}
|
|
332
|
+
</SortableBoardContainer>
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
> **Note:** Cross-container drag is experimental. The API may change in future versions.
|
|
336
|
+
|
|
337
|
+
### 🏷️ Namespace API
|
|
338
|
+
|
|
339
|
+
For convenience, all components are available under the `Drax` namespace:
|
|
340
|
+
|
|
341
|
+
```tsx
|
|
342
|
+
import { Drax } from 'react-native-drax';
|
|
343
|
+
|
|
344
|
+
<Drax.Provider>
|
|
345
|
+
<Drax.View draggable>
|
|
346
|
+
<Drax.Handle><GripIcon /></Drax.Handle>
|
|
347
|
+
</Drax.View>
|
|
348
|
+
</Drax.Provider>
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## 🧩 Components
|
|
352
|
+
|
|
353
|
+
| Component | Description |
|
|
354
|
+
|---|---|
|
|
355
|
+
| `DraxProvider` | Context provider — wrap your app's drag-and-drop area |
|
|
356
|
+
| `DraxView` | Draggable and/or receptive view with 19 callback events |
|
|
357
|
+
| `DraxList` | List-agnostic sortable list (convenience wrapper) |
|
|
358
|
+
| `DraxHandle` | Drag handle — only this area starts a drag |
|
|
359
|
+
| `DraxScrollView` | Scrollable container with auto-scroll during drag |
|
|
360
|
+
| `SortableContainer` | Monitoring wrapper for composable sortable API |
|
|
361
|
+
| `SortableItem` | Per-item wrapper with shift animation |
|
|
362
|
+
| `SortableBoardContainer` | Cross-container board coordinator (experimental) |
|
|
363
|
+
|
|
364
|
+
## 🪝 Hooks
|
|
365
|
+
|
|
366
|
+
| Hook | Description |
|
|
367
|
+
|---|---|
|
|
368
|
+
| `useSortableList` | List-agnostic reorder state management |
|
|
369
|
+
| `useSortableBoard` | Cross-container board coordinator (experimental) |
|
|
370
|
+
| `useDraxContext` | Access the Drax context |
|
|
371
|
+
| `useDraxId` | Generate a unique Drax view ID |
|
|
372
|
+
|
|
373
|
+
## 💡 Examples
|
|
374
|
+
|
|
375
|
+
The `example/` directory contains an Expo Router app with 11 screens demonstrating all features:
|
|
376
|
+
|
|
377
|
+
| Screen | Features shown |
|
|
378
|
+
|---|---|
|
|
379
|
+
| Color Drag & Drop | Drop acceptance, hover styles, snap alignment |
|
|
380
|
+
| Reorderable List | DraxList, animation presets, auto-scroll |
|
|
381
|
+
| Reorderable Grid | Sortable grid with multi-column layout |
|
|
382
|
+
| Mixed-Size Grid | Items with different spans (1×1, 2×2, etc.) using `getItemSpan` and `packGrid` |
|
|
383
|
+
| Drag Handles | Only the grip icon starts a drag |
|
|
384
|
+
| Drag Bounds | Constrain drag within a view |
|
|
385
|
+
| Collision Modes | Center vs Intersect vs Contain |
|
|
386
|
+
| Cross-List Reorder | FlashList + LegendList + FlatList cross-container drag (experimental) |
|
|
387
|
+
| Knight Moves | Chess knight drag puzzle |
|
|
388
|
+
| Scrolling | Drag from scroll view to drop zone |
|
|
389
|
+
| Stress Test | 100 items in a sortable list |
|
|
390
|
+
|
|
391
|
+
To run the example app:
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
cd example && yarn start
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
## 🔄 Migration from v0.x
|
|
398
|
+
|
|
399
|
+
v1.0.0 is a complete rewrite. Key changes:
|
|
400
|
+
|
|
401
|
+
- **`DraxList` is new** — list-agnostic convenience wrapper using the new sortable architecture. The old `DraxList` / `DraxListItem` API from v0.10.x and v0.11.0-alpha is removed.
|
|
402
|
+
- **New sortable architecture** — `useSortableList` + `SortableContainer` + `SortableItem` composable API replaces the old array-indexed approach.
|
|
403
|
+
- **Reanimated 4 + Gesture Handler 3** — required peer dependencies (Gesture Handler v2 supported via compat layer with reduced performance).
|
|
404
|
+
- **New Architecture (Fabric)** compatible.
|
|
405
|
+
|
|
406
|
+
## 📋 Changelog
|
|
407
|
+
|
|
408
|
+
See [CHANGELOG.md](CHANGELOG.md) for a full list of changes.
|
|
409
|
+
|
|
410
|
+
## 🤝 Contributing
|
|
411
|
+
|
|
412
|
+
Issues, pull requests, and discussion are all welcome. See the [Contribution Guidelines](CONTRIBUTING.md) for details.
|
|
413
|
+
|
|
414
|
+
## 📜 Code of Conduct
|
|
415
|
+
|
|
416
|
+
This project is released with a [Contributor Code of Conduct](CODE-OF-CONDUCT.md). By participating in this project you agree to abide by its terms.
|
|
417
|
+
|
|
418
|
+
## 🏆 Contributors
|
|
419
|
+
|
|
420
|
+
Originally created by [Joe Lafiosca](https://github.com/lafiosca). v1.0.0 rewrite led by [Ovidiu Cristescu](https://github.com/LunatiqueCoder).
|
|
421
|
+
|
|
422
|
+
Thanks to all contributors who have helped make Drax better:
|
|
423
|
+
|
|
424
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
425
|
+
<!-- prettier-ignore-start -->
|
|
426
|
+
<!-- markdownlint-disable -->
|
|
427
|
+
<table>
|
|
428
|
+
<tbody>
|
|
429
|
+
<tr>
|
|
430
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/lafiosca"><img src="https://avatars.githubusercontent.com/u/9442662?v=4" width="100px;" alt="Joe Lafiosca"/><br /><sub><b>Joe Lafiosca</b></sub></a><br /><a href="https://github.com/nuclearpasta/react-native-drax/commits?author=lafiosca" title="Code">💻</a> <a href="https://github.com/nuclearpasta/react-native-drax/commits?author=lafiosca" title="Documentation">📖</a> <a href="#example-lafiosca" title="Examples">💡</a> <a href="#maintenance-lafiosca" title="Maintenance">🚧</a> <a href="#infra-lafiosca" title="Infrastructure">🚇</a></td>
|
|
431
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/LunatiqueCoder"><img src="https://avatars.githubusercontent.com/u/55203625?v=4" width="100px;" alt="Ovidiu Cristescu"/><br /><sub><b>Ovidiu Cristescu</b></sub></a><br /><a href="https://github.com/nuclearpasta/react-native-drax/commits?author=LunatiqueCoder" title="Code">💻</a> <a href="https://github.com/nuclearpasta/react-native-drax/commits?author=LunatiqueCoder" title="Documentation">📖</a> <a href="#example-LunatiqueCoder" title="Examples">💡</a> <a href="#maintenance-LunatiqueCoder" title="Maintenance">🚧</a></td>
|
|
432
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Auticiel"><img src="https://avatars.githubusercontent.com/u/8429221?v=4" width="100px;" alt="François Dupayrat"/><br /><sub><b>François Dupayrat</b></sub></a><br /><a href="https://github.com/nuclearpasta/react-native-drax/commits?author=Auticiel" title="Code">💻</a></td>
|
|
433
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jmarnold"><img src="https://avatars.githubusercontent.com/u/181667?v=4" width="100px;" alt="Josh Arnold"/><br /><sub><b>Josh Arnold</b></sub></a><br /><a href="https://github.com/nuclearpasta/react-native-drax/commits?author=jmarnold" title="Code">💻</a></td>
|
|
434
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/rnz269"><img src="https://avatars.githubusercontent.com/u/20953181?v=4" width="100px;" alt="Rahul Nallappa"/><br /><sub><b>Rahul Nallappa</b></sub></a><br /><a href="https://github.com/nuclearpasta/react-native-drax/commits?author=rnz269" title="Code">💻</a></td>
|
|
435
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/negue"><img src="https://avatars.githubusercontent.com/u/842273?v=4" width="100px;" alt="negue"/><br /><sub><b>negue</b></sub></a><br /><a href="https://github.com/nuclearpasta/react-native-drax/commits?author=negue" title="Documentation">📖</a></td>
|
|
436
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/chrisdrackett"><img src="https://avatars.githubusercontent.com/u/4378?v=4" width="100px;" alt="Chris Drackett"/><br /><sub><b>Chris Drackett</b></sub></a><br /><a href="https://github.com/nuclearpasta/react-native-drax/commits?author=chrisdrackett" title="Code">💻</a></td>
|
|
437
|
+
</tr>
|
|
438
|
+
<tr>
|
|
439
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sturdynut"><img src="https://avatars.githubusercontent.com/u/8547391?v=4" width="100px;" alt="Matti Salokangas"/><br /><sub><b>Matti Salokangas</b></sub></a><br /><a href="https://github.com/nuclearpasta/react-native-drax/commits?author=sturdynut" title="Code">💻</a></td>
|
|
440
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/afgarcia86"><img src="https://avatars.githubusercontent.com/u/3606053?v=4" width="100px;" alt="Andres Garcia"/><br /><sub><b>Andres Garcia</b></sub></a><br /><a href="https://github.com/nuclearpasta/react-native-drax/commits?author=afgarcia86" title="Code">💻</a></td>
|
|
441
|
+
</tr>
|
|
442
|
+
</tbody>
|
|
443
|
+
</table>
|
|
444
|
+
<!-- markdownlint-restore -->
|
|
445
|
+
<!-- prettier-ignore-end -->
|
|
446
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
447
|
+
|
|
448
|
+
## 📃 License
|
|
449
|
+
|
|
450
|
+
[MIT](LICENSE.md)
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
Built and maintained using [OpenKit](https://www.openkit.work/).
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
function computeAbsoluteEntries(entries, scrollOffsets) {
|
|
7
|
+
return entries.map(entry => {
|
|
8
|
+
let absX = entry.x;
|
|
9
|
+
let absY = entry.y;
|
|
10
|
+
let parentIdx = entry.parentIndex;
|
|
11
|
+
while (parentIdx >= 0 && parentIdx < entries.length) {
|
|
12
|
+
const parent = entries[parentIdx];
|
|
13
|
+
const parentScroll = scrollOffsets[parentIdx] ?? {
|
|
14
|
+
x: 0,
|
|
15
|
+
y: 0
|
|
16
|
+
};
|
|
17
|
+
absX += parent.x - parentScroll.x;
|
|
18
|
+
absY += parent.y - parentScroll.y;
|
|
19
|
+
parentIdx = parent.parentIndex;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
...entry,
|
|
23
|
+
absX,
|
|
24
|
+
absY
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function getColor(entry) {
|
|
29
|
+
if (entry.receptive && entry.draggable) return '#e07a52'; // orange — both
|
|
30
|
+
if (entry.receptive) return '#22c55e'; // green — receiver
|
|
31
|
+
if (entry.draggable) return '#3b82f6'; // blue — draggable
|
|
32
|
+
if (entry.monitoring) return '#eab308'; // yellow — monitor
|
|
33
|
+
return '#888888'; // grey — passive
|
|
34
|
+
}
|
|
35
|
+
function getLabel(entry) {
|
|
36
|
+
const parts = [];
|
|
37
|
+
if (entry.draggable) parts.push('D');
|
|
38
|
+
if (entry.receptive) parts.push('R');
|
|
39
|
+
if (entry.monitoring) parts.push('M');
|
|
40
|
+
return parts.join('+') || '?';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Debug overlay that visualizes all registered Drax views.
|
|
45
|
+
* Reads the spatial index SharedValue and renders colored borders
|
|
46
|
+
* showing view bounds, roles (draggable/receptive/monitoring), and IDs.
|
|
47
|
+
*
|
|
48
|
+
* Rendered as an absolute-fill sibling in DraxProvider when debug={true}.
|
|
49
|
+
*/
|
|
50
|
+
export const DebugOverlay = ({
|
|
51
|
+
spatialIndexSV,
|
|
52
|
+
scrollOffsetsSV
|
|
53
|
+
}) => {
|
|
54
|
+
const [entries, setEntries] = useState([]);
|
|
55
|
+
|
|
56
|
+
// Poll the spatial index periodically (SharedValues update on UI thread,
|
|
57
|
+
// reading .value on JS thread gives the latest committed value).
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const update = () => {
|
|
60
|
+
const raw = spatialIndexSV.value;
|
|
61
|
+
const scrolls = scrollOffsetsSV.value;
|
|
62
|
+
if (raw.length > 0) {
|
|
63
|
+
setEntries(computeAbsoluteEntries(raw, scrolls));
|
|
64
|
+
} else {
|
|
65
|
+
setEntries([]);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
update();
|
|
69
|
+
const interval = setInterval(update, 500);
|
|
70
|
+
return () => clearInterval(interval);
|
|
71
|
+
}, [spatialIndexSV, scrollOffsetsSV]);
|
|
72
|
+
if (entries.length === 0) return null;
|
|
73
|
+
return /*#__PURE__*/_jsx(View, {
|
|
74
|
+
style: styles.container,
|
|
75
|
+
pointerEvents: "none",
|
|
76
|
+
children: entries.map(entry => {
|
|
77
|
+
const color = getColor(entry);
|
|
78
|
+
const label = getLabel(entry);
|
|
79
|
+
return /*#__PURE__*/_jsx(View, {
|
|
80
|
+
style: [styles.overlay, {
|
|
81
|
+
left: entry.absX,
|
|
82
|
+
top: entry.absY,
|
|
83
|
+
width: entry.width,
|
|
84
|
+
height: entry.height,
|
|
85
|
+
borderColor: color
|
|
86
|
+
}],
|
|
87
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
88
|
+
style: [styles.label, {
|
|
89
|
+
backgroundColor: color
|
|
90
|
+
}],
|
|
91
|
+
children: label
|
|
92
|
+
})
|
|
93
|
+
}, entry.id);
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
const styles = StyleSheet.create({
|
|
98
|
+
container: {
|
|
99
|
+
...StyleSheet.absoluteFill,
|
|
100
|
+
zIndex: 99999
|
|
101
|
+
},
|
|
102
|
+
overlay: {
|
|
103
|
+
position: 'absolute',
|
|
104
|
+
borderWidth: 2,
|
|
105
|
+
borderStyle: 'dashed'
|
|
106
|
+
},
|
|
107
|
+
label: {
|
|
108
|
+
position: 'absolute',
|
|
109
|
+
top: -1,
|
|
110
|
+
left: -1,
|
|
111
|
+
color: '#fff',
|
|
112
|
+
fontSize: 9,
|
|
113
|
+
fontWeight: '700',
|
|
114
|
+
fontFamily: 'monospace',
|
|
115
|
+
paddingHorizontal: 3,
|
|
116
|
+
paddingVertical: 1,
|
|
117
|
+
borderRadius: 2,
|
|
118
|
+
overflow: 'hidden'
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
//# sourceMappingURL=DebugOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useState","StyleSheet","Text","View","jsx","_jsx","computeAbsoluteEntries","entries","scrollOffsets","map","entry","absX","x","absY","y","parentIdx","parentIndex","length","parent","parentScroll","getColor","receptive","draggable","monitoring","getLabel","parts","push","join","DebugOverlay","spatialIndexSV","scrollOffsetsSV","setEntries","update","raw","value","scrolls","interval","setInterval","clearInterval","style","styles","container","pointerEvents","children","color","label","overlay","left","top","width","height","borderColor","backgroundColor","id","create","absoluteFillObject","zIndex","position","borderWidth","borderStyle","fontSize","fontWeight","fontFamily","paddingHorizontal","paddingVertical","borderRadius","overflow"],"sourceRoot":"../../src","sources":["DebugOverlay.tsx"],"mappings":";;AACA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,UAAU,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAetD,SAASC,sBAAsBA,CAC7BC,OAAuB,EACvBC,aAAyB,EACR;EACjB,OAAOD,OAAO,CAACE,GAAG,CAAEC,KAAK,IAAK;IAC5B,IAAIC,IAAI,GAAGD,KAAK,CAACE,CAAC;IAClB,IAAIC,IAAI,GAAGH,KAAK,CAACI,CAAC;IAClB,IAAIC,SAAS,GAAGL,KAAK,CAACM,WAAW;IAEjC,OAAOD,SAAS,IAAI,CAAC,IAAIA,SAAS,GAAGR,OAAO,CAACU,MAAM,EAAE;MACnD,MAAMC,MAAM,GAAGX,OAAO,CAACQ,SAAS,CAAE;MAClC,MAAMI,YAAY,GAAGX,aAAa,CAACO,SAAS,CAAC,IAAI;QAAEH,CAAC,EAAE,CAAC;QAAEE,CAAC,EAAE;MAAE,CAAC;MAC/DH,IAAI,IAAIO,MAAM,CAACN,CAAC,GAAGO,YAAY,CAACP,CAAC;MACjCC,IAAI,IAAIK,MAAM,CAACJ,CAAC,GAAGK,YAAY,CAACL,CAAC;MACjCC,SAAS,GAAGG,MAAM,CAACF,WAAW;IAChC;IAEA,OAAO;MAAE,GAAGN,KAAK;MAAEC,IAAI;MAAEE;IAAK,CAAC;EACjC,CAAC,CAAC;AACJ;AAEA,SAASO,QAAQA,CAACV,KAAmB,EAAU;EAC7C,IAAIA,KAAK,CAACW,SAAS,IAAIX,KAAK,CAACY,SAAS,EAAE,OAAO,SAAS,CAAC,CAAC;EAC1D,IAAIZ,KAAK,CAACW,SAAS,EAAE,OAAO,SAAS,CAAC,CAAC;EACvC,IAAIX,KAAK,CAACY,SAAS,EAAE,OAAO,SAAS,CAAC,CAAC;EACvC,IAAIZ,KAAK,CAACa,UAAU,EAAE,OAAO,SAAS,CAAC,CAAC;EACxC,OAAO,SAAS,CAAC,CAAC;AACpB;AAEA,SAASC,QAAQA,CAACd,KAAmB,EAAU;EAC7C,MAAMe,KAAe,GAAG,EAAE;EAC1B,IAAIf,KAAK,CAACY,SAAS,EAAEG,KAAK,CAACC,IAAI,CAAC,GAAG,CAAC;EACpC,IAAIhB,KAAK,CAACW,SAAS,EAAEI,KAAK,CAACC,IAAI,CAAC,GAAG,CAAC;EACpC,IAAIhB,KAAK,CAACa,UAAU,EAAEE,KAAK,CAACC,IAAI,CAAC,GAAG,CAAC;EACrC,OAAOD,KAAK,CAACE,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG;AAC/B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAGA,CAAC;EAC3BC,cAAc;EACdC;AACiB,CAAC,KAAgB;EAClC,MAAM,CAACvB,OAAO,EAAEwB,UAAU,CAAC,GAAG/B,QAAQ,CAAkB,EAAE,CAAC;;EAE3D;EACA;EACAD,SAAS,CAAC,MAAM;IACd,MAAMiC,MAAM,GAAGA,CAAA,KAAM;MACnB,MAAMC,GAAG,GAAGJ,cAAc,CAACK,KAAK;MAChC,MAAMC,OAAO,GAAGL,eAAe,CAACI,KAAK;MACrC,IAAID,GAAG,CAAChB,MAAM,GAAG,CAAC,EAAE;QAClBc,UAAU,CAACzB,sBAAsB,CAAC2B,GAAG,EAAEE,OAAO,CAAC,CAAC;MAClD,CAAC,MAAM;QACLJ,UAAU,CAAC,EAAE,CAAC;MAChB;IACF,CAAC;IAEDC,MAAM,CAAC,CAAC;IACR,MAAMI,QAAQ,GAAGC,WAAW,CAACL,MAAM,EAAE,GAAG,CAAC;IACzC,OAAO,MAAMM,aAAa,CAACF,QAAQ,CAAC;EACtC,CAAC,EAAE,CAACP,cAAc,EAAEC,eAAe,CAAC,CAAC;EAErC,IAAIvB,OAAO,CAACU,MAAM,KAAK,CAAC,EAAE,OAAO,IAAI;EAErC,oBACEZ,IAAA,CAACF,IAAI;IAACoC,KAAK,EAAEC,MAAM,CAACC,SAAU;IAACC,aAAa,EAAC,MAAM;IAAAC,QAAA,EAChDpC,OAAO,CAACE,GAAG,CAAEC,KAAK,IAAK;MACtB,MAAMkC,KAAK,GAAGxB,QAAQ,CAACV,KAAK,CAAC;MAC7B,MAAMmC,KAAK,GAAGrB,QAAQ,CAACd,KAAK,CAAC;MAC7B,oBACEL,IAAA,CAACF,IAAI;QAEHoC,KAAK,EAAE,CACLC,MAAM,CAACM,OAAO,EACd;UACEC,IAAI,EAAErC,KAAK,CAACC,IAAI;UAChBqC,GAAG,EAAEtC,KAAK,CAACG,IAAI;UACfoC,KAAK,EAAEvC,KAAK,CAACuC,KAAK;UAClBC,MAAM,EAAExC,KAAK,CAACwC,MAAM;UACpBC,WAAW,EAAEP;QACf,CAAC,CACD;QAAAD,QAAA,eAEFtC,IAAA,CAACH,IAAI;UAACqC,KAAK,EAAE,CAACC,MAAM,CAACK,KAAK,EAAE;YAAEO,eAAe,EAAER;UAAM,CAAC,CAAE;UAAAD,QAAA,EACrDE;QAAK,CACF;MAAC,GAdFnC,KAAK,CAAC2C,EAeP,CAAC;IAEX,CAAC;EAAC,CACE,CAAC;AAEX,CAAC;AAED,MAAMb,MAAM,GAAGvC,UAAU,CAACqD,MAAM,CAAC;EAC/Bb,SAAS,EAAE;IACT,GAAGxC,UAAU,CAACsD,kBAAkB;IAChCC,MAAM,EAAE;EACV,CAAC;EACDV,OAAO,EAAE;IACPW,QAAQ,EAAE,UAAU;IACpBC,WAAW,EAAE,CAAC;IACdC,WAAW,EAAE;EACf,CAAC;EACDd,KAAK,EAAE;IACLY,QAAQ,EAAE,UAAU;IACpBT,GAAG,EAAE,CAAC,CAAC;IACPD,IAAI,EAAE,CAAC,CAAC;IACRH,KAAK,EAAE,MAAM;IACbgB,QAAQ,EAAE,CAAC;IACXC,UAAU,EAAE,KAAK;IACjBC,UAAU,EAAE,WAAW;IACvBC,iBAAiB,EAAE,CAAC;IACpBC,eAAe,EAAE,CAAC;IAClBC,YAAY,EAAE,CAAC;IACfC,QAAQ,EAAE;EACZ;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { DraxHandle } from "./DraxHandle.js";
|
|
4
|
+
import { DraxList } from "./DraxList.js";
|
|
5
|
+
import { DraxProvider } from "./DraxProvider.js";
|
|
6
|
+
import { DraxScrollView } from "./DraxScrollView.js";
|
|
7
|
+
import { DraxView } from "./DraxView.js";
|
|
8
|
+
import { SortableBoardContainer } from "./SortableBoardContainer.js";
|
|
9
|
+
import { SortableContainer } from "./SortableContainer.js";
|
|
10
|
+
import { SortableItem } from "./SortableItem.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Namespace object for convenient access to all Drax components.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { Drax } from 'react-native-drax';
|
|
18
|
+
*
|
|
19
|
+
* <Drax.Provider>
|
|
20
|
+
* <Drax.View draggable>
|
|
21
|
+
* <Drax.Handle><GripIcon /></Drax.Handle>
|
|
22
|
+
* </Drax.View>
|
|
23
|
+
* </Drax.Provider>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const Drax = {
|
|
27
|
+
Handle: DraxHandle,
|
|
28
|
+
List: DraxList,
|
|
29
|
+
Provider: DraxProvider,
|
|
30
|
+
ScrollView: DraxScrollView,
|
|
31
|
+
View: DraxView,
|
|
32
|
+
SortableBoardContainer,
|
|
33
|
+
SortableContainer,
|
|
34
|
+
SortableItem
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=Drax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DraxHandle","DraxList","DraxProvider","DraxScrollView","DraxView","SortableBoardContainer","SortableContainer","SortableItem","Drax","Handle","List","Provider","ScrollView","View"],"sourceRoot":"../../src","sources":["Drax.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,iBAAc;AACzC,SAASC,QAAQ,QAAQ,eAAY;AACrC,SAASC,YAAY,QAAQ,mBAAgB;AAC7C,SAASC,cAAc,QAAQ,qBAAkB;AACjD,SAASC,QAAQ,QAAQ,eAAY;AACrC,SAASC,sBAAsB,QAAQ,6BAA0B;AACjE,SAASC,iBAAiB,QAAQ,wBAAqB;AACvD,SAASC,YAAY,QAAQ,mBAAgB;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,IAAI,GAAG;EAClBC,MAAM,EAAET,UAAU;EAClBU,IAAI,EAAET,QAAQ;EACdU,QAAQ,EAAET,YAAY;EACtBU,UAAU,EAAET,cAAc;EAC1BU,IAAI,EAAET,QAAQ;EACdC,sBAAsB;EACtBC,iBAAiB;EACjBC;AACF,CAAU","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","DraxContext","undefined","displayName"],"sourceRoot":"../../src","sources":["DraxContext.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,OAAO;AAIrC,OAAO,MAAMC,WAAW,gBAAGD,aAAa,CACtCE,SACF,CAAC;AACDD,WAAW,CAACE,WAAW,GAAG,MAAM","ignoreList":[]}
|