react-native-reanimated-dnd 1.0.2 → 1.0.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.
@@ -7,426 +7,93 @@ export declare enum ScrollDirection {
7
7
  Up = "up",
8
8
  Down = "down"
9
9
  }
10
- /**
11
- * Configuration options for the useSortable hook.
12
- *
13
- * @template T - The type of data associated with the sortable item
14
- */
15
10
  export interface UseSortableOptions<T> {
16
- /**
17
- * Unique identifier for this sortable item. Must be unique within the sortable list.
18
- * Used for tracking position changes and managing reordering logic.
19
- *
20
- * @example
21
- * ```typescript
22
- * const itemId = `task-${task.id}`;
23
- * ```
24
- */
25
11
  id: string;
26
- /**
27
- * Shared value containing the current positions of all items in the sortable list.
28
- * This is typically managed by the parent sortable list component.
29
- *
30
- * @example
31
- * ```typescript
32
- * // Managed by useSortableList hook
33
- * const positions = useSharedValue({
34
- * 'item-1': 0,
35
- * 'item-2': 1,
36
- * 'item-3': 2
37
- * });
38
- * ```
39
- */
40
12
  positions: SharedValue<{
41
13
  [id: string]: number;
42
14
  }>;
43
- /**
44
- * Shared value representing the current scroll position (lower bound) of the container.
45
- * Used for auto-scrolling during drag operations.
46
- */
47
15
  lowerBound: SharedValue<number>;
48
- /**
49
- * Shared value indicating the current auto-scroll direction.
50
- * Used to trigger automatic scrolling when dragging near container edges.
51
- */
52
16
  autoScrollDirection: SharedValue<ScrollDirection>;
53
- /**
54
- * Total number of items in the sortable list.
55
- * Used for boundary calculations and position validation.
56
- */
57
17
  itemsCount: number;
58
- /**
59
- * Height of each item in pixels. All items must have the same height.
60
- * Used for position calculations and auto-scrolling.
61
- *
62
- * @example
63
- * ```typescript
64
- * const ITEM_HEIGHT = 60; // 60px per item
65
- * ```
66
- */
67
18
  itemHeight: number;
68
- /**
69
- * Height of the scrollable container in pixels.
70
- * Used for auto-scroll calculations and determining scroll boundaries.
71
- *
72
- * @default 500
73
- */
74
19
  containerHeight?: number;
75
- /**
76
- * Callback fired when an item's position changes within the list.
77
- * This is called for both the moved item and any items that were displaced.
78
- *
79
- * @param id - The ID of the item that moved
80
- * @param from - The previous position index
81
- * @param to - The new position index
82
- *
83
- * @example
84
- * ```typescript
85
- * const handleMove = (id: string, from: number, to: number) => {
86
- * console.log(`Item ${id} moved from position ${from} to ${to}`);
87
- * // Update your data model
88
- * reorderItems(id, from, to);
89
- * };
90
- * ```
91
- */
92
20
  onMove?: (id: string, from: number, to: number) => void;
93
- /**
94
- * Callback fired when dragging starts for this item.
95
- *
96
- * @param id - The ID of the item being dragged
97
- * @param position - The current position index of the item
98
- *
99
- * @example
100
- * ```typescript
101
- * const handleDragStart = (id: string, position: number) => {
102
- * console.log(`Started dragging item ${id} from position ${position}`);
103
- * setDraggingItem(id);
104
- * hapticFeedback();
105
- * };
106
- * ```
107
- */
108
21
  onDragStart?: (id: string, position: number) => void;
109
- /**
110
- * Callback fired when dragging ends for this item.
111
- *
112
- * @param id - The ID of the item that was being dragged
113
- * @param position - The final position index of the item
114
- *
115
- * @example
116
- * ```typescript
117
- * const handleDrop = (id: string, position: number) => {
118
- * console.log(`Dropped item ${id} at position ${position}`);
119
- * setDraggingItem(null);
120
- * saveNewOrder();
121
- * };
122
- * ```
123
- */
124
22
  onDrop?: (id: string, position: number) => void;
125
- /**
126
- * Callback fired continuously while dragging, providing real-time position updates.
127
- * Useful for showing visual feedback or updating UI during drag operations.
128
- *
129
- * @param id - The ID of the item being dragged
130
- * @param overItemId - The ID of the item currently being hovered over (null if none)
131
- * @param yPosition - The current Y position of the dragged item
132
- *
133
- * @example
134
- * ```typescript
135
- * const handleDragging = (id: string, overItemId: string | null, yPosition: number) => {
136
- * if (overItemId) {
137
- * console.log(`Item ${id} is hovering over ${overItemId}`);
138
- * setHoverTarget(overItemId);
139
- * } else {
140
- * setHoverTarget(null);
141
- * }
142
- * };
143
- * ```
144
- */
145
23
  onDragging?: (id: string, overItemId: string | null, yPosition: number) => void;
146
- /**
147
- * Children elements - used internally for handle detection.
148
- * @internal
149
- */
150
- children?: React.ReactNode;
151
- /**
152
- * Handle component type - used internally for handle detection.
153
- * @internal
154
- */
155
- handleComponent?: React.ComponentType<any>;
156
24
  }
157
- /**
158
- * Return value from the useSortable hook.
159
- */
160
25
  export interface UseSortableReturn {
161
- /**
162
- * Animated style to apply to the sortable item.
163
- * Contains position transforms and visual effects for dragging state.
164
- */
165
26
  animatedStyle: StyleProp<ViewStyle>;
166
- /**
167
- * Pan gesture handler for drag interactions.
168
- * Attach this to a PanGestureHandler to enable dragging.
169
- */
170
27
  panGestureHandler: any;
171
- /**
172
- * Whether this item is currently being moved/dragged.
173
- * Useful for conditional styling or behavior.
174
- */
175
28
  isMoving: boolean;
176
- /**
177
- * Whether this sortable item has a handle component.
178
- * When true, only the handle can initiate dragging.
179
- * When false, the entire item is draggable.
180
- */
181
29
  hasHandle: boolean;
182
30
  }
183
- /**
184
- * Configuration options for the useSortableList hook.
185
- *
186
- * @template TData - The type of data items in the sortable list
187
- */
188
31
  export interface UseSortableListOptions<TData> {
189
- /**
190
- * Array of data items to be rendered as sortable list items.
191
- * Each item must have an `id` property for tracking.
192
- *
193
- * @example
194
- * ```typescript
195
- * const tasks = [
196
- * { id: '1', title: 'Task 1', completed: false },
197
- * { id: '2', title: 'Task 2', completed: true },
198
- * { id: '3', title: 'Task 3', completed: false }
199
- * ];
200
- * ```
201
- */
202
32
  data: TData[];
203
- /**
204
- * Height of each item in pixels. All items must have the same height
205
- * for proper position calculations and smooth animations.
206
- *
207
- * @example
208
- * ```typescript
209
- * const ITEM_HEIGHT = 80; // Each list item is 80px tall
210
- * ```
211
- */
212
33
  itemHeight: number;
213
- /**
214
- * Function to extract a unique key from each data item.
215
- * If not provided, defaults to using the `id` property.
216
- *
217
- * @param item - The data item
218
- * @param index - The index of the item in the array
219
- * @returns Unique string identifier for the item
220
- *
221
- * @default (item) => item.id
222
- *
223
- * @example
224
- * ```typescript
225
- * // Custom key extractor for items without id property
226
- * const keyExtractor = (item, index) => `${item.type}-${item.name}-${index}`;
227
- *
228
- * // Using a compound key
229
- * const keyExtractor = (item) => `${item.category}_${item.id}`;
230
- * ```
231
- */
232
34
  itemKeyExtractor?: (item: TData, index: number) => string;
233
35
  }
234
- /**
235
- * Return value from the useSortableList hook.
236
- *
237
- * @template TData - The type of data items in the sortable list
238
- */
239
36
  export interface UseSortableListReturn<TData> {
240
- /**
241
- * Shared value containing the current positions of all items.
242
- * Maps item IDs to their current position indices.
243
- *
244
- * @example
245
- * ```typescript
246
- * // positions.value might look like:
247
- * {
248
- * 'item-1': 0,
249
- * 'item-2': 1,
250
- * 'item-3': 2
251
- * }
252
- * ```
253
- */
254
37
  positions: any;
255
- /**
256
- * Shared value tracking the current scroll position.
257
- * Used for auto-scrolling during drag operations.
258
- */
259
38
  scrollY: any;
260
- /**
261
- * Shared value indicating the current auto-scroll direction.
262
- * Used to trigger automatic scrolling when dragging near edges.
263
- */
264
39
  autoScroll: any;
265
- /**
266
- * Animated ref for the scroll view component.
267
- * Used for programmatic scrolling during drag operations.
268
- */
269
40
  scrollViewRef: any;
270
- /**
271
- * Ref for the drop provider context.
272
- * Used for triggering position updates after scroll events.
273
- */
274
41
  dropProviderRef: React.RefObject<DropProviderRef>;
275
- /**
276
- * Animated scroll handler to attach to the ScrollView.
277
- * Tracks scroll position for auto-scroll calculations.
278
- */
279
42
  handleScroll: any;
280
- /**
281
- * Callback to call when scrolling ends.
282
- * Triggers position recalculation for accurate drop zone detection.
283
- */
284
43
  handleScrollEnd: () => void;
285
- /**
286
- * Total height of the scrollable content.
287
- * Calculated as `data.length * itemHeight`.
288
- */
289
44
  contentHeight: number;
290
- /**
291
- * Helper function to get props for individual sortable items.
292
- *
293
- * @param item - The data item
294
- * @param index - The index of the item in the array
295
- * @returns Props object to pass to the sortable item component
296
- *
297
- * @example
298
- * ```typescript
299
- * {data.map((item, index) => {
300
- * const itemProps = getItemProps(item, index);
301
- * return (
302
- * <SortableItem key={itemProps.id} {...itemProps}>
303
- * <Text>{item.title}</Text>
304
- * </SortableItem>
305
- * );
306
- * })}
307
- * ```
308
- */
309
45
  getItemProps: (item: TData, index: number) => {
310
- /** Unique identifier for the item */
311
46
  id: string;
312
- /** Shared positions object */
313
47
  positions: any;
314
- /** Shared scroll position */
315
48
  lowerBound: any;
316
- /** Shared auto-scroll direction */
317
49
  autoScrollDirection: any;
318
- /** Total number of items */
319
50
  itemsCount: number;
320
- /** Height of each item */
321
51
  itemHeight: number;
322
52
  };
323
53
  }
324
- /**
325
- * Props interface for the SortableItem component.
326
- *
327
- * @template T - The type of data associated with the sortable item
328
- *
329
- * @see {@link SortableItem} for component usage
330
- * @see {@link useSortable} for the underlying hook
331
- * @see {@link UseSortableOptions} for hook configuration options
332
- * @see {@link UseSortableReturn} for hook return details
333
- */
334
54
  export interface SortableItemProps<T> {
335
- /** Unique identifier for this sortable item */
336
55
  id: string;
337
- /** Data associated with this sortable item */
338
56
  data: T;
339
- /** Shared value containing positions of all items in the list */
340
57
  positions: SharedValue<{
341
58
  [id: string]: number;
342
59
  }>;
343
- /** Shared value representing the current scroll position */
344
60
  lowerBound: SharedValue<number>;
345
- /** Shared value indicating the current auto-scroll direction */
346
61
  autoScrollDirection: SharedValue<ScrollDirection>;
347
- /** Total number of items in the sortable list */
348
62
  itemsCount: number;
349
- /** Height of each item in pixels */
350
63
  itemHeight: number;
351
- /** Height of the scrollable container (optional) */
352
64
  containerHeight?: number;
353
- /** Child components to render inside the sortable item */
354
65
  children: ReactNode;
355
- /** Style to apply to the item container */
356
66
  style?: StyleProp<ViewStyle>;
357
- /** Additional animated style to apply */
358
67
  animatedStyle?: StyleProp<ViewStyle>;
359
- /** Callback fired when item position changes */
360
68
  onMove?: (id: string, from: number, to: number) => void;
361
- /** Callback fired when dragging starts */
362
69
  onDragStart?: (id: string, position: number) => void;
363
- /** Callback fired when dragging ends */
364
70
  onDrop?: (id: string, position: number) => void;
365
- /** Callback fired during dragging with position updates */
366
71
  onDragging?: (id: string, overItemId: string | null, yPosition: number) => void;
367
72
  }
368
- /**
369
- * Props interface for the Sortable component.
370
- *
371
- * @template TData - The type of data items in the sortable list
372
- *
373
- * @see {@link Sortable} for component usage
374
- * @see {@link useSortableList} for the underlying hook
375
- * @see {@link UseSortableListOptions} for hook configuration options
376
- * @see {@link UseSortableListReturn} for hook return details
377
- */
378
73
  export interface SortableProps<TData> {
379
- /** Array of data items to render as sortable list */
380
74
  data: TData[];
381
- /** Function to render each sortable item */
382
75
  renderItem: (props: SortableRenderItemProps<TData>) => ReactNode;
383
- /** Height of each item in pixels */
384
76
  itemHeight: number;
385
- /** Style to apply to the scroll view */
386
77
  style?: StyleProp<ViewStyle>;
387
- /** Style to apply to the scroll view content container */
388
78
  contentContainerStyle?: StyleProp<ViewStyle>;
389
- /** Function to extract unique key from each item */
390
79
  itemKeyExtractor?: (item: TData, index: number) => string;
391
80
  }
392
- /**
393
- * Props passed to the renderItem function in Sortable component.
394
- *
395
- * @template TData - The type of data item being rendered
396
- *
397
- * @see {@link SortableProps} for usage
398
- * @see {@link Sortable} for component usage
399
- * @see {@link SortableItem} for individual item component
400
- */
401
81
  export interface SortableRenderItemProps<TData> {
402
- /** The data item being rendered */
403
82
  item: TData;
404
- /** Index of the item in the original data array */
405
83
  index: number;
406
- /** Unique identifier for this item */
407
84
  id: string;
408
- /** Shared value containing positions of all items */
409
85
  positions: SharedValue<{
410
86
  [id: string]: number;
411
87
  }>;
412
- /** Shared value representing the current scroll position */
413
88
  lowerBound: SharedValue<number>;
414
- /** Shared value indicating the current auto-scroll direction */
415
89
  autoScrollDirection: SharedValue<ScrollDirection>;
416
- /** Total number of items in the list */
417
90
  itemsCount: number;
418
- /** Height of each item in pixels */
419
91
  itemHeight: number;
420
92
  }
421
93
  export interface SortableContextValue {
422
94
  panGestureHandler: any;
423
95
  }
424
- /**
425
- * Props for the SortableHandle component.
426
- */
427
96
  export interface SortableHandleProps {
428
- /** The content to render inside the handle */
429
97
  children: React.ReactNode;
430
- /** Optional style to apply to the handle */
431
98
  style?: StyleProp<ViewStyle>;
432
99
  }
@@ -1,6 +1 @@
1
- export var ScrollDirection;
2
- (function (ScrollDirection) {
3
- ScrollDirection["None"] = "none";
4
- ScrollDirection["Up"] = "up";
5
- ScrollDirection["Down"] = "down";
6
- })(ScrollDirection || (ScrollDirection = {}));
1
+ export var ScrollDirection;!function(o){o.None="none",o.Up="up",o.Down="down"}(ScrollDirection||(ScrollDirection={}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-reanimated-dnd",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A powerful drag-and-drop library for React Native using Reanimated 3",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",
@@ -15,7 +15,9 @@
15
15
  },
16
16
  "sideEffects": false,
17
17
  "scripts": {
18
- "build": "tsc",
18
+ "build": "tsc && npm run minify",
19
+ "build:clean": "rm -rf lib && npm run build",
20
+ "minify": "node scripts/build.js",
19
21
  "type-check": "tsc --noEmit",
20
22
  "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,yml,yaml}\" --ignore-path .prettierignore",
21
23
  "format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,md,yml,yaml}\" --ignore-path .prettierignore"
@@ -34,6 +36,7 @@
34
36
  "type": "git",
35
37
  "url": "git+https://github.com/entropyconquers/react-native-reanimated-dnd.git"
36
38
  },
39
+ "homepage": "https://react-native-reanimated-dnd.netlify.app/",
37
40
  "peerDependencies": {
38
41
  "react": ">=16.8.0",
39
42
  "react-native": ">=0.60.0",
@@ -49,10 +52,12 @@
49
52
  "react-native": "^0.72.0",
50
53
  "react-native-reanimated": "^3.5.0",
51
54
  "react-native-gesture-handler": "^2.13.0",
52
- "prettier": "^3.5.3"
55
+ "prettier": "^3.5.3",
56
+ "terser": "^5.36.0"
53
57
  },
54
58
  "files": [
55
- "lib/",
59
+ "lib/**/*.js",
60
+ "lib/**/*.d.ts",
56
61
  "README.md",
57
62
  "LICENSE"
58
63
  ]