react-native-drax 0.10.3 → 0.11.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/.eslintrc.js +2 -73
  2. package/.prettierrc +16 -0
  3. package/README.md +81 -1
  4. package/build/AllHoverViews.d.ts +0 -0
  5. package/build/AllHoverViews.js +30 -0
  6. package/build/DraxContext.d.ts +0 -1
  7. package/build/DraxList.d.ts +3 -3
  8. package/build/DraxList.js +231 -216
  9. package/build/DraxListItem.d.ts +7 -0
  10. package/build/DraxListItem.js +121 -0
  11. package/build/DraxProvider.d.ts +1 -3
  12. package/build/DraxProvider.js +322 -259
  13. package/build/DraxScrollView.d.ts +1 -1
  14. package/build/DraxScrollView.js +29 -90
  15. package/build/DraxSubprovider.d.ts +2 -2
  16. package/build/DraxSubprovider.js +1 -1
  17. package/build/DraxView.d.ts +7 -2
  18. package/build/DraxView.js +60 -383
  19. package/build/HoverView.d.ts +8 -0
  20. package/build/HoverView.js +40 -0
  21. package/build/PanGestureDetector.d.ts +3 -0
  22. package/build/PanGestureDetector.js +49 -0
  23. package/build/hooks/useContent.d.ts +23 -0
  24. package/build/hooks/useContent.js +212 -0
  25. package/build/hooks/useDraxProtocol.d.ts +5 -0
  26. package/build/hooks/useDraxProtocol.js +32 -0
  27. package/build/hooks/useDraxRegistry.d.ts +21 -20
  28. package/build/hooks/useDraxRegistry.js +195 -182
  29. package/build/hooks/useDraxScrollHandler.d.ts +25 -0
  30. package/build/hooks/useDraxScrollHandler.js +89 -0
  31. package/build/hooks/useDraxState.d.ts +1 -1
  32. package/build/hooks/useDraxState.js +9 -6
  33. package/build/hooks/useMeasurements.d.ts +9 -0
  34. package/build/hooks/useMeasurements.js +119 -0
  35. package/build/hooks/useStatus.d.ts +11 -0
  36. package/build/hooks/useStatus.js +96 -0
  37. package/build/index.d.ts +2 -0
  38. package/build/index.js +4 -1
  39. package/build/math.d.ts +2 -2
  40. package/build/math.js +10 -6
  41. package/build/params.d.ts +9 -0
  42. package/build/params.js +7 -1
  43. package/build/transform.d.ts +11 -4
  44. package/build/transform.js +50 -8
  45. package/build/types.d.ts +238 -87
  46. package/build/types.js +10 -7
  47. package/package.json +43 -45
package/build/types.d.ts CHANGED
@@ -1,13 +1,15 @@
1
- import { RefObject, ReactNode } from 'react';
2
- import { ViewProps, Animated, FlatListProps, ViewStyle, StyleProp, ScrollViewProps, ListRenderItemInfo } from 'react-native';
3
- import { LongPressGestureHandlerStateChangeEvent, LongPressGestureHandlerGestureEvent } from 'react-native-gesture-handler';
4
- import { PayloadActionCreator, ActionType } from 'typesafe-actions';
1
+ import { ElementRef, MutableRefObject, PropsWithChildren, ReactNode, RefObject } from 'react';
2
+ import { FlatListProps, ListRenderItem, ListRenderItemInfo, ScrollView, ScrollViewComponent, ScrollViewProps, StyleProp, View, ViewProps, ViewStyle } from 'react-native';
3
+ import { GestureStateChangeEvent, GestureUpdateEvent, LongPressGesture, LongPressGestureHandlerStateChangeEvent, PanGestureHandlerEventPayload } from 'react-native-gesture-handler';
4
+ import { AnimatedStyle, FlatListPropsWithLayout, SharedValue, StyleProps } from 'react-native-reanimated';
5
+ import { ActionType, PayloadActionCreator } from 'typesafe-actions';
5
6
  /** Gesture state change event expected by Drax handler */
6
- export declare type DraxGestureStateChangeEvent = LongPressGestureHandlerStateChangeEvent['nativeEvent'];
7
+ export type DraxGestureStateChangeEvent = LongPressGestureHandlerStateChangeEvent['nativeEvent'];
7
8
  /** Gesture event expected by Drax handler */
8
- export declare type DraxGestureEvent = LongPressGestureHandlerGestureEvent['nativeEvent'];
9
+ export type DraxGestureEvent = LongPressGesture;
9
10
  /** An xy-coordinate position value */
10
11
  export interface Position {
12
+ [k: string]: number;
11
13
  /** Position on horizontal x-axis, positive is right */
12
14
  x: number;
13
15
  /** Position on vertical y-axis, positive is down */
@@ -26,7 +28,7 @@ export interface ViewDimensions {
26
28
  export interface DraxViewMeasurements extends Position, ViewDimensions {
27
29
  }
28
30
  /** Data about a view involved in a Drax event */
29
- export interface DraxEventViewData {
31
+ export interface DraxEventViewData extends DraxPayloadViewData {
30
32
  /** The view's id */
31
33
  id: string;
32
34
  /** The view's parent id, if any */
@@ -45,7 +47,7 @@ export interface DraxEventDraggedViewData extends DraxEventViewData {
45
47
  /** The relative offset/dimensions ratio of where the view was grabbed */
46
48
  grabOffsetRatio: Position;
47
49
  /** The position in absolute coordinates of the dragged hover view (dragAbsolutePosition - grabOffset) */
48
- hoverPosition: Animated.ValueXY;
50
+ hoverPosition: Position;
49
51
  }
50
52
  /** Data about a receiver view involved in a Drax event */
51
53
  export interface DraxEventReceiverViewData extends DraxEventViewData {
@@ -81,12 +83,18 @@ export interface DraxDragWithReceiverEventData extends DraxDragEventData {
81
83
  /** Data about a Drax drag/receive end event */
82
84
  export interface DraxDragWithReceiverEndEventData extends DraxDragWithReceiverEventData, WithCancelledFlag {
83
85
  }
84
- /** Data about a Drax snapback, used for custom animations */
85
- export interface DraxSnapbackData {
86
- hoverPosition: Animated.ValueXY;
86
+ /** Data about a Drax snap, used for custom animations */
87
+ export interface DraxSnapData {
88
+ hoverPosition: SharedValue<Position>;
87
89
  toValue: Position;
88
90
  delay: number;
89
91
  duration: number;
92
+ /** Scroll position
93
+ * Will be receiver's parent scroll on succesful drops,
94
+ * else will be dragged parent scroll */
95
+ scrollPosition?: SharedValue<Position>;
96
+ /** Needed to pass to the custom animator for Drax to work properly. */
97
+ finishedCallback: (finished: boolean) => void;
90
98
  }
91
99
  /** Data about a Drax monitor event */
92
100
  export interface DraxMonitorEventData extends DraxDragEventData {
@@ -103,37 +111,44 @@ export interface DraxMonitorEndEventData extends DraxMonitorEventData, WithCance
103
111
  /** Data about a Drax monitor drag-drop event */
104
112
  export interface DraxMonitorDragDropEventData extends Required<DraxMonitorEventData> {
105
113
  }
106
- /** Preset values for specifying snapback targets without a Position */
114
+ /** Preset values for specifying snap targets without a Position */
107
115
  export declare enum DraxSnapbackTargetPreset {
108
116
  Default = 0,
109
117
  None = 1
110
118
  }
111
- /** Target for snapback hover view release animation: none, default, or specified Position */
112
- export declare type DraxSnapbackTarget = DraxSnapbackTargetPreset | Position;
119
+ /** Target for snap hover view release animation: none, default, or specified Position */
120
+ export type DraxSnapbackTarget = DraxSnapbackTargetPreset | Position;
113
121
  /**
114
122
  * Response type for Drax protocol callbacks involving end of a drag,
115
- * allowing override of default release snapback behavior.
123
+ * allowing override of default release snap behavior.
116
124
  */
117
- export declare type DraxProtocolDragEndResponse = void | DraxSnapbackTarget;
125
+ export type DraxProtocolDragEndResponse = void | DraxSnapbackTarget;
118
126
  /** Props provided to an internal render function for a hovering copy of a Drax view */
119
127
  export interface DraxInternalRenderHoverViewProps {
120
128
  /** Key of the hover view React node */
121
129
  key: string;
122
- /** Hover position of the view */
123
- hoverPosition: Animated.ValueXY;
130
+ /** Hover position of the view - Reanimated shared value */
131
+ hoverPosition: SharedValue<Position>;
124
132
  /** State for the view */
125
133
  viewState: DraxViewState;
126
134
  /** Drax tracking status */
127
135
  trackingStatus: DraxTrackingStatus;
128
136
  /** Dimensions for the view */
129
137
  dimensions: ViewDimensions;
130
- }
138
+ /** Scroll Position - Reanimated shared value
139
+ * Will be receiver's parent scroll on succesful drops,
140
+ * else will be dragged parent scroll */
141
+ scrollPosition?: SharedValue<Position>;
142
+ }
143
+ export type TReanimatedHoverViewProps = {
144
+ internalProps: DraxInternalRenderHoverViewProps;
145
+ } & Partial<DraxViewProps>;
131
146
  /** Props provided to a render function for a Drax view */
132
147
  export interface DraxRenderContentProps {
133
148
  /** State for the view, if available */
134
149
  viewState?: DraxViewState;
135
150
  /** Drax tracking status */
136
- trackingStatus: DraxTrackingStatus;
151
+ trackingStatus?: DraxTrackingStatus;
137
152
  /** Is this a hovering copy of the view? */
138
153
  hover: boolean;
139
154
  /** React children of the DraxView */
@@ -142,10 +157,24 @@ export interface DraxRenderContentProps {
142
157
  dimensions?: ViewDimensions;
143
158
  }
144
159
  /** Props provided to a render function for a hovering copy of a Drax view, compatible with DraxRenderContentProps */
145
- export interface DraxRenderHoverContentProps extends Required<DraxRenderContentProps> {
160
+ export interface DraxRenderHoverContentProps extends DraxRenderContentProps {
146
161
  }
162
+ type DraxPayloadViewData = {
163
+ data: DraxAbsoluteViewData;
164
+ };
165
+ type DraxSnapPayload = {
166
+ dragged: DraxPayloadViewData & Omit<DraxTrackingDrag, 'receiver'>;
167
+ receiver?: DraxPayloadViewData & DraxTrackingReceiver;
168
+ };
147
169
  /** Callback protocol for communicating Drax events to views */
148
170
  export interface DraxProtocol {
171
+ hoverPosition: SharedValue<Position>;
172
+ scrollPositionValue?: Position;
173
+ /** A function that can be used to conditionally enable or disable receiving. `receptive` prop will override it. */
174
+ dynamicReceptiveCallback?: (data: {
175
+ foundView: DraxFoundAbsoluteViewEntry;
176
+ excludedView: DraxAbsoluteViewData;
177
+ }) => boolean;
149
178
  /** Called in the dragged view when a drag action begins */
150
179
  onDragStart?: (data: DraxDragEventData) => void;
151
180
  /** Called in the dragged view repeatedly while dragged, not over any receiver */
@@ -160,8 +189,10 @@ export interface DraxProtocol {
160
189
  onDragEnd?: (data: DraxDragEndEventData) => DraxProtocolDragEndResponse;
161
190
  /** Called in the dragged view when drag ends over a receiver */
162
191
  onDragDrop?: (data: DraxDragWithReceiverEventData) => DraxProtocolDragEndResponse;
163
- /** Called in the dragged view when drag release snapback ends */
164
- onSnapbackEnd?: () => void;
192
+ /** Called in the dragged view when drag release snap ends */
193
+ onSnapEnd?: (snapPayload: DraxSnapPayload) => void;
194
+ /** Called in the receiver view when drag release snap ends */
195
+ onReceiveSnapEnd?: (snapPayload: DraxSnapPayload) => void;
165
196
  /** Called in the receiver view each time an item is initially dragged over it */
166
197
  onReceiveDragEnter?: (data: DraxDragWithReceiverEventData) => void;
167
198
  /** Called in the receiver view repeatedly while an item is dragged over it */
@@ -182,35 +213,38 @@ export interface DraxProtocol {
182
213
  onMonitorDragEnd?: (data: DraxMonitorEndEventData) => DraxProtocolDragEndResponse;
183
214
  /** Called in the monitor view when drag ends over it while over a receiver */
184
215
  onMonitorDragDrop?: (data: DraxMonitorDragDropEventData) => DraxProtocolDragEndResponse;
185
- /** Whether or not to animate hover view snapback after drag release, defaults to true */
186
- animateSnapback?: boolean;
187
- /** Delay in ms before hover view snapback begins after drag is released */
188
- snapbackDelay?: number;
189
- /** Duration in ms for hover view snapback to complete */
190
- snapbackDuration?: number;
191
- /** Function returning custom hover view snapback animation */
192
- snapbackAnimator?: (data: DraxSnapbackData) => Animated.CompositeAnimation;
216
+ /** Whether or not to animate hover view snap after drag release, defaults to true */
217
+ animateSnap?: boolean;
218
+ /** Delay in ms before hover view snap begins after drag is released */
219
+ snapDelay?: number;
220
+ /** Duration in ms for hover view snap to complete */
221
+ snapDuration?: number;
222
+ /** Function returning custom hover view snap animation */
223
+ snapAnimator?: (data: DraxSnapData) => void;
193
224
  /** Payload that will be delivered to receiver views when this view is dragged; overrides `payload` */
194
225
  dragPayload?: any;
195
226
  /** Payload that will be delievered to dragged views when this view receives them; overrides `payload` */
196
227
  receiverPayload?: any;
228
+ /** Convenience prop to provide one value for both `dragPayload` and `receiverPayload` */
229
+ payload?: any;
197
230
  /** Whether the view can be dragged */
198
- draggable: boolean;
231
+ draggable?: boolean;
199
232
  /** Whether the view can receive drags */
200
- receptive: boolean;
233
+ receptive?: boolean;
201
234
  /** Whether the view can monitor drags */
202
- monitoring: boolean;
235
+ monitoring?: boolean;
203
236
  /** If true, lock drag's x-position */
204
237
  lockDragXPosition?: boolean;
205
238
  /** If true, lock drag's y position */
206
239
  lockDragYPosition?: boolean;
207
- /** Function used internally for rendering hovering copy of view when dragged/released */
208
- internalRenderHoverView?: (props: DraxInternalRenderHoverViewProps) => ReactNode;
240
+ /**
241
+ * Disable automatic HoverView measurements which occur on the `onLayout` event.
242
+ * Could be useful in case the area size that activates the drag might differ from the actual HoverView
243
+ * content size. */
244
+ disableHoverViewMeasurementsOnLayout?: boolean;
209
245
  }
210
246
  /** Props for components implementing the protocol */
211
247
  export interface DraxProtocolProps extends Partial<Omit<DraxProtocol, 'internalRenderHoverView'>> {
212
- /** Convenience prop to provide one value for both `dragPayload` and `receiverPayload` */
213
- payload?: any;
214
248
  }
215
249
  /** The states a dragged view can be in */
216
250
  export declare enum DraxViewDragStatus {
@@ -233,11 +267,13 @@ export interface DraxViewData {
233
267
  /** The view's Drax parent view id, if nested */
234
268
  parentId?: string;
235
269
  /** The view's scroll position ref, if it is a scrollable parent view */
236
- scrollPositionRef?: RefObject<Position>;
270
+ scrollPosition?: SharedValue<Position>;
237
271
  /** The view's protocol callbacks and data */
238
272
  protocol: DraxProtocol;
239
273
  /** The view's measurements for bounds checking */
240
274
  measurements?: DraxViewMeasurements;
275
+ /** The hover view's measurements for bounds checking */
276
+ hoverMeasurements?: DraxViewMeasurements;
241
277
  }
242
278
  /** Information about a view, plus its clipped absolute measurements */
243
279
  export interface DraxAbsoluteViewData extends Omit<DraxViewData, 'measurements'>, Required<Pick<DraxViewData, 'measurements'>> {
@@ -287,7 +323,7 @@ export interface DraxTrackingDrag {
287
323
  /** The relative offset/dimensions ratio within the dragged view of where it was grabbed */
288
324
  grabOffsetRatio: Position;
289
325
  /** The position in absolute coordinates of the dragged hover view (dragAbsolutePosition - grabOffset) */
290
- hoverPosition: Animated.ValueXY;
326
+ hoverPosition: SharedValue<Position>;
291
327
  /** Tracking information about the current drag receiver, if any */
292
328
  receiver?: DraxTrackingReceiver;
293
329
  /** View ids of monitors that the drag is currently over */
@@ -298,7 +334,13 @@ export interface DraxTrackingRelease {
298
334
  /** View id of the released view */
299
335
  viewId: string;
300
336
  /** The position in absolute coordinates of the released hover view */
301
- hoverPosition: Animated.ValueXY;
337
+ hoverPosition: SharedValue<Position>;
338
+ /** Scroll position - Reanimated shared value
339
+ * Will be receiver's parent scroll on succesful drops,
340
+ * else will be dragged parent scroll */
341
+ scrollPosition: SharedValue<Position>;
342
+ /** Offset of the snap's target scroll position in the moment of the release. */
343
+ scrollPositionOffset: Position;
302
344
  }
303
345
  /** Tracking status for reference in views */
304
346
  export interface DraxTrackingStatus {
@@ -308,7 +350,8 @@ export interface DraxTrackingStatus {
308
350
  receiving: boolean;
309
351
  }
310
352
  /** Render-related state for a registered view */
311
- export interface DraxViewState {
353
+ export interface DraxViewState extends Partial<DraxPayloadViewData> {
354
+ id?: string;
312
355
  /** Current drag status of the view: Dragged, Released, or Inactive */
313
356
  dragStatus: DraxViewDragStatus;
314
357
  /** If being dragged, the position in absolute coordinates of the drag point */
@@ -324,7 +367,6 @@ export interface DraxViewState {
324
367
  /** If being dragged, the relative offset/dimensions ratio of where the view was grabbed */
325
368
  grabOffsetRatio?: Position;
326
369
  /** The position in absolute coordinates of the dragged hover view (dragAbsolutePosition - grabOffset) */
327
- hoverPosition?: Animated.ValueXY;
328
370
  /** Data about the receiver this view is being dragged over, if any */
329
371
  draggingOverReceiver?: DraxEventViewData;
330
372
  /** Current receive status of the view: Receiving or Inactive */
@@ -335,6 +377,8 @@ export interface DraxViewState {
335
377
  receiveOffsetRatio?: Position;
336
378
  /** Data about the dragged item this view is receiving, if any */
337
379
  receivingDrag?: DraxEventViewData;
380
+ /** Data about the released dragged item */
381
+ releasedDragTracking?: DraxTrackingDrag;
338
382
  }
339
383
  /** Drax provider render state; maintains render-related data */
340
384
  export interface DraxState {
@@ -366,7 +410,7 @@ export interface RegisterViewPayload {
366
410
  /** The view's Drax parent view id, if nested */
367
411
  parentId?: string;
368
412
  /** The view's scroll position ref, if it is a scrollable parent view */
369
- scrollPositionRef?: RefObject<Position>;
413
+ scrollPosition?: SharedValue<Position>;
370
414
  }
371
415
  /** Payload for unregistering a Drax view */
372
416
  export interface UnregisterViewPayload {
@@ -415,9 +459,9 @@ export interface DraxStateActionCreators {
415
459
  updateTrackingStatus: PayloadActionCreator<'updateTrackingStatus', UpdateTrackingStatusPayload>;
416
460
  }
417
461
  /** Dispatchable Drax state action */
418
- export declare type DraxStateAction = ActionType<DraxStateActionCreators>;
462
+ export type DraxStateAction = ActionType<DraxStateActionCreators>;
419
463
  /** Dispatcher of Drax state actions */
420
- export declare type DraxStateDispatch = (action: DraxStateAction) => void;
464
+ export type DraxStateDispatch = (action: DraxStateAction) => void;
421
465
  /** Drax provider internal registry; maintains view data and tracks drags, updating state */
422
466
  export interface DraxRegistry {
423
467
  /** A list of the unique identifiers of the registered views, in order of registration */
@@ -438,9 +482,56 @@ export interface DraxRegistry {
438
482
  /** Drax state dispatch function */
439
483
  stateDispatch: DraxStateDispatch;
440
484
  }
485
+ export type TDragPositionData = {
486
+ dragAbsolutePosition: {
487
+ x: number;
488
+ y: number;
489
+ };
490
+ dragTranslation: {
491
+ x: number;
492
+ y: number;
493
+ };
494
+ dragTranslationRatio: {
495
+ x: number;
496
+ y: number;
497
+ };
498
+ } | undefined;
499
+ export interface GetDragPositionDataParams {
500
+ parentPosition: Position;
501
+ draggedMeasurements: DraxViewMeasurements;
502
+ lockXPosition?: boolean;
503
+ lockYPosition?: boolean;
504
+ }
505
+ export type TPanGestureDetectorProps = PropsWithChildren<{
506
+ id: string;
507
+ longPressDelay: number;
508
+ draggable: boolean;
509
+ }>;
441
510
  /** Context value used internally by Drax provider */
442
511
  export interface DraxContextValue {
443
- /** Get a Drax view state by view id, if it exists */
512
+ getReleaseViews: () => string[];
513
+ startPosition: SharedValue<TStartPosition>;
514
+ parentPosition: SharedValue<Position>;
515
+ findMonitorsAndReceiver: (absolutePosition: Position, excludeViewId: string) => {
516
+ monitors: DraxFoundAbsoluteViewEntry[];
517
+ receiver: DraxFoundAbsoluteViewEntry | undefined;
518
+ };
519
+ getTrackingDragged: () => {
520
+ tracking: DraxTrackingDrag;
521
+ id: string;
522
+ data: DraxAbsoluteViewData;
523
+ } | undefined;
524
+ getTrackingReceiver: () => {
525
+ tracking: DraxTrackingReceiver;
526
+ id: string;
527
+ data: DraxAbsoluteViewData;
528
+ } | undefined;
529
+ resetReceiver: () => void;
530
+ getAbsoluteViewData: (id: string | undefined) => DraxAbsoluteViewData | undefined;
531
+ getTrackingMonitorIds: () => string[];
532
+ setMonitorIds: (monitorIds: string[]) => void;
533
+ updateReceiver: (receiver: DraxFoundAbsoluteViewEntry, dragged: DraxAbsoluteViewEntry) => DraxTrackingReceiver | undefined;
534
+ dragPositionDataSV: SharedValue<TDragPositionData> /** Get a Drax view state by view id, if it exists */;
444
535
  getViewState: (id: string) => DraxViewState | undefined;
445
536
  /** Get current Drax tracking status */
446
537
  getTrackingStatus: () => DraxTrackingStatus;
@@ -452,12 +543,14 @@ export interface DraxContextValue {
452
543
  updateViewProtocol: (payload: UpdateViewProtocolPayload) => void;
453
544
  /** Update view measurements for a registered Drax view */
454
545
  updateViewMeasurements: (payload: UpdateViewMeasurementsPayload) => void;
546
+ /** Update hover view measurements for a registered Drax view */
547
+ updateHoverViewMeasurements: (payload: UpdateViewMeasurementsPayload) => void;
455
548
  /** Handle gesture state change for a registered Drax view */
456
- handleGestureStateChange: (id: string, event: DraxGestureStateChangeEvent) => void;
549
+ handleGestureStateChange: (id: string) => (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => void;
457
550
  /** Handle gesture event for a registered Drax view */
458
- handleGestureEvent: (id: string, event: DraxGestureEvent) => void;
459
- /** Root node handle ref for the Drax provider, for measuring non-parented views in relation to */
460
- rootNodeHandleRef: RefObject<number | null>;
551
+ handleGestureEvent: (id: string, event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => void;
552
+ /** Root View ref for the Drax provider, for measuring non-parented views in relation to */
553
+ rootViewRef: RefObject<View | null>;
461
554
  /** Drax parent view for all views under this context, when nesting */
462
555
  parent?: DraxParentView;
463
556
  }
@@ -481,33 +574,34 @@ export interface DraxViewRegistration {
481
574
  export interface DraxParentView {
482
575
  /** Drax view id of the parent */
483
576
  id: string;
484
- /** Ref to node handle of the parent, for measuring relative to */
485
- nodeHandleRef: RefObject<number | null>;
577
+ /** View Ref of the parent, for measuring relative to */
578
+ viewRef: RefObject<ElementRef<typeof ScrollViewComponent> | ScrollView | View | null | undefined>;
486
579
  }
487
580
  /** Function that receives a Drax view measurement */
488
581
  export interface DraxViewMeasurementHandler {
489
582
  (measurements: DraxViewMeasurements | undefined): void;
490
583
  }
491
584
  /** Layout-related style keys that are omitted from hover view styles */
492
- export declare type LayoutStyleKey = ('margin' | 'marginHorizontal' | 'marginVertical' | 'marginLeft' | 'marginRight' | 'marginTop' | 'marginBottom' | 'marginStart' | 'marginEnd' | 'left' | 'right' | 'top' | 'bottom' | 'flex' | 'flexBasis' | 'flexDirection' | 'flexGrow' | 'flexShrink');
585
+ export type LayoutStyleKey = 'margin' | 'marginHorizontal' | 'marginVertical' | 'marginLeft' | 'marginRight' | 'marginTop' | 'marginBottom' | 'marginStart' | 'marginEnd' | 'left' | 'right' | 'top' | 'bottom' | 'flex' | 'flexBasis' | 'flexDirection' | 'flexGrow' | 'flexShrink';
586
+ export type TSDraxtyles = ViewStyle | StyleProp<StyleProps> | null | StyleProp<ViewStyle> | StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
493
587
  /** Style for a Animated.View used for a hover view */
494
- export declare type AnimatedViewStyleWithoutLayout = Omit<Animated.WithAnimatedValue<ViewStyle>, LayoutStyleKey>;
588
+ export type AnimatedViewStyleWithoutLayout = Omit<TSDraxtyles, LayoutStyleKey>;
495
589
  /** Style prop for a Animated.View used for a hover view */
496
- export declare type AnimatedViewStylePropWithoutLayout = StyleProp<AnimatedViewStyleWithoutLayout>;
590
+ export type AnimatedViewStylePropWithoutLayout = TSDraxtyles;
497
591
  /** Style-related props for a Drax view */
498
592
  export interface DraxViewStyleProps {
499
593
  /** Custom style prop to allow animated values */
500
- style?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
594
+ style?: TSDraxtyles;
501
595
  /** Additional view style applied while this view is not being dragged or released */
502
- dragInactiveStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
596
+ dragInactiveStyle?: TSDraxtyles;
503
597
  /** Additional view style applied while this view is being dragged */
504
- draggingStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
598
+ draggingStyle?: TSDraxtyles;
505
599
  /** Additional view style applied while this view is being dragged over a receiver */
506
- draggingWithReceiverStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
600
+ draggingWithReceiverStyle?: TSDraxtyles;
507
601
  /** Additional view style applied while this view is being dragged NOT over a receiver */
508
- draggingWithoutReceiverStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
602
+ draggingWithoutReceiverStyle?: TSDraxtyles;
509
603
  /** Additional view style applied while this view has just been released from a drag */
510
- dragReleasedStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
604
+ dragReleasedStyle?: TSDraxtyles;
511
605
  /** Additional view style applied to the hovering copy of this view during drag/release */
512
606
  hoverStyle?: AnimatedViewStylePropWithoutLayout;
513
607
  /** Additional view style applied to the hovering copy of this view while dragging */
@@ -519,15 +613,15 @@ export interface DraxViewStyleProps {
519
613
  /** Additional view style applied to the hovering copy of this view when just released */
520
614
  hoverDragReleasedStyle?: AnimatedViewStylePropWithoutLayout;
521
615
  /** Additional view style applied while this view is not receiving a drag */
522
- receiverInactiveStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
616
+ receiverInactiveStyle?: TSDraxtyles;
523
617
  /** Additional view style applied while this view is receiving a drag */
524
- receivingStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
618
+ receivingStyle?: TSDraxtyles;
525
619
  /** Additional view style applied to this view while any other view is being dragged */
526
- otherDraggingStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
620
+ otherDraggingStyle?: TSDraxtyles;
527
621
  /** Additional view style applied to this view while any other view is being dragged over a receiver */
528
- otherDraggingWithReceiverStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
622
+ otherDraggingWithReceiverStyle?: TSDraxtyles;
529
623
  /** Additional view style applied to this view while any other view is being dragged NOT over a receiver */
530
- otherDraggingWithoutReceiverStyle?: StyleProp<Animated.WithAnimatedValue<ViewStyle>>;
624
+ otherDraggingWithoutReceiverStyle?: TSDraxtyles;
531
625
  }
532
626
  /** Custom render function for content of a DraxView */
533
627
  export interface DraxViewRenderContent {
@@ -537,6 +631,10 @@ export interface DraxViewRenderContent {
537
631
  export interface DraxViewRenderHoverContent {
538
632
  (props: DraxRenderHoverContentProps): ReactNode;
539
633
  }
634
+ export type TStartPosition = {
635
+ parent: Position;
636
+ grab: Position;
637
+ };
540
638
  /** Props for a DraxView; combines protocol props and standard view props */
541
639
  export interface DraxViewProps extends Omit<ViewProps, 'style'>, DraxProtocolProps, DraxViewStyleProps {
542
640
  /** Custom render function for content of this view */
@@ -555,8 +653,8 @@ export interface DraxViewProps extends Omit<ViewProps, 'style'>, DraxProtocolPro
555
653
  parent?: DraxParentView;
556
654
  /** If true, treat this view as a Drax parent view for nested children */
557
655
  isParent?: boolean;
558
- /** The view's scroll position ref, if it is a scrollable parent view */
559
- scrollPositionRef?: RefObject<Position>;
656
+ /** Used internally - The view's scroll position, if it is a scrollable parent view */
657
+ scrollPosition?: SharedValue<Position>;
560
658
  /** Time in milliseconds view needs to be pressed before drag starts */
561
659
  longPressDelay?: number;
562
660
  }
@@ -588,8 +686,12 @@ export interface DraxScrollViewProps extends ScrollViewProps, DraxAutoScrollProp
588
686
  }
589
687
  /** DraxList item being dragged */
590
688
  export interface DraxListDraggedItemData<TItem> {
689
+ /** The list index of the item that is being dragged */
591
690
  index: number;
691
+ /** The item that is being dragged (or undefined if data is not found) */
592
692
  item?: TItem;
693
+ /** Boolean representing an incoming external item dragged into the DraxList */
694
+ isExternalDrag: boolean;
593
695
  }
594
696
  /** Event data for when a list item reorder drag action begins */
595
697
  export interface DraxListOnItemDragStartEventData<TItem> extends DraxDragEventData, DraxListDraggedItemData<TItem> {
@@ -606,10 +708,16 @@ export interface DraxListOnItemDragEndEventData<TItem> extends DraxMonitorEventD
606
708
  }
607
709
  /** Event data for when an item is released in a new position within a DraxList, reordering the list */
608
710
  export interface DraxListOnItemReorderEventData<TItem> {
609
- fromItem: TItem;
711
+ /** The item that was moved */
712
+ fromItem?: TItem;
713
+ /** The list index of the item that was moved */
610
714
  fromIndex: number;
611
- toItem: TItem;
715
+ /** The item it was moved onto */
716
+ toItem?: TItem;
717
+ /** The list index of the item it was moved onto */
612
718
  toIndex: number;
719
+ /** Boolean representing an incoming external item dragged into the DraxList */
720
+ isExternalDrag: boolean;
613
721
  }
614
722
  /** Render function for content of a DraxList item's DraxView */
615
723
  export interface DraxListRenderItemContent<TItem> {
@@ -624,17 +732,20 @@ export interface DraxListOnItemReorder<TItem> {
624
732
  (eventData: DraxListOnItemReorderEventData<TItem>): void;
625
733
  }
626
734
  /** Props for a DraxList; extends standard FlatList props */
627
- export interface DraxListProps<TItem> extends Omit<FlatListProps<TItem>, 'renderItem'>, DraxAutoScrollProps {
628
- /** Unique drax view id, auto-generated if omitted */
629
- id?: string;
630
- /** Style prop for the underlying FlatList */
631
- flatListStyle?: StyleProp<ViewStyle>;
632
- /** Style props to apply to all DraxView items in the list */
633
- itemStyles?: DraxViewStyleProps;
634
- /** Render function for content of an item's DraxView */
635
- renderItemContent: DraxListRenderItemContent<TItem>;
636
- /** Render function for content of an item's hovering copy, defaults to renderItemContent */
637
- renderItemHoverContent?: DraxListRenderItemHoverContent<TItem>;
735
+ export interface DraxListProps<TItem> extends Omit<RemoveSharedValues<FlatListPropsWithLayout<TItem>>, 'renderItem'>, DraxAutoScrollProps {
736
+ /**
737
+ * @deprecated
738
+ *
739
+ * @description Unique drax view id, auto-generated if omitted
740
+ *
741
+ * Please use `parentDraxViewProps.id` instead
742
+ */
743
+ id?: never;
744
+ /**
745
+ * @experimental
746
+ * Style props to apply to the parent DraxView when monitoring an External item drag
747
+ * Might be very expensive in terms of performance */
748
+ monitoringExternalDragStyle?: TSDraxtyles;
638
749
  /** Callback handler for when a list item reorder drag action begins */
639
750
  onItemDragStart?: (eventData: DraxListOnItemDragStartEventData<TItem>) => void;
640
751
  /** Callback handler for when a list item position (index) changes during a reorder drag */
@@ -645,12 +756,52 @@ export interface DraxListProps<TItem> extends Omit<FlatListProps<TItem>, 'render
645
756
  onItemReorder?: DraxListOnItemReorder<TItem>;
646
757
  /** Can the list be reordered by dragging items? Defaults to true if onItemReorder is set. */
647
758
  reorderable?: boolean;
648
- /** Can the items be dragged? Defaults to true. */
649
- itemsDraggable?: boolean;
650
759
  /** If true, lock item drags to the list's main axis */
651
760
  lockItemDragsToMainAxis?: boolean;
652
761
  /** Time in milliseconds view needs to be pressed before drag starts */
653
762
  longPressDelay?: number;
654
- /** Function that receives an item and returns a list of DraxViewProps to apply to that item's DraxView */
655
- viewPropsExtractor?: (item: TItem) => Partial<DraxViewProps>;
656
- }
763
+ renderItem: (info: ListRenderItemInfo<TItem>, itemProps: DraxListItemProps<TItem>) => ReturnType<ListRenderItem<TItem>>;
764
+ /**
765
+ * @inheritDoc `originalIndex` and `index` cannot be used in the DraxList data payload, since
766
+ * it can break it when using external drags
767
+ */
768
+ data: FlatListProps<WithoutIndexAndOriginalIndex<TItem>>['data'];
769
+ /**
770
+ * @experimental
771
+ * Props to apply to the parent DraxView that's wrapping the FlatList
772
+ */
773
+ parentDraxViewProps?: DraxViewProps;
774
+ /**
775
+ * When true, items will shift based on their centers instead of edges.
776
+ * This is always true for grid layouts (numColumns > 1).
777
+ * @default false
778
+ */
779
+ centerShift?: boolean;
780
+ }
781
+ export interface DraxListItemProps<T extends unknown> {
782
+ index: number;
783
+ item: T;
784
+ originalIndex: number;
785
+ horizontal: boolean;
786
+ lockItemDragsToMainAxis: boolean;
787
+ draggedItem: SharedValue<number | undefined>;
788
+ shiftsRef: SharedValue<Position[]>;
789
+ itemMeasurementsRef: MutableRefObject<((DraxViewMeasurements & {
790
+ key?: string;
791
+ }) | undefined)[]>;
792
+ prevItemMeasurementsRef: MutableRefObject<((DraxViewMeasurements & {
793
+ key?: string;
794
+ }) | undefined)[]>;
795
+ resetDraggedItem: () => void;
796
+ keyExtractor?: (item: T, index: number) => string;
797
+ previousShiftsRef: SharedValue<Position[]>;
798
+ registrationsRef: MutableRefObject<(DraxViewRegistration | undefined)[]>;
799
+ data: DraxListProps<T>['data'];
800
+ }
801
+ type UnwrapSharedValue<T> = T extends SharedValue<infer U> ? U : T;
802
+ type RemoveSharedValues<T> = {
803
+ [K in keyof T]: UnwrapSharedValue<T[K]>;
804
+ };
805
+ type IsAny<T> = 0 extends 1 & T ? true : false;
806
+ type WithoutIndexAndOriginalIndex<T> = IsAny<T> extends true ? T : T extends object ? 'index' extends keyof T ? never : 'originalIndex' extends keyof T ? never : T : T;
807
+ export {};
package/build/types.js CHANGED
@@ -2,17 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AutoScrollDirection = exports.DraxViewReceiveStatus = exports.DraxViewDragStatus = exports.DraxSnapbackTargetPreset = exports.isWithCancelledFlag = exports.isPosition = void 0;
4
4
  /** Predicate for checking if something is a Position */
5
- const isPosition = (something) => (typeof something === 'object' && something !== null && typeof something.x === 'number' && typeof something.y === 'number');
5
+ const isPosition = (something) => typeof something === 'object' &&
6
+ something !== null &&
7
+ typeof something.x === 'number' &&
8
+ typeof something.y === 'number';
6
9
  exports.isPosition = isPosition;
7
10
  /** Predicate for checking if something has a cancelled flag */
8
- const isWithCancelledFlag = (something) => (typeof something === 'object' && something !== null && typeof something.cancelled === 'boolean');
11
+ const isWithCancelledFlag = (something) => typeof something === 'object' && something !== null && typeof something.cancelled === 'boolean';
9
12
  exports.isWithCancelledFlag = isWithCancelledFlag;
10
- /** Preset values for specifying snapback targets without a Position */
13
+ /** Preset values for specifying snap targets without a Position */
11
14
  var DraxSnapbackTargetPreset;
12
15
  (function (DraxSnapbackTargetPreset) {
13
16
  DraxSnapbackTargetPreset[DraxSnapbackTargetPreset["Default"] = 0] = "Default";
14
17
  DraxSnapbackTargetPreset[DraxSnapbackTargetPreset["None"] = 1] = "None";
15
- })(DraxSnapbackTargetPreset = exports.DraxSnapbackTargetPreset || (exports.DraxSnapbackTargetPreset = {}));
18
+ })(DraxSnapbackTargetPreset || (exports.DraxSnapbackTargetPreset = DraxSnapbackTargetPreset = {}));
16
19
  /** The states a dragged view can be in */
17
20
  var DraxViewDragStatus;
18
21
  (function (DraxViewDragStatus) {
@@ -22,7 +25,7 @@ var DraxViewDragStatus;
22
25
  DraxViewDragStatus[DraxViewDragStatus["Dragging"] = 1] = "Dragging";
23
26
  /** View has been released but has not yet snapped back to inactive */
24
27
  DraxViewDragStatus[DraxViewDragStatus["Released"] = 2] = "Released";
25
- })(DraxViewDragStatus = exports.DraxViewDragStatus || (exports.DraxViewDragStatus = {}));
28
+ })(DraxViewDragStatus || (exports.DraxViewDragStatus = DraxViewDragStatus = {}));
26
29
  /** The states a receiver view can be in */
27
30
  var DraxViewReceiveStatus;
28
31
  (function (DraxViewReceiveStatus) {
@@ -30,7 +33,7 @@ var DraxViewReceiveStatus;
30
33
  DraxViewReceiveStatus[DraxViewReceiveStatus["Inactive"] = 0] = "Inactive";
31
34
  /** View is receiving a drag; an active drag touch point is currently over this view */
32
35
  DraxViewReceiveStatus[DraxViewReceiveStatus["Receiving"] = 1] = "Receiving";
33
- })(DraxViewReceiveStatus = exports.DraxViewReceiveStatus || (exports.DraxViewReceiveStatus = {}));
36
+ })(DraxViewReceiveStatus || (exports.DraxViewReceiveStatus = DraxViewReceiveStatus = {}));
34
37
  /** Auto-scroll direction used internally by DraxScrollView and DraxList */
35
38
  var AutoScrollDirection;
36
39
  (function (AutoScrollDirection) {
@@ -40,4 +43,4 @@ var AutoScrollDirection;
40
43
  AutoScrollDirection[AutoScrollDirection["None"] = 0] = "None";
41
44
  /** Auto-scrolling forward toward the end of the list */
42
45
  AutoScrollDirection[AutoScrollDirection["Forward"] = 1] = "Forward";
43
- })(AutoScrollDirection = exports.AutoScrollDirection || (exports.AutoScrollDirection = {}));
46
+ })(AutoScrollDirection || (exports.AutoScrollDirection = AutoScrollDirection = {}));