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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +390 -227
  3. package/lib/module/DebugOverlay.js +121 -0
  4. package/lib/module/DebugOverlay.js.map +1 -0
  5. package/lib/module/Drax.js +36 -0
  6. package/lib/module/Drax.js.map +1 -0
  7. package/lib/module/DraxContext.js +6 -0
  8. package/lib/module/DraxContext.js.map +1 -0
  9. package/lib/module/DraxHandle.js +47 -0
  10. package/lib/module/DraxHandle.js.map +1 -0
  11. package/lib/module/DraxHandleContext.js +11 -0
  12. package/lib/module/DraxHandleContext.js.map +1 -0
  13. package/lib/module/DraxList.js +108 -0
  14. package/lib/module/DraxList.js.map +1 -0
  15. package/lib/module/DraxProvider.js +203 -0
  16. package/lib/module/DraxProvider.js.map +1 -0
  17. package/lib/module/DraxScrollView.js +167 -0
  18. package/lib/module/DraxScrollView.js.map +1 -0
  19. package/lib/module/DraxSubprovider.js +21 -0
  20. package/lib/module/DraxSubprovider.js.map +1 -0
  21. package/lib/module/DraxView.js +348 -0
  22. package/lib/module/DraxView.js.map +1 -0
  23. package/lib/module/HoverLayer.js +152 -0
  24. package/lib/module/HoverLayer.js.map +1 -0
  25. package/lib/module/SortableBoardContainer.js +386 -0
  26. package/lib/module/SortableBoardContainer.js.map +1 -0
  27. package/lib/module/SortableBoardContext.js +6 -0
  28. package/lib/module/SortableBoardContext.js.map +1 -0
  29. package/lib/module/SortableContainer.js +571 -0
  30. package/lib/module/SortableContainer.js.map +1 -0
  31. package/lib/module/SortableItem.js +226 -0
  32. package/lib/module/SortableItem.js.map +1 -0
  33. package/lib/module/SortableItemContext.js +38 -0
  34. package/lib/module/SortableItemContext.js.map +1 -0
  35. package/lib/module/compat/detectVersion.js +19 -0
  36. package/lib/module/compat/detectVersion.js.map +1 -0
  37. package/lib/module/compat/index.js +5 -0
  38. package/lib/module/compat/index.js.map +1 -0
  39. package/lib/module/compat/types.js +4 -0
  40. package/lib/module/compat/types.js.map +1 -0
  41. package/lib/module/compat/useDraxPanGesture.js +94 -0
  42. package/lib/module/compat/useDraxPanGesture.js.map +1 -0
  43. package/lib/module/hooks/index.js +5 -0
  44. package/lib/module/hooks/index.js.map +1 -0
  45. package/lib/module/hooks/useCallbackDispatch.js +688 -0
  46. package/lib/module/hooks/useCallbackDispatch.js.map +1 -0
  47. package/lib/module/hooks/useDragGesture.js +240 -0
  48. package/lib/module/hooks/useDragGesture.js.map +1 -0
  49. package/lib/module/hooks/useDraxContext.js +12 -0
  50. package/lib/module/hooks/useDraxContext.js.map +1 -0
  51. package/lib/module/hooks/useDraxId.js +13 -0
  52. package/lib/module/hooks/useDraxId.js.map +1 -0
  53. package/lib/module/hooks/useDraxMethods.js +73 -0
  54. package/lib/module/hooks/useDraxMethods.js.map +1 -0
  55. package/lib/module/hooks/useDraxScrollHandler.js +97 -0
  56. package/lib/module/hooks/useDraxScrollHandler.js.map +1 -0
  57. package/lib/module/hooks/useSortableBoard.js +37 -0
  58. package/lib/module/hooks/useSortableBoard.js.map +1 -0
  59. package/lib/module/hooks/useSortableList.js +988 -0
  60. package/lib/module/hooks/useSortableList.js.map +1 -0
  61. package/lib/module/hooks/useSpatialIndex.js +283 -0
  62. package/lib/module/hooks/useSpatialIndex.js.map +1 -0
  63. package/lib/module/hooks/useViewStyles.js +158 -0
  64. package/lib/module/hooks/useViewStyles.js.map +1 -0
  65. package/lib/module/hooks/useWebScrollFreeze.js +52 -0
  66. package/lib/module/hooks/useWebScrollFreeze.js.map +1 -0
  67. package/lib/module/index.js +37 -0
  68. package/lib/module/index.js.map +1 -0
  69. package/lib/module/math.js +294 -0
  70. package/lib/module/math.js.map +1 -0
  71. package/lib/module/package.json +1 -0
  72. package/lib/module/params.js +88 -0
  73. package/lib/module/params.js.map +1 -0
  74. package/lib/module/types.js +215 -0
  75. package/lib/module/types.js.map +1 -0
  76. package/lib/typescript/package.json +1 -0
  77. package/lib/typescript/src/DebugOverlay.d.ts +17 -0
  78. package/lib/typescript/src/DebugOverlay.d.ts.map +1 -0
  79. package/lib/typescript/src/Drax.d.ts +28 -0
  80. package/lib/typescript/src/Drax.d.ts.map +1 -0
  81. package/lib/typescript/src/DraxContext.d.ts +3 -0
  82. package/lib/typescript/src/DraxContext.d.ts.map +1 -0
  83. package/lib/typescript/src/DraxHandle.d.ts +25 -0
  84. package/lib/typescript/src/DraxHandle.d.ts.map +1 -0
  85. package/lib/typescript/src/DraxHandleContext.d.ts +12 -0
  86. package/lib/typescript/src/DraxHandleContext.d.ts.map +1 -0
  87. package/lib/typescript/src/DraxList.d.ts +66 -0
  88. package/lib/typescript/src/DraxList.d.ts.map +1 -0
  89. package/lib/typescript/src/DraxProvider.d.ts +4 -0
  90. package/lib/typescript/src/DraxProvider.d.ts.map +1 -0
  91. package/lib/typescript/src/DraxScrollView.d.ts +7 -0
  92. package/lib/typescript/src/DraxScrollView.d.ts.map +1 -0
  93. package/lib/typescript/src/DraxSubprovider.d.ts +4 -0
  94. package/lib/typescript/src/DraxSubprovider.d.ts.map +1 -0
  95. package/lib/typescript/src/DraxView.d.ts +4 -0
  96. package/lib/typescript/src/DraxView.d.ts.map +1 -0
  97. package/lib/typescript/src/HoverLayer.d.ts +38 -0
  98. package/lib/typescript/src/HoverLayer.d.ts.map +1 -0
  99. package/lib/typescript/src/SortableBoardContainer.d.ts +11 -0
  100. package/lib/typescript/src/SortableBoardContainer.d.ts.map +1 -0
  101. package/lib/typescript/src/SortableBoardContext.d.ts +4 -0
  102. package/lib/typescript/src/SortableBoardContext.d.ts.map +1 -0
  103. package/lib/typescript/src/SortableContainer.d.ts +13 -0
  104. package/lib/typescript/src/SortableContainer.d.ts.map +1 -0
  105. package/lib/typescript/src/SortableItem.d.ts +14 -0
  106. package/lib/typescript/src/SortableItem.d.ts.map +1 -0
  107. package/lib/typescript/src/SortableItemContext.d.ts +37 -0
  108. package/lib/typescript/src/SortableItemContext.d.ts.map +1 -0
  109. package/lib/typescript/src/compat/detectVersion.d.ts +2 -0
  110. package/lib/typescript/src/compat/detectVersion.d.ts.map +1 -0
  111. package/lib/typescript/src/compat/index.d.ts +4 -0
  112. package/lib/typescript/src/compat/index.d.ts.map +1 -0
  113. package/lib/typescript/src/compat/types.d.ts +33 -0
  114. package/lib/typescript/src/compat/types.d.ts.map +1 -0
  115. package/lib/typescript/src/compat/useDraxPanGesture.d.ts +8 -0
  116. package/lib/typescript/src/compat/useDraxPanGesture.d.ts.map +1 -0
  117. package/lib/typescript/src/hooks/index.d.ts +3 -0
  118. package/lib/typescript/src/hooks/index.d.ts.map +1 -0
  119. package/lib/typescript/src/hooks/useCallbackDispatch.d.ts +40 -0
  120. package/lib/typescript/src/hooks/useCallbackDispatch.d.ts.map +1 -0
  121. package/lib/typescript/src/hooks/useDragGesture.d.ts +17 -0
  122. package/lib/typescript/src/hooks/useDragGesture.d.ts.map +1 -0
  123. package/lib/typescript/src/hooks/useDraxContext.d.ts +2 -0
  124. package/lib/typescript/src/hooks/useDraxContext.d.ts.map +1 -0
  125. package/{build → lib/typescript/src}/hooks/useDraxId.d.ts +1 -0
  126. package/lib/typescript/src/hooks/useDraxId.d.ts.map +1 -0
  127. package/lib/typescript/src/hooks/useDraxMethods.d.ts +13 -0
  128. package/lib/typescript/src/hooks/useDraxMethods.d.ts.map +1 -0
  129. package/lib/typescript/src/hooks/useDraxScrollHandler.d.ts +27 -0
  130. package/lib/typescript/src/hooks/useDraxScrollHandler.d.ts.map +1 -0
  131. package/lib/typescript/src/hooks/useSortableBoard.d.ts +10 -0
  132. package/lib/typescript/src/hooks/useSortableBoard.d.ts.map +1 -0
  133. package/lib/typescript/src/hooks/useSortableList.d.ts +11 -0
  134. package/lib/typescript/src/hooks/useSortableList.d.ts.map +1 -0
  135. package/lib/typescript/src/hooks/useSpatialIndex.d.ts +22 -0
  136. package/lib/typescript/src/hooks/useSpatialIndex.d.ts.map +1 -0
  137. package/lib/typescript/src/hooks/useViewStyles.d.ts +183 -0
  138. package/lib/typescript/src/hooks/useViewStyles.d.ts.map +1 -0
  139. package/lib/typescript/src/hooks/useWebScrollFreeze.d.ts +14 -0
  140. package/lib/typescript/src/hooks/useWebScrollFreeze.d.ts.map +1 -0
  141. package/lib/typescript/src/index.d.ts +25 -0
  142. package/lib/typescript/src/index.d.ts.map +1 -0
  143. package/lib/typescript/src/math.d.ts +76 -0
  144. package/lib/typescript/src/math.d.ts.map +1 -0
  145. package/{build → lib/typescript/src}/params.d.ts +13 -9
  146. package/lib/typescript/src/params.d.ts.map +1 -0
  147. package/lib/typescript/src/types.d.ts +756 -0
  148. package/lib/typescript/src/types.d.ts.map +1 -0
  149. package/package.json +164 -34
  150. package/src/DebugOverlay.tsx +140 -0
  151. package/src/Drax.ts +33 -0
  152. package/src/DraxContext.ts +8 -0
  153. package/src/DraxHandle.tsx +52 -0
  154. package/src/DraxHandleContext.ts +15 -0
  155. package/src/DraxList.tsx +181 -0
  156. package/src/DraxProvider.tsx +224 -0
  157. package/src/DraxScrollView.tsx +180 -0
  158. package/src/DraxSubprovider.tsx +22 -0
  159. package/src/DraxView.tsx +430 -0
  160. package/src/HoverLayer.tsx +167 -0
  161. package/src/SortableBoardContainer.tsx +439 -0
  162. package/src/SortableBoardContext.ts +6 -0
  163. package/src/SortableContainer.tsx +650 -0
  164. package/src/SortableItem.tsx +264 -0
  165. package/src/SortableItemContext.ts +46 -0
  166. package/src/compat/detectVersion.ts +17 -0
  167. package/src/compat/index.ts +7 -0
  168. package/src/compat/types.ts +35 -0
  169. package/src/compat/useDraxPanGesture.ts +112 -0
  170. package/src/hooks/index.ts +2 -0
  171. package/src/hooks/useCallbackDispatch.tsx +830 -0
  172. package/src/hooks/useDragGesture.ts +273 -0
  173. package/src/hooks/useDraxContext.ts +11 -0
  174. package/src/hooks/useDraxId.ts +11 -0
  175. package/src/hooks/useDraxMethods.ts +71 -0
  176. package/src/hooks/useDraxScrollHandler.ts +121 -0
  177. package/src/hooks/useSortableBoard.ts +44 -0
  178. package/src/hooks/useSortableList.ts +1063 -0
  179. package/src/hooks/useSpatialIndex.ts +336 -0
  180. package/src/hooks/useViewStyles.ts +180 -0
  181. package/src/hooks/useWebScrollFreeze.ts +60 -0
  182. package/src/index.ts +111 -0
  183. package/src/math.ts +333 -0
  184. package/src/params.ts +74 -0
  185. package/src/types.ts +933 -0
  186. package/.editorconfig +0 -15
  187. package/.eslintrc.js +0 -4
  188. package/.prettierrc +0 -16
  189. package/CHANGELOG.md +0 -270
  190. package/CODE-OF-CONDUCT.md +0 -85
  191. package/CONTRIBUTING.md +0 -15
  192. package/FUNDING.yml +0 -4
  193. package/build/AllHoverViews.d.ts +0 -0
  194. package/build/AllHoverViews.js +0 -30
  195. package/build/DraxContext.d.ts +0 -2
  196. package/build/DraxContext.js +0 -6
  197. package/build/DraxList.d.ts +0 -8
  198. package/build/DraxList.js +0 -512
  199. package/build/DraxListItem.d.ts +0 -7
  200. package/build/DraxListItem.js +0 -121
  201. package/build/DraxProvider.d.ts +0 -2
  202. package/build/DraxProvider.js +0 -704
  203. package/build/DraxScrollView.d.ts +0 -6
  204. package/build/DraxScrollView.js +0 -136
  205. package/build/DraxSubprovider.d.ts +0 -3
  206. package/build/DraxSubprovider.js +0 -18
  207. package/build/DraxView.d.ts +0 -8
  208. package/build/DraxView.js +0 -93
  209. package/build/HoverView.d.ts +0 -8
  210. package/build/HoverView.js +0 -40
  211. package/build/PanGestureDetector.d.ts +0 -3
  212. package/build/PanGestureDetector.js +0 -49
  213. package/build/hooks/index.d.ts +0 -4
  214. package/build/hooks/index.js +0 -11
  215. package/build/hooks/useContent.d.ts +0 -23
  216. package/build/hooks/useContent.js +0 -212
  217. package/build/hooks/useDraxContext.d.ts +0 -1
  218. package/build/hooks/useDraxContext.js +0 -13
  219. package/build/hooks/useDraxId.js +0 -13
  220. package/build/hooks/useDraxProtocol.d.ts +0 -5
  221. package/build/hooks/useDraxProtocol.js +0 -32
  222. package/build/hooks/useDraxRegistry.d.ts +0 -78
  223. package/build/hooks/useDraxRegistry.js +0 -714
  224. package/build/hooks/useDraxScrollHandler.d.ts +0 -25
  225. package/build/hooks/useDraxScrollHandler.js +0 -89
  226. package/build/hooks/useDraxState.d.ts +0 -10
  227. package/build/hooks/useDraxState.js +0 -132
  228. package/build/hooks/useMeasurements.d.ts +0 -9
  229. package/build/hooks/useMeasurements.js +0 -119
  230. package/build/hooks/useStatus.d.ts +0 -11
  231. package/build/hooks/useStatus.js +0 -96
  232. package/build/index.d.ts +0 -9
  233. package/build/index.js +0 -33
  234. package/build/math.d.ts +0 -22
  235. package/build/math.js +0 -68
  236. package/build/params.js +0 -27
  237. package/build/transform.d.ts +0 -11
  238. package/build/transform.js +0 -59
  239. package/build/types.d.ts +0 -807
  240. package/build/types.js +0 -46
  241. package/docs/concept.md +0 -79
  242. package/docs/images/color-drag-drop.gif +0 -0
  243. package/docs/images/deck-cards.gif +0 -0
  244. package/docs/images/drag-drop-events.jpg +0 -0
  245. package/docs/images/knight-moves.gif +0 -0
  246. package/docs/images/reorderable-list.gif +0 -0
package/build/types.d.ts DELETED
@@ -1,807 +0,0 @@
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';
6
- /** Gesture state change event expected by Drax handler */
7
- export type DraxGestureStateChangeEvent = LongPressGestureHandlerStateChangeEvent['nativeEvent'];
8
- /** Gesture event expected by Drax handler */
9
- export type DraxGestureEvent = LongPressGesture;
10
- /** An xy-coordinate position value */
11
- export interface Position {
12
- [k: string]: number;
13
- /** Position on horizontal x-axis, positive is right */
14
- x: number;
15
- /** Position on vertical y-axis, positive is down */
16
- y: number;
17
- }
18
- /** Predicate for checking if something is a Position */
19
- export declare const isPosition: (something: any) => something is Position;
20
- /** Dimensions of a view */
21
- export interface ViewDimensions {
22
- /** Width of view */
23
- width: number;
24
- /** Height of view */
25
- height: number;
26
- }
27
- /** Measurements of a Drax view for bounds checking purposes, relative to Drax parent view or DraxProvider (absolute) */
28
- export interface DraxViewMeasurements extends Position, ViewDimensions {
29
- }
30
- /** Data about a view involved in a Drax event */
31
- export interface DraxEventViewData extends DraxPayloadViewData {
32
- /** The view's id */
33
- id: string;
34
- /** The view's parent id, if any */
35
- parentId?: string;
36
- /** The view's payload for this event */
37
- payload: any;
38
- }
39
- /** Data about a dragged view involved in a Drax event */
40
- export interface DraxEventDraggedViewData extends DraxEventViewData {
41
- /** The ratio of the drag translation to the dimensions of the view */
42
- dragTranslationRatio: Position;
43
- /** The relative offset of the drag point from the view */
44
- dragOffset: Position;
45
- /** The relative offset of where the view was grabbed */
46
- grabOffset: Position;
47
- /** The relative offset/dimensions ratio of where the view was grabbed */
48
- grabOffsetRatio: Position;
49
- /** The position in absolute coordinates of the dragged hover view (dragAbsolutePosition - grabOffset) */
50
- hoverPosition: Position;
51
- }
52
- /** Data about a receiver view involved in a Drax event */
53
- export interface DraxEventReceiverViewData extends DraxEventViewData {
54
- /** The relative offset of the drag point in the receiving view */
55
- receiveOffset: Position;
56
- /** The relative offset/dimensions ratio of the drag point in the receiving view */
57
- receiveOffsetRatio: Position;
58
- }
59
- /** Data about a Drax drag event */
60
- export interface DraxDragEventData {
61
- /** Position of the drag event in absolute coordinates */
62
- dragAbsolutePosition: Position;
63
- /** The absolute drag distance from where the drag started */
64
- dragTranslation: Position;
65
- /** Data about the dragged view */
66
- dragged: DraxEventDraggedViewData;
67
- }
68
- /** Supplemental type for adding a cancelled flag */
69
- export interface WithCancelledFlag {
70
- /** True if the event was cancelled */
71
- cancelled: boolean;
72
- }
73
- /** Predicate for checking if something has a cancelled flag */
74
- export declare const isWithCancelledFlag: (something: any) => something is WithCancelledFlag;
75
- /** Data about a Drax drag end event */
76
- export interface DraxDragEndEventData extends DraxDragEventData, WithCancelledFlag {
77
- }
78
- /** Data about a Drax drag event that involves a receiver */
79
- export interface DraxDragWithReceiverEventData extends DraxDragEventData {
80
- /** The receiver for the drag event */
81
- receiver: DraxEventReceiverViewData;
82
- }
83
- /** Data about a Drax drag/receive end event */
84
- export interface DraxDragWithReceiverEndEventData extends DraxDragWithReceiverEventData, WithCancelledFlag {
85
- }
86
- /** Data about a Drax snap, used for custom animations */
87
- export interface DraxSnapData {
88
- hoverPosition: SharedValue<Position>;
89
- toValue: Position;
90
- delay: number;
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;
98
- }
99
- /** Data about a Drax monitor event */
100
- export interface DraxMonitorEventData extends DraxDragEventData {
101
- /** The receiver for the monitor event, if any */
102
- receiver?: DraxEventReceiverViewData;
103
- /** Event position relative to the monitor */
104
- monitorOffset: Position;
105
- /** Event position/dimensions ratio relative to the monitor */
106
- monitorOffsetRatio: Position;
107
- }
108
- /** Data about a Drax monitor drag end event */
109
- export interface DraxMonitorEndEventData extends DraxMonitorEventData, WithCancelledFlag {
110
- }
111
- /** Data about a Drax monitor drag-drop event */
112
- export interface DraxMonitorDragDropEventData extends Required<DraxMonitorEventData> {
113
- }
114
- /** Preset values for specifying snap targets without a Position */
115
- export declare enum DraxSnapbackTargetPreset {
116
- Default = 0,
117
- None = 1
118
- }
119
- /** Target for snap hover view release animation: none, default, or specified Position */
120
- export type DraxSnapbackTarget = DraxSnapbackTargetPreset | Position;
121
- /**
122
- * Response type for Drax protocol callbacks involving end of a drag,
123
- * allowing override of default release snap behavior.
124
- */
125
- export type DraxProtocolDragEndResponse = void | DraxSnapbackTarget;
126
- /** Props provided to an internal render function for a hovering copy of a Drax view */
127
- export interface DraxInternalRenderHoverViewProps {
128
- /** Key of the hover view React node */
129
- key: string;
130
- /** Hover position of the view - Reanimated shared value */
131
- hoverPosition: SharedValue<Position>;
132
- /** State for the view */
133
- viewState: DraxViewState;
134
- /** Drax tracking status */
135
- trackingStatus: DraxTrackingStatus;
136
- /** Dimensions for the view */
137
- dimensions: ViewDimensions;
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>;
146
- /** Props provided to a render function for a Drax view */
147
- export interface DraxRenderContentProps {
148
- /** State for the view, if available */
149
- viewState?: DraxViewState;
150
- /** Drax tracking status */
151
- trackingStatus?: DraxTrackingStatus;
152
- /** Is this a hovering copy of the view? */
153
- hover: boolean;
154
- /** React children of the DraxView */
155
- children: ReactNode;
156
- /** Dimensions for the view, if available */
157
- dimensions?: ViewDimensions;
158
- }
159
- /** Props provided to a render function for a hovering copy of a Drax view, compatible with DraxRenderContentProps */
160
- export interface DraxRenderHoverContentProps extends DraxRenderContentProps {
161
- }
162
- type DraxPayloadViewData = {
163
- data: DraxAbsoluteViewData;
164
- };
165
- type DraxSnapPayload = {
166
- dragged: DraxPayloadViewData & Omit<DraxTrackingDrag, 'receiver'>;
167
- receiver?: DraxPayloadViewData & DraxTrackingReceiver;
168
- };
169
- /** Callback protocol for communicating Drax events to views */
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;
178
- /** Called in the dragged view when a drag action begins */
179
- onDragStart?: (data: DraxDragEventData) => void;
180
- /** Called in the dragged view repeatedly while dragged, not over any receiver */
181
- onDrag?: (data: DraxDragEventData) => void;
182
- /** Called in the dragged view when initially dragged over a new receiver */
183
- onDragEnter?: (data: DraxDragWithReceiverEventData) => void;
184
- /** Called in the dragged view repeatedly while dragged over a receiver */
185
- onDragOver?: (data: DraxDragWithReceiverEventData) => void;
186
- /** Called in the dragged view when dragged off of a receiver */
187
- onDragExit?: (data: DraxDragWithReceiverEventData) => void;
188
- /** Called in the dragged view when drag ends not over any receiver or is cancelled */
189
- onDragEnd?: (data: DraxDragEndEventData) => DraxProtocolDragEndResponse;
190
- /** Called in the dragged view when drag ends over a receiver */
191
- onDragDrop?: (data: DraxDragWithReceiverEventData) => DraxProtocolDragEndResponse;
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;
196
- /** Called in the receiver view each time an item is initially dragged over it */
197
- onReceiveDragEnter?: (data: DraxDragWithReceiverEventData) => void;
198
- /** Called in the receiver view repeatedly while an item is dragged over it */
199
- onReceiveDragOver?: (data: DraxDragWithReceiverEventData) => void;
200
- /** Called in the receiver view when item is dragged off of it or drag is cancelled */
201
- onReceiveDragExit?: (data: DraxDragWithReceiverEndEventData) => void;
202
- /** Called in the receiver view when drag ends over it */
203
- onReceiveDragDrop?: (data: DraxDragWithReceiverEventData) => DraxProtocolDragEndResponse;
204
- /** Called in the monitor view when a drag action begins over it */
205
- onMonitorDragStart?: (data: DraxMonitorEventData) => void;
206
- /** Called in the monitor view each time an item is initially dragged over it */
207
- onMonitorDragEnter?: (data: DraxMonitorEventData) => void;
208
- /** Called in the monitor view repeatedly while an item is dragged over it */
209
- onMonitorDragOver?: (data: DraxMonitorEventData) => void;
210
- /** Called in the monitor view when item is dragged off of it */
211
- onMonitorDragExit?: (data: DraxMonitorEventData) => void;
212
- /** Called in the monitor view when drag ends over it while not over any receiver or drag is cancelled */
213
- onMonitorDragEnd?: (data: DraxMonitorEndEventData) => DraxProtocolDragEndResponse;
214
- /** Called in the monitor view when drag ends over it while over a receiver */
215
- onMonitorDragDrop?: (data: DraxMonitorDragDropEventData) => DraxProtocolDragEndResponse;
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;
224
- /** Payload that will be delivered to receiver views when this view is dragged; overrides `payload` */
225
- dragPayload?: any;
226
- /** Payload that will be delievered to dragged views when this view receives them; overrides `payload` */
227
- receiverPayload?: any;
228
- /** Convenience prop to provide one value for both `dragPayload` and `receiverPayload` */
229
- payload?: any;
230
- /** Whether the view can be dragged */
231
- draggable?: boolean;
232
- /** Whether the view can receive drags */
233
- receptive?: boolean;
234
- /** Whether the view can monitor drags */
235
- monitoring?: boolean;
236
- /** If true, lock drag's x-position */
237
- lockDragXPosition?: boolean;
238
- /** If true, lock drag's y position */
239
- lockDragYPosition?: boolean;
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;
245
- }
246
- /** Props for components implementing the protocol */
247
- export interface DraxProtocolProps extends Partial<Omit<DraxProtocol, 'internalRenderHoverView'>> {
248
- }
249
- /** The states a dragged view can be in */
250
- export declare enum DraxViewDragStatus {
251
- /** View is not being dragged */
252
- Inactive = 0,
253
- /** View is being actively dragged; an active drag touch began in this view */
254
- Dragging = 1,
255
- /** View has been released but has not yet snapped back to inactive */
256
- Released = 2
257
- }
258
- /** The states a receiver view can be in */
259
- export declare enum DraxViewReceiveStatus {
260
- /** View is not receiving a drag */
261
- Inactive = 0,
262
- /** View is receiving a drag; an active drag touch point is currently over this view */
263
- Receiving = 1
264
- }
265
- /** Information about a view, used internally by the Drax provider */
266
- export interface DraxViewData {
267
- /** The view's Drax parent view id, if nested */
268
- parentId?: string;
269
- /** The view's scroll position ref, if it is a scrollable parent view */
270
- scrollPosition?: SharedValue<Position>;
271
- /** The view's protocol callbacks and data */
272
- protocol: DraxProtocol;
273
- /** The view's measurements for bounds checking */
274
- measurements?: DraxViewMeasurements;
275
- /** The hover view's measurements for bounds checking */
276
- hoverMeasurements?: DraxViewMeasurements;
277
- }
278
- /** Information about a view, plus its clipped absolute measurements */
279
- export interface DraxAbsoluteViewData extends Omit<DraxViewData, 'measurements'>, Required<Pick<DraxViewData, 'measurements'>> {
280
- /** Absolute measurements for view */
281
- absoluteMeasurements: DraxViewMeasurements;
282
- }
283
- /** Wrapper of id and absolute data for a view */
284
- export interface DraxAbsoluteViewEntry {
285
- /** The view's unique identifier */
286
- id: string;
287
- data: DraxAbsoluteViewData;
288
- }
289
- /** Wrapper of id and absolute data for a view found when checking a position */
290
- export interface DraxFoundAbsoluteViewEntry extends DraxAbsoluteViewEntry {
291
- /** Position, relative to the view, of the touch for which it was found */
292
- relativePosition: Position;
293
- /** Position/dimensions ratio, relative to the view, of the touch for which it was found */
294
- relativePositionRatio: Position;
295
- }
296
- /** Tracking information about the current receiver, used internally by the Drax provider */
297
- export interface DraxTrackingReceiver {
298
- /** View id of the current receiver */
299
- receiverId: string;
300
- /** The relative offset of the drag point in the receiving view */
301
- receiveOffset: Position;
302
- /** The relative offset/dimensions ratio of the drag point in the receiving view */
303
- receiveOffsetRatio: Position;
304
- }
305
- /** Tracking information about the current drag, used internally by the Drax provider */
306
- export interface DraxTrackingDrag {
307
- /** View id of the dragged view */
308
- draggedId: string;
309
- /** Start position of the drag in absolute coordinates */
310
- absoluteStartPosition: Position;
311
- /** Start position of the drag relative to dragged view's immediate parent */
312
- parentStartPosition: Position;
313
- /** The position in absolute coordinates of the drag point */
314
- dragAbsolutePosition: Position;
315
- /** The absolute drag distance from where the drag started (dragAbsolutePosition - absoluteStartPosition) */
316
- dragTranslation: Position;
317
- /** The ratio of the drag translation to the dimensions of the view */
318
- dragTranslationRatio: Position;
319
- /** The relative offset of the drag point from the view */
320
- dragOffset: Position;
321
- /** The relative offset within the dragged view of where it was grabbed */
322
- grabOffset: Position;
323
- /** The relative offset/dimensions ratio within the dragged view of where it was grabbed */
324
- grabOffsetRatio: Position;
325
- /** The position in absolute coordinates of the dragged hover view (dragAbsolutePosition - grabOffset) */
326
- hoverPosition: SharedValue<Position>;
327
- /** Tracking information about the current drag receiver, if any */
328
- receiver?: DraxTrackingReceiver;
329
- /** View ids of monitors that the drag is currently over */
330
- monitorIds: string[];
331
- }
332
- /** Tracking information about a view that was released and is snapping back */
333
- export interface DraxTrackingRelease {
334
- /** View id of the released view */
335
- viewId: string;
336
- /** The position in absolute coordinates of the released hover view */
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;
344
- }
345
- /** Tracking status for reference in views */
346
- export interface DraxTrackingStatus {
347
- /** Is any view being dragged? */
348
- dragging: boolean;
349
- /** Is any view receiving a drag? */
350
- receiving: boolean;
351
- }
352
- /** Render-related state for a registered view */
353
- export interface DraxViewState extends Partial<DraxPayloadViewData> {
354
- id?: string;
355
- /** Current drag status of the view: Dragged, Released, or Inactive */
356
- dragStatus: DraxViewDragStatus;
357
- /** If being dragged, the position in absolute coordinates of the drag point */
358
- dragAbsolutePosition?: Position;
359
- /** If being dragged, the absolute drag distance from where the drag started (dragAbsolutePosition - absoluteStartPosition) */
360
- dragTranslation?: Position;
361
- /** If being dragged, the ratio of the drag translation to the dimensions of the view */
362
- dragTranslationRatio?: Position;
363
- /** If being dragged, the relative offset of the drag point from the view */
364
- dragOffset?: Position;
365
- /** If being dragged, the relative offset of where the view was grabbed */
366
- grabOffset?: Position;
367
- /** If being dragged, the relative offset/dimensions ratio of where the view was grabbed */
368
- grabOffsetRatio?: Position;
369
- /** The position in absolute coordinates of the dragged hover view (dragAbsolutePosition - grabOffset) */
370
- /** Data about the receiver this view is being dragged over, if any */
371
- draggingOverReceiver?: DraxEventViewData;
372
- /** Current receive status of the view: Receiving or Inactive */
373
- receiveStatus: DraxViewReceiveStatus;
374
- /** If receiving a drag, the relative offset of the drag point in the view */
375
- receiveOffset?: Position;
376
- /** If receiving a drag, the relative offset/dimensions ratio of the drag point in the view */
377
- receiveOffsetRatio?: Position;
378
- /** Data about the dragged item this view is receiving, if any */
379
- receivingDrag?: DraxEventViewData;
380
- /** Data about the released dragged item */
381
- releasedDragTracking?: DraxTrackingDrag;
382
- }
383
- /** Drax provider render state; maintains render-related data */
384
- export interface DraxState {
385
- /** Render-related state for all registered views, keyed by their unique identifiers */
386
- viewStateById: {
387
- /** Render-related state for a registered view, keyed by its unique identifier */
388
- [id: string]: DraxViewState;
389
- };
390
- /** Tracking status indicating whether anything is being dragged/received */
391
- trackingStatus: DraxTrackingStatus;
392
- }
393
- /** Payload to start tracking a drag */
394
- export interface StartDragPayload {
395
- /** Absolute position of where the drag started */
396
- dragAbsolutePosition: Position;
397
- /** Position relative to the dragged view's immediate parent where the drag started */
398
- dragParentPosition: Position;
399
- /** The dragged view's unique identifier */
400
- draggedId: string;
401
- /** The relative offset within the view of where it was grabbed */
402
- grabOffset: Position;
403
- /** The relative offset/dimensions ratio within the view of where it was grabbed */
404
- grabOffsetRatio: Position;
405
- }
406
- /** Payload for registering a Drax view */
407
- export interface RegisterViewPayload {
408
- /** The view's unique identifier */
409
- id: string;
410
- /** The view's Drax parent view id, if nested */
411
- parentId?: string;
412
- /** The view's scroll position ref, if it is a scrollable parent view */
413
- scrollPosition?: SharedValue<Position>;
414
- }
415
- /** Payload for unregistering a Drax view */
416
- export interface UnregisterViewPayload {
417
- /** The view's unique identifier */
418
- id: string;
419
- }
420
- /** Payload for updating the protocol values of a registered view */
421
- export interface UpdateViewProtocolPayload {
422
- /** The view's unique identifier */
423
- id: string;
424
- /** The current protocol values for the view */
425
- protocol: DraxProtocol;
426
- }
427
- /** Payload for reporting the latest measurements of a view after layout */
428
- export interface UpdateViewMeasurementsPayload {
429
- /** The view's unique identifier */
430
- id: string;
431
- /** The view's measurements */
432
- measurements: DraxViewMeasurements | undefined;
433
- }
434
- /** Payload used by Drax provider internally for creating a view's state */
435
- export interface CreateViewStatePayload {
436
- /** The view's unique identifier */
437
- id: string;
438
- }
439
- /** Payload used by Drax provider internally for updating a view's state */
440
- export interface UpdateViewStatePayload {
441
- /** The view's unique identifier */
442
- id: string;
443
- /** The view state update */
444
- viewStateUpdate: Partial<DraxViewState>;
445
- }
446
- /** Payload used by Drax provider internally for deleting a view's state */
447
- export interface DeleteViewStatePayload {
448
- /** The view's unique identifier */
449
- id: string;
450
- }
451
- /** Payload used by Drax provider internally for updating tracking status */
452
- export interface UpdateTrackingStatusPayload extends Partial<DraxTrackingStatus> {
453
- }
454
- /** Collection of Drax state action creators */
455
- export interface DraxStateActionCreators {
456
- createViewState: PayloadActionCreator<'createViewState', CreateViewStatePayload>;
457
- updateViewState: PayloadActionCreator<'updateViewState', UpdateViewStatePayload>;
458
- deleteViewState: PayloadActionCreator<'deleteViewState', DeleteViewStatePayload>;
459
- updateTrackingStatus: PayloadActionCreator<'updateTrackingStatus', UpdateTrackingStatusPayload>;
460
- }
461
- /** Dispatchable Drax state action */
462
- export type DraxStateAction = ActionType<DraxStateActionCreators>;
463
- /** Dispatcher of Drax state actions */
464
- export type DraxStateDispatch = (action: DraxStateAction) => void;
465
- /** Drax provider internal registry; maintains view data and tracks drags, updating state */
466
- export interface DraxRegistry {
467
- /** A list of the unique identifiers of the registered views, in order of registration */
468
- viewIds: string[];
469
- /** Data about all registered views, keyed by their unique identifiers */
470
- viewDataById: {
471
- /** Data about a registered view, keyed by its unique identifier */
472
- [id: string]: DraxViewData;
473
- };
474
- /** Information about the current drag, if any */
475
- drag?: DraxTrackingDrag;
476
- /** A list of the unique identifiers of tracked drag releases, in order of release */
477
- releaseIds: string[];
478
- /** Released drags that are snapping back, keyed by unique release identifier */
479
- releaseById: {
480
- [releaseId: string]: DraxTrackingRelease;
481
- };
482
- /** Drax state dispatch function */
483
- stateDispatch: DraxStateDispatch;
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
- }>;
510
- /** Context value used internally by Drax provider */
511
- export interface DraxContextValue {
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 */;
535
- getViewState: (id: string) => DraxViewState | undefined;
536
- /** Get current Drax tracking status */
537
- getTrackingStatus: () => DraxTrackingStatus;
538
- /** Register a Drax view */
539
- registerView: (payload: RegisterViewPayload) => void;
540
- /** Unregister a Drax view */
541
- unregisterView: (payload: UnregisterViewPayload) => void;
542
- /** Update protocol for a registered Drax view */
543
- updateViewProtocol: (payload: UpdateViewProtocolPayload) => void;
544
- /** Update view measurements for a registered Drax view */
545
- updateViewMeasurements: (payload: UpdateViewMeasurementsPayload) => void;
546
- /** Update hover view measurements for a registered Drax view */
547
- updateHoverViewMeasurements: (payload: UpdateViewMeasurementsPayload) => void;
548
- /** Handle gesture state change for a registered Drax view */
549
- handleGestureStateChange: (id: string) => (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => void;
550
- /** Handle gesture event for a registered Drax view */
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>;
554
- /** Drax parent view for all views under this context, when nesting */
555
- parent?: DraxParentView;
556
- }
557
- /** Optional props that can be passed to a DraxProvider to modify its behavior */
558
- export interface DraxProviderProps {
559
- style?: StyleProp<ViewStyle>;
560
- debug?: boolean;
561
- children?: ReactNode;
562
- }
563
- /** Props that are passed to a DraxSubprovider, used internally for nesting views */
564
- export interface DraxSubproviderProps {
565
- /** Drax parent view for all views under this subprovider, when nesting */
566
- parent: DraxParentView;
567
- }
568
- /** Methods provided by a DraxView when registered externally */
569
- export interface DraxViewRegistration {
570
- id: string;
571
- measure: (measurementHandler?: DraxViewMeasurementHandler) => void;
572
- }
573
- /** Information about the parent of a nested DraxView, primarily used for scrollable parent views */
574
- export interface DraxParentView {
575
- /** Drax view id of the parent */
576
- id: string;
577
- /** View Ref of the parent, for measuring relative to */
578
- viewRef: RefObject<ElementRef<typeof ScrollViewComponent> | ScrollView | View | null | undefined>;
579
- }
580
- /** Function that receives a Drax view measurement */
581
- export interface DraxViewMeasurementHandler {
582
- (measurements: DraxViewMeasurements | undefined): void;
583
- }
584
- /** Layout-related style keys that are omitted from hover view styles */
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>>>;
587
- /** Style for a Animated.View used for a hover view */
588
- export type AnimatedViewStyleWithoutLayout = Omit<TSDraxtyles, LayoutStyleKey>;
589
- /** Style prop for a Animated.View used for a hover view */
590
- export type AnimatedViewStylePropWithoutLayout = TSDraxtyles;
591
- /** Style-related props for a Drax view */
592
- export interface DraxViewStyleProps {
593
- /** Custom style prop to allow animated values */
594
- style?: TSDraxtyles;
595
- /** Additional view style applied while this view is not being dragged or released */
596
- dragInactiveStyle?: TSDraxtyles;
597
- /** Additional view style applied while this view is being dragged */
598
- draggingStyle?: TSDraxtyles;
599
- /** Additional view style applied while this view is being dragged over a receiver */
600
- draggingWithReceiverStyle?: TSDraxtyles;
601
- /** Additional view style applied while this view is being dragged NOT over a receiver */
602
- draggingWithoutReceiverStyle?: TSDraxtyles;
603
- /** Additional view style applied while this view has just been released from a drag */
604
- dragReleasedStyle?: TSDraxtyles;
605
- /** Additional view style applied to the hovering copy of this view during drag/release */
606
- hoverStyle?: AnimatedViewStylePropWithoutLayout;
607
- /** Additional view style applied to the hovering copy of this view while dragging */
608
- hoverDraggingStyle?: AnimatedViewStylePropWithoutLayout;
609
- /** Additional view style applied to the hovering copy of this view while dragging over a receiver */
610
- hoverDraggingWithReceiverStyle?: AnimatedViewStylePropWithoutLayout;
611
- /** Additional view style applied to the hovering copy of this view while dragging NOT over a receiver */
612
- hoverDraggingWithoutReceiverStyle?: AnimatedViewStylePropWithoutLayout;
613
- /** Additional view style applied to the hovering copy of this view when just released */
614
- hoverDragReleasedStyle?: AnimatedViewStylePropWithoutLayout;
615
- /** Additional view style applied while this view is not receiving a drag */
616
- receiverInactiveStyle?: TSDraxtyles;
617
- /** Additional view style applied while this view is receiving a drag */
618
- receivingStyle?: TSDraxtyles;
619
- /** Additional view style applied to this view while any other view is being dragged */
620
- otherDraggingStyle?: TSDraxtyles;
621
- /** Additional view style applied to this view while any other view is being dragged over a receiver */
622
- otherDraggingWithReceiverStyle?: TSDraxtyles;
623
- /** Additional view style applied to this view while any other view is being dragged NOT over a receiver */
624
- otherDraggingWithoutReceiverStyle?: TSDraxtyles;
625
- }
626
- /** Custom render function for content of a DraxView */
627
- export interface DraxViewRenderContent {
628
- (props: DraxRenderContentProps): ReactNode;
629
- }
630
- /** Custom render function for content of hovering copy of a DraxView */
631
- export interface DraxViewRenderHoverContent {
632
- (props: DraxRenderHoverContentProps): ReactNode;
633
- }
634
- export type TStartPosition = {
635
- parent: Position;
636
- grab: Position;
637
- };
638
- /** Props for a DraxView; combines protocol props and standard view props */
639
- export interface DraxViewProps extends Omit<ViewProps, 'style'>, DraxProtocolProps, DraxViewStyleProps {
640
- /** Custom render function for content of this view */
641
- renderContent?: DraxViewRenderContent;
642
- /** Custom render function for content of hovering copy of this view, defaults to renderContent */
643
- renderHoverContent?: DraxViewRenderHoverContent;
644
- /** If true, do not render hover view copies for this view when dragging */
645
- noHover?: boolean;
646
- /** For external registration of this view, to access internal methods, similar to a ref */
647
- registration?: (registration: DraxViewRegistration | undefined) => void;
648
- /** For receiving view measurements externally */
649
- onMeasure?: DraxViewMeasurementHandler;
650
- /** Unique Drax view id, auto-generated if omitted */
651
- id?: string;
652
- /** Drax parent view, if nesting */
653
- parent?: DraxParentView;
654
- /** If true, treat this view as a Drax parent view for nested children */
655
- isParent?: boolean;
656
- /** Used internally - The view's scroll position, if it is a scrollable parent view */
657
- scrollPosition?: SharedValue<Position>;
658
- /** Time in milliseconds view needs to be pressed before drag starts */
659
- longPressDelay?: number;
660
- }
661
- /** Auto-scroll direction used internally by DraxScrollView and DraxList */
662
- export declare enum AutoScrollDirection {
663
- /** Auto-scrolling back toward the beginning of list */
664
- Back = -1,
665
- /** Not auto-scrolling */
666
- None = 0,
667
- /** Auto-scrolling forward toward the end of the list */
668
- Forward = 1
669
- }
670
- /** Auto-scroll state used internally by DraxScrollView */
671
- export interface AutoScrollState {
672
- x: AutoScrollDirection;
673
- y: AutoScrollDirection;
674
- }
675
- /** Props for auto-scroll options, used by DraxScrollView and DraxList */
676
- export interface DraxAutoScrollProps {
677
- autoScrollIntervalLength?: number;
678
- autoScrollJumpRatio?: number;
679
- autoScrollBackThreshold?: number;
680
- autoScrollForwardThreshold?: number;
681
- }
682
- /** Props for a DraxScrollView; extends standard ScrollView props */
683
- export interface DraxScrollViewProps extends ScrollViewProps, DraxAutoScrollProps {
684
- /** Unique drax view id, auto-generated if omitted */
685
- id?: string;
686
- }
687
- /** DraxList item being dragged */
688
- export interface DraxListDraggedItemData<TItem> {
689
- /** The list index of the item that is being dragged */
690
- index: number;
691
- /** The item that is being dragged (or undefined if data is not found) */
692
- item?: TItem;
693
- /** Boolean representing an incoming external item dragged into the DraxList */
694
- isExternalDrag: boolean;
695
- }
696
- /** Event data for when a list item reorder drag action begins */
697
- export interface DraxListOnItemDragStartEventData<TItem> extends DraxDragEventData, DraxListDraggedItemData<TItem> {
698
- }
699
- /** Event data for when a list item position (index) changes during a reorder drag */
700
- export interface DraxListOnItemDragPositionChangeEventData<TItem> extends DraxMonitorEventData, DraxListDraggedItemData<TItem> {
701
- toIndex: number | undefined;
702
- previousIndex: number | undefined;
703
- }
704
- /** Event data for when a list item reorder drag action ends */
705
- export interface DraxListOnItemDragEndEventData<TItem> extends DraxMonitorEventData, WithCancelledFlag, DraxListDraggedItemData<TItem> {
706
- toIndex?: number;
707
- toItem?: TItem;
708
- }
709
- /** Event data for when an item is released in a new position within a DraxList, reordering the list */
710
- export interface DraxListOnItemReorderEventData<TItem> {
711
- /** The item that was moved */
712
- fromItem?: TItem;
713
- /** The list index of the item that was moved */
714
- fromIndex: number;
715
- /** The item it was moved onto */
716
- toItem?: TItem;
717
- /** The list index of the item it was moved onto */
718
- toIndex: number;
719
- /** Boolean representing an incoming external item dragged into the DraxList */
720
- isExternalDrag: boolean;
721
- }
722
- /** Render function for content of a DraxList item's DraxView */
723
- export interface DraxListRenderItemContent<TItem> {
724
- (info: ListRenderItemInfo<TItem>, props: DraxRenderContentProps): ReactNode;
725
- }
726
- /** Render function for content of a DraxList item's hovering copy */
727
- export interface DraxListRenderItemHoverContent<TItem> {
728
- (info: ListRenderItemInfo<TItem>, props: DraxRenderHoverContentProps): ReactNode;
729
- }
730
- /** Callback handler for when a list item is moved within a DraxList, reordering the list */
731
- export interface DraxListOnItemReorder<TItem> {
732
- (eventData: DraxListOnItemReorderEventData<TItem>): void;
733
- }
734
- /** Props for a DraxList; extends standard FlatList props */
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;
749
- /** Callback handler for when a list item reorder drag action begins */
750
- onItemDragStart?: (eventData: DraxListOnItemDragStartEventData<TItem>) => void;
751
- /** Callback handler for when a list item position (index) changes during a reorder drag */
752
- onItemDragPositionChange?: (eventData: DraxListOnItemDragPositionChangeEventData<TItem>) => void;
753
- /** Callback handler for when a list item reorder drag action ends */
754
- onItemDragEnd?: (eventData: DraxListOnItemDragEndEventData<TItem>) => void;
755
- /** Callback handler for when a list item is moved within the list, reordering the list */
756
- onItemReorder?: DraxListOnItemReorder<TItem>;
757
- /** Can the list be reordered by dragging items? Defaults to true if onItemReorder is set. */
758
- reorderable?: boolean;
759
- /** If true, lock item drags to the list's main axis */
760
- lockItemDragsToMainAxis?: boolean;
761
- /** Time in milliseconds view needs to be pressed before drag starts */
762
- longPressDelay?: number;
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 {};