react-native-reanimated-dnd 1.0.5 โ†’ 2.0.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.
Files changed (45) hide show
  1. package/README.md +373 -386
  2. package/lib/components/Draggable.js +1 -1
  3. package/lib/components/Droppable.d.ts +0 -1
  4. package/lib/components/Droppable.js +1 -1
  5. package/lib/components/Sortable.d.ts +1 -3
  6. package/lib/components/Sortable.js +1 -1
  7. package/lib/components/SortableGrid.d.ts +3 -0
  8. package/lib/components/SortableGrid.js +1 -0
  9. package/lib/components/SortableGridItem.d.ts +7 -0
  10. package/lib/components/SortableGridItem.js +1 -0
  11. package/lib/components/SortableItem.d.ts +2 -2
  12. package/lib/components/SortableItem.js +1 -1
  13. package/lib/components/sortableUtils.d.ts +33 -0
  14. package/lib/components/sortableUtils.js +1 -1
  15. package/lib/context/DropContext.js +1 -1
  16. package/lib/hooks/index.d.ts +2 -0
  17. package/lib/hooks/index.js +1 -1
  18. package/lib/hooks/safeMeasure.d.ts +3 -0
  19. package/lib/hooks/safeMeasure.js +1 -0
  20. package/lib/hooks/useDraggable.js +1 -1
  21. package/lib/hooks/useDroppable.js +1 -1
  22. package/lib/hooks/useGridSortable.d.ts +2 -0
  23. package/lib/hooks/useGridSortable.js +1 -0
  24. package/lib/hooks/useGridSortableList.d.ts +3 -0
  25. package/lib/hooks/useGridSortableList.js +1 -0
  26. package/lib/hooks/useHorizontalSortable.d.ts +2 -0
  27. package/lib/hooks/useHorizontalSortable.js +1 -0
  28. package/lib/hooks/useHorizontalSortableList.d.ts +4 -0
  29. package/lib/hooks/useHorizontalSortableList.js +1 -0
  30. package/lib/hooks/useSortable.d.ts +13 -6
  31. package/lib/hooks/useSortable.js +1 -1
  32. package/lib/hooks/useSortableList.d.ts +15 -3
  33. package/lib/hooks/useSortableList.js +1 -1
  34. package/lib/index.d.ts +7 -0
  35. package/lib/index.js +1 -1
  36. package/lib/types/draggable.d.ts +3 -0
  37. package/lib/types/grid.d.ts +148 -0
  38. package/lib/types/grid.js +1 -0
  39. package/lib/types/index.d.ts +1 -0
  40. package/lib/types/index.js +1 -1
  41. package/lib/types/sortable.d.ts +197 -19
  42. package/lib/types/sortable.js +1 -1
  43. package/lib/utils/gridCalculations.d.ts +21 -0
  44. package/lib/utils/gridCalculations.js +1 -0
  45. package/package.json +23 -15
package/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # React Native Reanimated DnD ๐ŸŽฏ
2
2
 
3
3
  <p align="center">
4
- <img src="https://github.com/user-attachments/assets/dba6226e-c407-4a12-9feb-e8f588d6c1e3" alt="React Native Reanimated DnD Demo" style="max-width: 100%; width: 100%;" />
4
+
5
+ https://github.com/user-attachments/assets/023c0a9c-194a-45a9-bb88-ac8f16f5ffd5
6
+
5
7
  </p>
6
8
  <div align="center">
7
9
 
@@ -12,15 +14,18 @@ _Powerful, performant, and built for the modern React Native developer_
12
14
  [![npm version](https://badge.fury.io/js/react-native-reanimated-dnd.svg)](https://badge.fury.io/js/react-native-reanimated-dnd)
13
15
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
14
16
  [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
15
- [![React Native](https://img.shields.io/badge/React%20Native-0.60+-green.svg)](https://reactnative.dev/)
17
+ [![React Native](https://img.shields.io/badge/React%20Native-0.80+-green.svg)](https://reactnative.dev/)
16
18
 
17
19
  <br />
18
20
 
19
- <a href="https://react-native-reanimated-dnd.netlify.app/" target="_blank">
20
- <img src="https://img.shields.io/badge/๐Ÿ“–%20Read%20the%20Docs-4f46e5?style=for-the-badge&logo=gitbook&logoColor=white&labelColor=1e293b&color=6366f1" alt="Documentation" />
21
+ <a href="https://www.npmjs.com/package/react-native-reanimated-dnd" target="_blank">
22
+ <img src="https://img.shields.io/badge/๐Ÿ“ฆ%20View%20on%20NPM-cb3837?style=for-the-badge&logo=npm&logoColor=white&labelColor=1e293b&fontSize=24" alt="NPM Package" height="36"/>
23
+ </a>
24
+ <a href="https://reanimated-dnd-docs.vercel.app/" target="_blank">
25
+ <img src="https://img.shields.io/badge/๐Ÿ“–%20Read%20the%20Docs-4f46e5?style=for-the-badge&logo=gitbook&logoColor=white&labelColor=1e293b&color=6366f1&fontSize=24" alt="Documentation" height="36"/>
21
26
  </a>
22
27
  <a href="#-interactive-examples" target="_blank">
23
- <img src="https://img.shields.io/badge/๐Ÿ“ฑ%20Try%20Live%20Demo-ff3b30?style=for-the-badge&logo=expo&logoColor=white&labelColor=1e293b" alt="Live Demo" />
28
+ <img src="https://img.shields.io/badge/๐Ÿ“ฑ%20Try%20Live%20Demo-fcba03?style=for-the-badge&logo=expo&logoColor=white&labelColor=1e293b&fontSize=24" alt="Live Demo" height="36"/>
24
29
  </a>
25
30
 
26
31
  </div>
@@ -35,15 +40,20 @@ After countless attempts with drag-and-drop solutions that don't work or are sim
35
40
 
36
41
  ## โœจ Features
37
42
 
38
- - ๐Ÿš€ **High Performance** - Built with Reanimated 3 for buttery-smooth 60fps animations
43
+ - ๐Ÿš€ **High Performance** - Built with Reanimated 4 and Worklets for buttery-smooth 60fps animations
44
+ - ๐Ÿ—๏ธ **New Architecture Ready** - Built for the modern React Native architecture used by Expo SDK 55+
45
+ - ๐Ÿ“ฆ **Expo Compatible** - Tested against Expo SDK 55 and React Native 0.83
46
+ - ๐Ÿชถ **Tiny Bundle Size** - Only 70kb unpacked size, won't bloat your app
39
47
  - ๐ŸŽฏ **Flexible API** - From simple drag-and-drop to complex sortable lists
40
48
  - ๐Ÿ“ฑ **React Native First** - Designed specifically for mobile, not ported from web
41
49
  - ๐Ÿ”ง **TypeScript Ready** - Full type safety with comprehensive definitions
42
50
  - ๐ŸŽจ **Infinitely Customizable** - Every animation, behavior, and style is configurable
43
51
  - ๐Ÿ“ฆ **Complete Component Suite** - Draggable, Droppable, Sortable, and more
44
52
  - ๐ŸŽช **Smart Collision Detection** - Multiple algorithms (center, intersect, contain)
45
- - ๐Ÿ“œ **Sortable Lists** - Drag and drop to sort a Vertical List, also
46
- supports Automatic scrolling for out of screen dragging
53
+ - ๐Ÿ“œ **Vertical & Horizontal Sortable Lists** - Drag and drop to sort lists in any direction with automatic scrolling
54
+ - ๐Ÿ”ฒ **Sortable Grids** - 2D grid drag-and-drop with flexible layouts, insert and swap modes
55
+ - โ†• **Dynamic Heights** - Sortable lists with variable item heights
56
+ - โšก **FlatList Performance** - Optional FlatList rendering for large datasets with virtualization
47
57
  - ๐ŸŽญ **Drag Handles** - Precise control with dedicated drag areas
48
58
  - ๐ŸŽฌ **Custom Animations** - Spring, timing, or bring your own animation functions
49
59
  - ๐Ÿ“ **Pixel-Perfect Positioning** - 9-point alignment system with custom offsets
@@ -53,7 +63,7 @@ After countless attempts with drag-and-drop solutions that don't work or are sim
53
63
 
54
64
  ## ๐Ÿ“ฑ Interactive Examples
55
65
 
56
- **See it in action!** A comprehensive example app with **15 interactive demos** showcasing every feature and use case.
66
+ **See it in action!** A comprehensive example app with **18 interactive demos** showcasing every feature and use case.
57
67
 
58
68
  <div align="center">
59
69
 
@@ -65,19 +75,18 @@ After countless attempts with drag-and-drop solutions that don't work or are sim
65
75
 
66
76
  **๐Ÿ“ฑ Scan & Play**
67
77
 
68
- <img src="https://github.com/user-attachments/assets/80f923f6-7c5f-42e9-9817-7770ee27a70b" alt="Expo QR Code" width="200" height="200" />
78
+ <img src="https://raw.githubusercontent.com/entropyconquers/react-native-reanimated-dnd/main/documentation/images/expo-qr-code.png" alt="Expo QR Code" width="200" height="200" />
69
79
 
70
- *Scan with your camera or Expo Go app*
80
+ _Scan with Expo Go to try the demo instantly_
71
81
 
72
82
  </td>
73
83
  <td align="center" width="50%">
74
84
 
75
85
  **๐Ÿš€ Quick Start**
76
86
 
77
- 1. Install [Expo Go](https://expo.dev/client) on your phone
87
+ 1. Install [Expo Go](https://expo.dev/go) on your phone (SDK 55)
78
88
  2. Scan the QR code with your camera
79
- 3. Open the link in Expo Go
80
- 4. Explore 15 interactive examples!
89
+ 3. Explore 18 interactive examples!
81
90
 
82
91
  **Or browse the code:**
83
92
  [**๐Ÿ“‚ View Example App โ†’**](./example-app/README.md)
@@ -88,93 +97,173 @@ After countless attempts with drag-and-drop solutions that don't work or are sim
88
97
 
89
98
  ### ๐Ÿ“š Complete Documentation
90
99
 
91
- <a href="https://react-native-reanimated-dnd.netlify.app/" target="_blank">
100
+ <a href="https://reanimated-dnd-docs.vercel.app/" target="_blank">
92
101
  <img src="https://img.shields.io/badge/๐Ÿ“–%20Documentation-Visit%20Docs-4f46e5?style=for-the-badge&logo=gitbook&logoColor=white&labelColor=1e293b" alt="Documentation" />
93
102
  </a>
94
103
 
95
- *Comprehensive guides, API reference, and interactive examples*
104
+ _Comprehensive guides, API reference, and interactive examples_
96
105
 
97
106
  </div>
98
107
 
99
108
  The example app includes:
100
109
 
101
- - ๐ŸŽต **Sortable Music Queue** - Complete list reordering with handles
102
- - ๐ŸŽฏ **Collision Detection** - Different algorithms in action
103
- - ๐ŸŽฌ **Custom Animations** - Spring, timing, and easing variations
110
+ - ๐ŸŽต **Sortable Music Queue** - Complete list reordering with drag handles
111
+ - โ‡Œ **Horizontal Sortable** - Reorderable horizontal scrolling list
112
+ - ๐Ÿ”ฒ **Sortable Grid** - 2D grid reordering with insert/swap modes
113
+ - โ†• **Dynamic Heights** - Sortable list with variable item heights
114
+ - ๐ŸŽฏ **Basic Drag & Drop** - Drag items to drop zones with pre-drag delay
115
+ - ๐ŸŽช **Drag Handles** - Dedicated drag regions for precise control
116
+ - ๐ŸŽฌ **Custom Animations** - Spring, timing, bounce & easing curves
117
+ - โœจ **Active Drop Styles** - Visual feedback on hover
118
+ - ๐Ÿ“ **Alignment & Offset** - Precise drop positioning with offsets
104
119
  - ๐Ÿ“ฆ **Boundary Constraints** - Axis-locked and bounded dragging
105
- - โœจ **Visual Feedback** - Active styles and state management
106
- - โš™๏ธ **Advanced Patterns** - Custom implementations and hooks
120
+ - ๐ŸŽฏ **Collision Detection** - Center, intersect & contain algorithms
121
+ - ๐Ÿ—บ๏ธ **Dropped Items Map** - Track items across multiple zones
122
+ - โšก **Drag State** - State enum & onStateChange lifecycle
123
+ - โš™๏ธ **Custom Draggable** - useDraggable hook implementation
107
124
 
108
- ## ๐ŸŽฌ Video Showcase
109
-
110
- **See the library in action** with these demos showcasing some of the key features and use cases.
125
+ ## ๐ŸŽฌ Demo Showcase
111
126
 
112
127
  <div align="center">
113
128
 
114
129
  <table>
115
130
  <tr>
116
- <td align="center" width="50%">
131
+ <td align="center" width="33%">
132
+
133
+ ### ๐ŸŽต Sortable Music Queue
117
134
 
118
- ### ๐Ÿ“‹ Sortable Lists
119
- *Drag and drop to reorder items with smooth animations*
135
+ _Vertical list reordering with drag handles_
120
136
 
121
- https://github.com/user-attachments/assets/1cd1929c-724b-4dda-a916-f3e69f917f7b
137
+ https://github.com/user-attachments/assets/6493c05f-571c-416d-b81d-90bee98738b4
122
138
 
123
139
  **Features:** Auto-scrolling โ€ข Drag handles โ€ข Smooth transitions
124
140
 
125
141
  </td>
126
- <td align="center" width="50%">
142
+ <td align="center" width="33%">
127
143
 
128
- ### ๐ŸŽฏ Collision Detection
129
- *Multiple algorithms for precise drop targeting*
144
+ ### โ‡Œ Horizontal Sortable
130
145
 
131
- https://github.com/user-attachments/assets/379040d7-8489-430b-bae4-3fcbde34264e
146
+ _Reorderable horizontal scrolling list_
132
147
 
133
- **Algorithms:** Center โ€ข Intersect โ€ข Contain
148
+ https://github.com/user-attachments/assets/909c687e-146d-4233-a6e9-4bc3e7b69a35
149
+
150
+ **Features:** Horizontal scroll โ€ข Handle & full item modes
151
+
152
+ </td>
153
+ <td align="center" width="33%">
154
+
155
+ ### ๐Ÿ”ฒ Grid Sortable
156
+
157
+ _2D grid reordering with insert & swap_
158
+
159
+ https://github.com/user-attachments/assets/9647af01-098c-485f-92ba-cfc39d1bba0c
160
+
161
+ **Features:** Grid layout โ€ข Insert & swap modes
134
162
 
135
163
  </td>
136
164
  </tr>
137
165
  <tr>
138
- <td align="center" width="50%">
166
+ <td align="center" width="33%">
139
167
 
140
- ### ๐ŸŽช Drag Handles
141
- *Precise control with dedicated drag areas*
168
+ ### โ†• Dynamic Heights
142
169
 
143
- https://github.com/user-attachments/assets/ec051d5b-8ba0-41b7-86ae-379de26a97dd
170
+ _Sortable list with variable item heights_
144
171
 
145
- **Features:** Touch-friendly โ€ข Visual feedback โ€ข Accessibility
172
+ https://github.com/user-attachments/assets/b53078ca-51ab-4675-9389-e8fe69492370
173
+
174
+ **Features:** Variable heights โ€ข Expand/collapse โ€ข Auto-scroll
146
175
 
147
176
  </td>
148
- <td align="center" width="50%">
177
+ <td align="center" width="33%">
149
178
 
150
- ### ๐Ÿ“ฆ Bounded Dragging
151
- *Constrain movement within specific boundaries*
179
+ ### ๐ŸŽฏ Basic Drag & Drop
180
+
181
+ _Drag items to drop zones_
182
+
183
+ https://github.com/user-attachments/assets/05859d25-6749-41b7-ae7e-cad5f864a268
152
184
 
153
- https://github.com/user-attachments/assets/7bd5045b-47c4-4d9b-a0c5-eb89122ec9c0
185
+ **Features:** Drop zones โ€ข Pre-drag delay โ€ข Visual feedback
154
186
 
155
- **Constraints:** Axis-locked โ€ข Container bounds โ€ข Custom limits
187
+ </td>
188
+ <td align="center" width="33%">
189
+
190
+ ### ๐ŸŽญ Drag Handles
191
+
192
+ _Dedicated regions for drag control_
193
+
194
+ https://github.com/user-attachments/assets/f8be7bea-0f24-4446-83be-06ede43fa02a
195
+
196
+ **Features:** Full handle โ€ข Bar handle โ€ข Header handle
156
197
 
157
198
  </td>
158
199
  </tr>
159
200
  <tr>
160
- <td align="center" width="50%">
201
+ <td align="center" width="33%">
161
202
 
162
203
  ### โœจ Active Drop Styles
163
- *Visual feedback during drag operations*
164
204
 
165
- https://github.com/user-attachments/assets/3b8a3d00-38ad-4532-bd42-173037ea61b9
205
+ _Visual hover effects on drop zones_
166
206
 
167
- **Feedback:** Hover states โ€ข Drop zones โ€ข Visual cues
207
+ https://github.com/user-attachments/assets/d4124110-6eb7-4a15-8f97-3e58b392d62e
208
+
209
+ **Feedback:** Pulse effect โ€ข Glow effect โ€ข Hover states
168
210
 
169
211
  </td>
170
- <td align="center" width="50%">
212
+ <td align="center" width="33%">
213
+
214
+ ### ๐Ÿ“ Alignment & Offset
171
215
 
172
- ### ๐Ÿ”„ State Management
173
- *Complete lifecycle tracking and callbacks*
216
+ _Precise drop positioning with offsets_
174
217
 
175
- https://github.com/user-attachments/assets/da5e526f-f2d2-4dc5-96b5-3fecc4faf57a
218
+ https://github.com/user-attachments/assets/07fd39d0-a0d8-471c-86be-b73d70027163
176
219
 
177
- **States:** Idle โ€ข Dragging โ€ข Animating โ€ข Dropped
220
+ **Features:** 9-point alignment โ€ข X/Y offset controls
221
+
222
+ </td>
223
+ <td align="center" width="33%">
224
+
225
+ ### ๐Ÿ“ฆ Bounded Dragging
226
+
227
+ _Constrain movement within boundaries_
228
+
229
+ https://github.com/user-attachments/assets/ce43a226-ec42-49c1-b528-df6599d294e1
230
+
231
+ **Constraints:** Container bounds โ€ข Axis-locked โ€ข Custom limits
232
+
233
+ </td>
234
+ </tr>
235
+ <tr>
236
+ <td align="center" width="33%">
237
+
238
+ ### ๐ŸŽช Collision Detection
239
+
240
+ _Center, intersect & contain algorithms_
241
+
242
+ https://github.com/user-attachments/assets/1ac1860a-acc1-469a-ae3e-644a22393b86
243
+
244
+ **Algorithms:** Center โ€ข Intersect โ€ข Contain
245
+
246
+ </td>
247
+ <td align="center" width="33%">
248
+
249
+ ### ๐Ÿ—บ๏ธ Dropped Items Map
250
+
251
+ _Track items across multiple zones_
252
+
253
+ https://github.com/user-attachments/assets/e4effc88-7161-4c5c-af6e-c06152cfbd09
254
+
255
+ **Features:** Multi-zone tracking โ€ข Real-time mapping
256
+
257
+ </td>
258
+ <td align="center" width="33%">
259
+
260
+ ### โšก Drag State
261
+
262
+ _State lifecycle tracking & callbacks_
263
+
264
+ https://github.com/user-attachments/assets/bceb9e7c-8f29-4630-81b0-945a7bcf29c5
265
+
266
+ **States:** Idle โ€ข Dragging โ€ข Dropped
178
267
 
179
268
  </td>
180
269
  </tr>
@@ -191,88 +280,98 @@ npm install react-native-reanimated-dnd
191
280
  ### Peer Dependencies
192
281
 
193
282
  ```bash
194
- npm install react-native-reanimated react-native-gesture-handler
283
+ npm install react-native-reanimated react-native-gesture-handler react-native-worklets
195
284
  ```
196
285
 
197
286
  Follow the setup guides:
198
287
 
199
- - [React Native Reanimated](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation)
288
+ - [React Native Worklets](https://docs.swmansion.com/react-native-worklets/docs/getting-started/installation/)
289
+ - [React Native Reanimated](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/)
200
290
  - [React Native Gesture Handler](https://docs.swmansion.com/react-native-gesture-handler/docs/installation)
201
291
 
202
- ## ๐Ÿƒโ€โ™‚๏ธ Quick Start
292
+ Make sure your Babel config uses `"react-native-worklets/plugin"` as the last plugin and that your app is running on the New Architecture, which is required by Reanimated 4.
203
293
 
204
- ### Basic Draggable
294
+ ## ๐Ÿ“‹ Requirements
205
295
 
206
- ```tsx
207
- import React from "react";
208
- import { View, Text } from "react-native";
209
- import { GestureHandlerRootView } from "react-native-gesture-handler";
210
- import { Draggable, DropProvider } from "react-native-reanimated-dnd";
296
+ ### Data Structure
211
297
 
212
- export default function App() {
213
- return (
214
- <GestureHandlerRootView style={{ flex: 1 }}>
215
- <DropProvider>
216
- <View style={{ flex: 1, padding: 20 }}>
217
- <Draggable data={{ id: "1", title: "Drag me!" }}>
218
- <View
219
- style={{
220
- padding: 20,
221
- backgroundColor: "#007AFF",
222
- borderRadius: 8,
223
- }}
224
- >
225
- <Text style={{ color: "white" }}>Drag me around!</Text>
226
- </View>
227
- </Draggable>
228
- </View>
229
- </DropProvider>
230
- </GestureHandlerRootView>
231
- );
298
+ All items in your data array **MUST** have an `id` property of type string:
299
+
300
+ ```typescript
301
+ interface YourDataType {
302
+ id: string; // Required!
303
+ // ... your other properties
232
304
  }
233
305
  ```
234
306
 
235
- ### Drag & Drop with Multiple Zones
307
+ This is essential for the library to track items during reordering.
308
+
309
+ **Example:**
310
+
311
+ ```typescript
312
+ // โœ… Good - Each item has a unique string id
313
+ const tasks = [
314
+ { id: "1", title: "Learn React Native", completed: false },
315
+ { id: "2", title: "Build an app", completed: false },
316
+ { id: "3", title: "Deploy to store", completed: true },
317
+ ];
318
+
319
+ // โŒ Bad - Missing id properties
320
+ const badTasks = [{ title: "Task 1" }, { title: "Task 2" }];
321
+
322
+ // โŒ Bad - Non-string ids
323
+ const badTasksWithNumbers = [
324
+ { id: 1, title: "Task 1" },
325
+ { id: 2, title: "Task 2" },
326
+ ];
327
+ ```
328
+
329
+ The library includes runtime validation in development mode that will warn you if items are missing valid ID properties.
330
+
331
+ ## State Management Guidelines
332
+
333
+ **IMPORTANT**: Sortable components maintain their own internal state for optimal performance and animation consistency.
334
+
335
+ ### Do NOT Do This
336
+
337
+ - Never update external state (arrays, Redux, Zustand, etc.) directly in `onMove` callbacks
338
+ - Never call `setItems()`, `setTasks()`, or similar functions during drag operations
339
+ - Never manually splice or reorder external arrays in response to drag events
340
+
341
+ ### Correct Approach
342
+
343
+ - Use `onMove` for logging, analytics, or side effects only
344
+ - Use `onDrop` with `allPositions` parameter for read-only position tracking
345
+ - Let sortable components handle their internal reordering automatically
346
+ - Use external state only for the initial data and for non-reordering updates
347
+
348
+ ### Future Features
349
+
350
+ Programmatic list operations (add, update, delete, reorder items) that work correctly with internal state management will be added in upcoming releases. This will provide safe methods to modify sortable lists externally.
351
+
352
+ ## ๐Ÿƒโ€โ™‚๏ธ Quick Start
353
+
354
+ ### Basic Drag & Drop
236
355
 
237
356
  ```tsx
238
- import React from "react";
239
- import { View, Text } from "react-native";
240
357
  import { GestureHandlerRootView } from "react-native-gesture-handler";
241
- import {
242
- Draggable,
243
- Droppable,
244
- DropProvider,
245
- } from "react-native-reanimated-dnd";
246
-
247
- export default function DragDropExample() {
248
- const handleDrop = (data: any) => {
249
- console.log("Item dropped:", data);
250
- };
358
+ import { Draggable, Droppable, DropProvider } from "react-native-reanimated-dnd";
251
359
 
360
+ export default function App() {
252
361
  return (
253
362
  <GestureHandlerRootView style={{ flex: 1 }}>
254
363
  <DropProvider>
255
- <View style={{ flex: 1, padding: 20 }}>
256
- {/* Draggable Item */}
257
- <Draggable data={{ id: "1", title: "Drag me!" }}>
258
- <View style={styles.draggableItem}>
259
- <Text>๐Ÿ“ฆ Drag me to a zone</Text>
260
- </View>
261
- </Draggable>
262
-
263
- {/* Drop Zones */}
264
- <Droppable onDrop={handleDrop}>
265
- <View style={styles.dropZone}>
266
- <Text>๐ŸŽฏ Drop Zone 1</Text>
267
- </View>
268
- </Droppable>
269
-
270
- <Droppable onDrop={handleDrop}>
271
- <View style={styles.dropZone}>
272
- <Text>๐ŸŽฏ Drop Zone 2</Text>
273
- </View>
274
- </Droppable>
275
- </View>
364
+ <Droppable onDrop={(data) => console.log("Dropped:", data)}>
365
+ <View style={styles.dropZone}>
366
+ <Text>Drop here</Text>
367
+ </View>
368
+ </Droppable>
369
+
370
+ <Draggable data={{ id: "1", title: "Drag me!" }}>
371
+ <View style={styles.item}>
372
+ <Text>Drag me around!</Text>
373
+ </View>
374
+ </Draggable>
276
375
  </DropProvider>
277
376
  </GestureHandlerRootView>
278
377
  );
@@ -282,333 +381,203 @@ export default function DragDropExample() {
282
381
  ### Sortable List
283
382
 
284
383
  ```tsx
285
- import React, { useState } from "react";
286
- import { View, Text } from "react-native";
287
- import { GestureHandlerRootView } from "react-native-gesture-handler";
288
- import { Sortable, SortableItem } from "react-native-reanimated-dnd";
384
+ import { Sortable, SortableItem, SortableRenderItemProps } from "react-native-reanimated-dnd";
385
+
386
+ const tasks = [
387
+ { id: "1", title: "Learn React Native" },
388
+ { id: "2", title: "Build an app" },
389
+ { id: "3", title: "Deploy to store" },
390
+ ];
391
+
392
+ function TaskList() {
393
+ const renderItem = useCallback((props: SortableRenderItemProps<typeof tasks[0]>) => {
394
+ const { item, id, ...rest } = props;
395
+ return (
396
+ <SortableItem key={id} id={id} data={item} {...rest}>
397
+ <View style={styles.task}>
398
+ <Text>{item.title}</Text>
399
+ <SortableItem.Handle>
400
+ <Text>โ‹ฎโ‹ฎ</Text>
401
+ </SortableItem.Handle>
402
+ </View>
403
+ </SortableItem>
404
+ );
405
+ }, []);
289
406
 
290
- interface Task {
291
- id: string;
292
- title: string;
407
+ return <Sortable data={tasks} renderItem={renderItem} itemHeight={60} />;
293
408
  }
409
+ ```
294
410
 
295
- export default function SortableExample() {
296
- const [tasks, setTasks] = useState<Task[]>([
297
- { id: "1", title: "Learn React Native" },
298
- { id: "2", title: "Build an app" },
299
- { id: "3", title: "Deploy to store" },
300
- ]);
301
-
302
- const renderTask = ({ item, id, positions, ...props }) => (
303
- <SortableItem
304
- key={id}
305
- id={id}
306
- positions={positions}
307
- {...props}
308
- onMove={(itemId, from, to) => {
309
- const newTasks = [...tasks];
310
- const [movedTask] = newTasks.splice(from, 1);
311
- newTasks.splice(to, 0, movedTask);
312
- setTasks(newTasks);
313
- }}
314
- >
315
- <View style={styles.taskItem}>
316
- <Text>{item.title}</Text>
317
-
318
- {/* Drag Handle */}
319
- <SortableItem.Handle style={styles.dragHandle}>
320
- <Text>โ‹ฎโ‹ฎ</Text>
321
- </SortableItem.Handle>
322
- </View>
323
- </SortableItem>
324
- );
411
+ ### Sortable Grid
412
+
413
+ ```tsx
414
+ import { SortableGrid, SortableGridItem } from "react-native-reanimated-dnd";
415
+
416
+ const apps = [
417
+ { id: "1", label: "Photos" },
418
+ { id: "2", label: "Music" },
419
+ { id: "3", label: "Settings" },
420
+ { id: "4", label: "Mail" },
421
+ ];
422
+
423
+ function AppGrid() {
424
+ const renderItem = useCallback((props) => {
425
+ const { item, id, ...rest } = props;
426
+ return (
427
+ <SortableGridItem key={id} id={id} {...rest}>
428
+ <View style={styles.gridItem}>
429
+ <Text>{item.label}</Text>
430
+ </View>
431
+ </SortableGridItem>
432
+ );
433
+ }, []);
325
434
 
326
435
  return (
327
- <GestureHandlerRootView style={{ flex: 1 }}>
328
- <Sortable
329
- data={tasks}
330
- renderItem={renderTask}
331
- itemHeight={60}
332
- style={{ flex: 1, padding: 16 }}
333
- />
334
- </GestureHandlerRootView>
436
+ <SortableGrid
437
+ data={apps}
438
+ renderItem={renderItem}
439
+ dimensions={{ columns: 4, itemWidth: 80, itemHeight: 80, rowGap: 12, columnGap: 12 }}
440
+ />
335
441
  );
336
442
  }
337
443
  ```
338
444
 
339
- ## ๐Ÿ“š API Reference
445
+ > **More examples:** [Quick Start Guide](https://reanimated-dnd-docs.vercel.app/docs/getting-started/quick-start) ยท [Sortable Lists](https://reanimated-dnd-docs.vercel.app/docs/examples/sortable-lists) ยท [Sortable Grids](https://reanimated-dnd-docs.vercel.app/docs/api/components/sortable-grid) ยท [All Examples](https://reanimated-dnd-docs.vercel.app/docs/examples/basic-drag-drop)
340
446
 
341
- ### Components
447
+ ## ๐Ÿ“š Documentation
342
448
 
343
- #### `<Draggable>`
449
+ Visit **[reanimated-dnd-docs.vercel.app](https://reanimated-dnd-docs.vercel.app/)** for the full documentation:
344
450
 
345
- Makes any component draggable with extensive customization options.
451
+ - **[Getting Started](https://reanimated-dnd-docs.vercel.app/docs/getting-started/installation)** โ€” Installation, setup, and quick start
452
+ - **[Components](https://reanimated-dnd-docs.vercel.app/docs/api/components/draggable)** โ€” Draggable, Droppable, Sortable, SortableGrid, SortableItem
453
+ - **[Hooks](https://reanimated-dnd-docs.vercel.app/docs/api/hooks/useDraggable)** โ€” useDraggable, useDroppable, useSortable, useGridSortable
454
+ - **[Guides](https://reanimated-dnd-docs.vercel.app/docs/guides/animations)** โ€” Animations, collision algorithms, performance, accessibility
455
+ - **[Examples](https://reanimated-dnd-docs.vercel.app/docs/examples/basic-drag-drop)** โ€” Interactive code examples for every feature
456
+ - **[API Reference](https://reanimated-dnd-docs.vercel.app/docs/api/overview)** โ€” Complete types, enums, and utilities
346
457
 
347
- ```tsx
348
- <Draggable
349
- data={any} // Data associated with the item
350
- onDragStart={(data) => void} // Called when dragging starts
351
- onDragEnd={(data) => void} // Called when dragging ends
352
- onDragging={(position) => void} // Called during dragging
353
- onStateChange={(state) => void} // Called on state changes
354
- dragDisabled={boolean} // Disable dragging
355
- collisionAlgorithm="center|intersect|contain" // Collision detection method
356
- dragAxis="x|y|both" // Constrain movement axis
357
- dragBoundsRef={RefObject} // Boundary container reference
358
- animationFunction={(toValue) => Animation} // Custom animation function
359
- style={StyleProp<ViewStyle>} // Component styling
360
- >
361
- {children}
362
- </Draggable>
363
- ```
364
-
365
- #### `<Droppable>`
458
+ ## ๐Ÿƒโ€โ™‚๏ธ Running the Example App
366
459
 
367
- Creates drop zones with visual feedback and capacity management.
460
+ 1. Clone the repository:
368
461
 
369
- ```tsx
370
- <Droppable
371
- onDrop={(data) => void} // Called when item is dropped
372
- onActiveChange={(isActive) => void} // Called on hover state change
373
- dropDisabled={boolean} // Disable drop functionality
374
- dropAlignment="top-left|center|bottom-right|..." // Drop positioning
375
- dropOffset={{ x: number, y: number }} // Position offset
376
- activeStyle={StyleProp<ViewStyle>} // Style when active
377
- capacity={number} // Maximum items allowed
378
- droppableId={string} // Unique identifier
379
- >
380
- {children}
381
- </Droppable>
462
+ ```bash
463
+ git clone https://github.com/entropyconquers/react-native-reanimated-dnd.git
464
+ cd react-native-reanimated-dnd
382
465
  ```
383
466
 
384
- #### `<Sortable>`
385
-
386
- High-level component for sortable lists with auto-scrolling.
467
+ 2. Install dependencies (uses npm workspaces):
387
468
 
388
- ```tsx
389
- <Sortable
390
- data={Array<{ id: string }>} // Array of items to render
391
- renderItem={(props) => ReactNode} // Render function for items
392
- itemHeight={number} // Height of each item
393
- itemKeyExtractor={(item) => string} // Custom key extractor
394
- style={StyleProp<ViewStyle>} // List container style
395
- contentContainerStyle={StyleProp<ViewStyle>} // Content container style
396
- />
469
+ ```bash
470
+ npm install
397
471
  ```
398
472
 
399
- #### `<SortableItem>`
473
+ 3. Run the example app:
400
474
 
401
- Individual item within a sortable list with gesture handling.
475
+ ```bash
476
+ # iOS
477
+ npm run start --workspace example-app
478
+ # then press 'i' for iOS or 'a' for Android
402
479
 
403
- ```tsx
404
- <SortableItem
405
- id={string} // Unique identifier
406
- data={any} // Item data
407
- positions={SharedValue} // Position tracking
408
- onMove={(id, from, to) => void} // Called when item moves
409
- onDragStart={(id, position) => void} // Called when dragging starts
410
- onDrop={(id, position) => void} // Called when item is dropped
411
- onDragging={(id, overItemId, y) => void} // Called during dragging
412
- style={StyleProp<ViewStyle>} // Item styling
413
- animatedStyle={StyleProp<AnimatedStyle>} // Animated styling
414
- >
415
- {children}
416
- </SortableItem>
480
+ # Or run directly:
481
+ npx expo run:ios --cwd example-app
482
+ npx expo run:android --cwd example-app
417
483
  ```
418
484
 
419
- ### Hooks
420
-
421
- #### `useDraggable(options)`
422
-
423
- Core hook for implementing draggable functionality.
424
-
425
- #### `useDroppable(options)`
426
-
427
- Core hook for implementing droppable functionality.
428
-
429
- #### `useSortable(options)`
430
-
431
- Hook for individual sortable items with position management.
432
-
433
- #### `useSortableList(options)`
434
-
435
- Hook for managing entire sortable lists with auto-scrolling.
485
+ **Note:** Reanimated 4 requires the New Architecture, so you must use a development build (`npx expo run:ios` / `npx expo run:android`), not Expo Go.
436
486
 
437
- ### Context
487
+ The example app includes all 18 interactive examples showcasing every feature of the library.
438
488
 
439
- #### `<DropProvider>`
489
+ ## ๐Ÿ—บ๏ธ Project Roadmap
440
490
 
441
- Required context provider that manages global drag-and-drop state.
491
+ I am constantly working to improve React Native Reanimated DnD. Here's what's coming next:
442
492
 
443
- ```tsx
444
- <DropProvider>{/* All draggable and droppable components */}</DropProvider>
445
- ```
493
+ ### โœ… v2.0.0 (Current)
446
494
 
447
- ### Types & Enums
495
+ **Reanimated 4 + Worklets Migration**
448
496
 
449
- #### `DraggableState`
497
+ - ๐Ÿš€ **Reanimated 4 & Worklets** - Migrated from Reanimated 3 to Reanimated 4 with react-native-worklets
498
+ - ๐Ÿ—๏ธ **New Architecture** - Built for React Native's New Architecture (required by Reanimated 4)
499
+ - ๐Ÿ“ฆ **Expo SDK 55** - Tested and compatible with Expo SDK 55 and React Native 0.83
500
+ - ๐Ÿ”ง **Handle Registration** - Replaced tree-walking handle detection with a registration pattern
501
+ - โšก **Improved Scheduling** - Uses `scheduleOnRN`/`scheduleOnUI` for better worklet-to-JS communication
502
+ - ๐ŸŽฏ **Pre-drag Delay** - New `preDragDelay` prop for distinguishing taps from drags
503
+ - ๐Ÿ“ **npm Workspaces** - Example app now uses workspace-based development setup
504
+ - ๐Ÿ”ฒ **Sortable Grids** - 2D grid drag-and-drop with flexible layouts and insert/swap modes
505
+ - โ†• **Dynamic Heights** - Sortable list support for variable item heights
450
506
 
451
- ```tsx
452
- enum DraggableState {
453
- IDLE = "idle",
454
- DRAGGING = "dragging",
455
- ANIMATING = "animating",
456
- }
457
- ```
507
+ ### ๐ŸŽฏ Next Release
458
508
 
459
- #### `CollisionAlgorithm`
509
+ **Focus: Enhanced Functionality & New Features**
460
510
 
461
- ```tsx
462
- type CollisionAlgorithm = "center" | "intersect" | "contain";
463
- ```
511
+ - ๐Ÿ› **Bug Fixes & Issues Resolution**
464
512
 
465
- #### `DropAlignment`
513
+ - Address existing reported issues
514
+ - Performance optimizations
515
+ - Gesture handling improvements
516
+ - API Improvements
466
517
 
467
- ```tsx
468
- type DropAlignment =
469
- | "top-left"
470
- | "top-center"
471
- | "top-right"
472
- | "center-left"
473
- | "center"
474
- | "center-right"
475
- | "bottom-left"
476
- | "bottom-center"
477
- | "bottom-right";
478
- ```
518
+ - ๐Ÿช† **Nested Sortable Lists**
479
519
 
480
- ## ๐ŸŽจ Advanced Usage
520
+ - Multi-level hierarchy support
521
+ - Collapse/expand functionality
522
+ - Parent-child relationship management
523
+ - Tree-like data structure handling
481
524
 
482
- ### Custom Animations
525
+ - ๐Ÿ“‹ **Kanban Board Support**
526
+ - Cross-list dragging capabilities
527
+ - Multiple column support
528
+ - Inter-list item transfer
529
+ - Board-level state management
483
530
 
484
- ```tsx
485
- import { withTiming, withSpring, Easing } from "react-native-reanimated";
486
-
487
- // Smooth timing animation
488
- const smoothAnimation = (toValue) => {
489
- "worklet";
490
- return withTiming(toValue, {
491
- duration: 300,
492
- easing: Easing.bezier(0.25, 0.1, 0.25, 1),
493
- });
494
- };
495
-
496
- // Spring animation
497
- const springAnimation = (toValue) => {
498
- "worklet";
499
- return withSpring(toValue, {
500
- damping: 15,
501
- stiffness: 150,
502
- });
503
- };
504
-
505
- <Draggable animationFunction={springAnimation}>{/* content */}</Draggable>;
506
- ```
531
+ ### ๐Ÿ’ก Community Requests
507
532
 
508
- ### Collision Detection Strategies
533
+ Vote on features you'd like to see by raising an issue.
509
534
 
510
- ```tsx
511
- // Precise center-point collision
512
- <Draggable collisionAlgorithm="center">
513
- {/* Requires center point to be over drop zone */}
514
- </Draggable>
515
-
516
- // Forgiving intersection collision (default)
517
- <Draggable collisionAlgorithm="intersect">
518
- {/* Any overlap triggers collision */}
519
- </Draggable>
520
-
521
- // Strict containment collision
522
- <Draggable collisionAlgorithm="contain">
523
- {/* Entire draggable must be within drop zone */}
524
- </Draggable>
525
- ```
535
+ **Have an idea?** [Open a feature request](https://github.com/entropyconquers/react-native-reanimated-dnd/issues/new?assignees=&labels=enhancement&template=feature_request.md) and let me know!
526
536
 
527
- ### Drag Handles
537
+ ## ๐Ÿค– AI Integration Skill
528
538
 
529
- ```tsx
530
- <SortableItem id={item.id} {...props}>
531
- <View style={styles.itemContainer}>
532
- <Text>{item.title}</Text>
533
-
534
- {/* Only this handle area can initiate dragging */}
535
- <SortableItem.Handle style={styles.dragHandle}>
536
- <View style={styles.handleIcon}>
537
- <View style={styles.dot} />
538
- <View style={styles.dot} />
539
- <View style={styles.dot} />
540
- </View>
541
- </SortableItem.Handle>
542
- </View>
543
- </SortableItem>
544
- ```
539
+ Speed up development with the official [agent skill](https://agentskills.io). It teaches AI coding agents (Claude Code, Codex, Cursor, Gemini CLI, Copilot, and 30+ more) the full API so they generate correct code โ€” no hallucinated props.
545
540
 
546
- ### Bounded Dragging
541
+ ```bash
542
+ # Install via npx skills (auto-detects your agents)
543
+ npx skills add entropyconquers/react-native-reanimated-dnd
547
544
 
548
- ```tsx
549
- const containerRef = useRef<View>(null);
550
-
551
- <View ref={containerRef} style={styles.container}>
552
- <Draggable
553
- data={data}
554
- dragBoundsRef={containerRef}
555
- dragAxis="x" // Constrain to horizontal movement
556
- >
557
- {/* content */}
558
- </Draggable>
559
- </View>;
545
+ # Or install globally
546
+ npx skills add entropyconquers/react-native-reanimated-dnd -g
560
547
  ```
561
548
 
562
- ### Drop Zone Capacity
549
+ Once installed, just describe what you want:
563
550
 
564
- ```tsx
565
- <Droppable
566
- capacity={3}
567
- onDrop={(data) => {
568
- if (currentItems.length < 3) {
569
- addItem(data);
570
- }
571
- }}
572
- activeStyle={{
573
- backgroundColor: currentItems.length < 3 ? "#e8f5e8" : "#ffe8e8",
574
- }}
575
- >
576
- <Text>Drop Zone ({currentItems.length}/3)</Text>
577
- </Droppable>
578
- ```
551
+ > "Add a sortable list where I can reorder items by dragging"
579
552
 
580
- ## ๐Ÿƒโ€โ™‚๏ธ Running the Example App
553
+ > "Create a drag and drop interface with drop zones"
581
554
 
582
- 1. Clone the repository:
555
+ > "Make a reorderable 3-column grid"
583
556
 
584
- ```bash
585
- git clone https://github.com/entropyconquers/react-native-reanimated-dnd.git
586
- cd react-native-reanimated-dnd
587
- ```
588
-
589
- 2. Install dependencies:
557
+ Your agent will generate complete, working implementations with correct imports, props, and state management.
590
558
 
591
- ```bash
592
- npm install
593
- cd example-app
594
- npm install
595
- ```
559
+ The skill ships in both `.claude/skills/` (Claude Code) and `.agents/skills/` (Codex, Cursor, Gemini CLI, Copilot, and others) for universal agent compatibility. See the [AI Integration Skill docs](https://reanimated-dnd-docs.vercel.app/docs/getting-started/ai-skill) for all installation options and the full agent compatibility table.
596
560
 
597
- 3. Run the example app:
561
+ ## ๐Ÿค Contributing
598
562
 
599
- ```bash
600
- # iOS
601
- npx expo run:ios
563
+ Contributions are always welcome! We believe in building this library together with the community.
602
564
 
603
- # Android
604
- npx expo run:android
605
- ```
565
+ **Ways to contribute:**
606
566
 
607
- The example app includes all 15 interactive examples showcasing every feature of the library.
567
+ - ๐Ÿ› Report bugs and issues
568
+ - โœจ Suggest new features
569
+ - ๐Ÿ”ง Submit pull requests
570
+ - ๐Ÿ“š Improve documentation
571
+ - ๐Ÿงช Write tests
572
+ - ๐Ÿ’ฌ Help others in discussions
608
573
 
609
- ## ๐Ÿค Contributing
574
+ Please see our [**Contributing Guide**](CONTRIBUTING.md) for detailed information on:
610
575
 
611
- Contributions are always welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
576
+ - Setting up the development environment
577
+ - Code style guidelines
578
+ - Pull request process
579
+ - Testing requirements
580
+ - Community guidelines
612
581
 
613
582
  ## ๐Ÿ“„ License
614
583
 
@@ -621,12 +590,30 @@ MIT ยฉ [Vishesh Raheja](https://github.com/entropyconquers)
621
590
  - Inspired by the React ecosystem's drag-and-drop libraries
622
591
  - Special thanks to the React Native community for feedback and contributions
623
592
 
593
+ ## โ˜• Support the Project
594
+
595
+ <div align="center">
596
+ <body>
597
+ If this library has helped you build amazing apps, consider supporting its development!
598
+ </br></br>
599
+ <a href="https://www.buymeacoffee.com/entropyconquers" target="_blank">
600
+ <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me a Coffee" style="height: 60px; width: 217px;">
601
+ </a>
602
+ </br>
603
+ </br>
604
+ Your support helps maintain and improve this library for the entire React Native community! ๐Ÿš€
605
+ </body>
606
+ </html>
607
+
608
+ </div>
609
+ <br/>
610
+
624
611
  ---
625
612
 
626
613
  <div align="center">
627
614
 
628
615
  **Made with โค๏ธ for the React Native community**
629
616
 
630
- [โญ Star on GitHub](https://github.com/entropyconquers/react-native-reanimated-dnd) โ€ข [๐Ÿ“ฑ Try the Demo](https://github.com/entropyconquers/react-native-reanimated-dnd/tree/main/example-app) โ€ข [๐Ÿ“– Documentation](https://github.com/entropyconquers/react-native-reanimated-dnd#readme)
617
+ [โญ Star on GitHub](https://github.com/entropyconquers/react-native-reanimated-dnd) โ€ข [๐Ÿ“ฑ Try the Demo](https://github.com/entropyconquers/react-native-reanimated-dnd/tree/main/example-app) โ€ข [๐Ÿ“– Documentation](https://reanimated-dnd-docs.vercel.app/)
631
618
 
632
619
  </div>