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
@@ -2,5 +2,5 @@ import React from 'react';
2
2
  import { ScrollView } from 'react-native';
3
3
  import { DraxScrollViewProps } from './types';
4
4
  export declare const DraxScrollView: React.ForwardRefExoticComponent<DraxScrollViewProps & {
5
- children?: React.ReactNode;
5
+ children?: React.ReactNode | undefined;
6
6
  } & React.RefAttributes<ScrollView>>;
@@ -22,36 +22,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.DraxScrollView = void 0;
27
30
  const react_1 = __importStar(require("react"));
28
- const react_native_1 = require("react-native");
29
- const DraxView_1 = require("./DraxView");
31
+ const react_native_reanimated_1 = __importDefault(require("react-native-reanimated"));
30
32
  const DraxSubprovider_1 = require("./DraxSubprovider");
31
- const hooks_1 = require("./hooks");
32
- const types_1 = require("./types");
33
+ const DraxView_1 = require("./DraxView");
34
+ const useDraxScrollHandler_1 = require("./hooks/useDraxScrollHandler");
33
35
  const params_1 = require("./params");
36
+ const types_1 = require("./types");
34
37
  const DraxScrollViewUnforwarded = (props, forwardedRef) => {
35
- const { children, style, onScroll: onScrollProp, onContentSizeChange: onContentSizeChangeProp, scrollEventThrottle = params_1.defaultScrollEventThrottle, autoScrollIntervalLength = params_1.defaultAutoScrollIntervalLength, autoScrollJumpRatio = params_1.defaultAutoScrollJumpRatio, autoScrollBackThreshold = params_1.defaultAutoScrollBackThreshold, autoScrollForwardThreshold = params_1.defaultAutoScrollForwardThreshold, id: idProp, ...scrollViewProps } = props;
36
- // The unique identifer for this view.
37
- const id = (0, hooks_1.useDraxId)(idProp);
38
- // Scrollable view, used for scrolling.
39
- const scrollRef = (0, react_1.useRef)(null);
40
- // ScrollView node handle, used for measuring children.
41
- const nodeHandleRef = (0, react_1.useRef)(null);
42
- // Container view measurements, for scrolling by percentage.
43
- const containerMeasurementsRef = (0, react_1.useRef)(undefined);
44
- // Content size, for scrolling by percentage.
45
- const contentSizeRef = (0, react_1.useRef)(undefined);
46
- // Scroll position, for Drax bounds checking and auto-scrolling.
47
- const scrollPositionRef = (0, react_1.useRef)({ x: 0, y: 0 });
38
+ const { children, style, onContentSizeChange: onContentSizeChangeProp, scrollEventThrottle = params_1.defaultScrollEventThrottle, autoScrollIntervalLength = params_1.defaultAutoScrollIntervalLength, autoScrollJumpRatio = params_1.defaultAutoScrollJumpRatio, autoScrollBackThreshold = params_1.defaultAutoScrollBackThreshold, autoScrollForwardThreshold = params_1.defaultAutoScrollForwardThreshold, id: idProp, ...scrollViewProps } = props;
48
39
  // Auto-scroll state.
49
40
  const autoScrollStateRef = (0, react_1.useRef)({
50
41
  x: types_1.AutoScrollDirection.None,
51
42
  y: types_1.AutoScrollDirection.None,
52
43
  });
53
- // Auto-scroll interval.
54
- const autoScrollIntervalRef = (0, react_1.useRef)(undefined);
55
44
  // Handle auto-scrolling on interval.
56
45
  const doScroll = (0, react_1.useCallback)(() => {
57
46
  const scroll = scrollRef.current;
@@ -60,7 +49,6 @@ const DraxScrollViewUnforwarded = (props, forwardedRef) => {
60
49
  if (!scroll || !containerMeasurements || !contentSize) {
61
50
  return;
62
51
  }
63
- const scrollPosition = scrollPositionRef.current;
64
52
  const autoScrollState = autoScrollStateRef.current;
65
53
  const jump = {
66
54
  x: containerMeasurements.width * autoScrollJumpRatio,
@@ -70,56 +58,41 @@ const DraxScrollViewUnforwarded = (props, forwardedRef) => {
70
58
  let yNew;
71
59
  if (autoScrollState.x === types_1.AutoScrollDirection.Forward) {
72
60
  const xMax = contentSize.x - containerMeasurements.width;
73
- if (scrollPosition.x < xMax) {
74
- xNew = Math.min(scrollPosition.x + jump.x, xMax);
61
+ if (scrollPosition.value.x < xMax) {
62
+ xNew = Math.min(scrollPosition.value.x + jump.x, xMax);
75
63
  }
76
64
  }
77
65
  else if (autoScrollState.x === types_1.AutoScrollDirection.Back) {
78
- if (scrollPosition.x > 0) {
79
- xNew = Math.max(scrollPosition.x - jump.x, 0);
66
+ if (scrollPosition.value.x > 0) {
67
+ xNew = Math.max(scrollPosition.value.x - jump.x, 0);
80
68
  }
81
69
  }
82
70
  if (autoScrollState.y === types_1.AutoScrollDirection.Forward) {
83
71
  const yMax = contentSize.y - containerMeasurements.height;
84
- if (scrollPosition.y < yMax) {
85
- yNew = Math.min(scrollPosition.y + jump.y, yMax);
72
+ if (scrollPosition.value.y < yMax) {
73
+ yNew = Math.min(scrollPosition.value.y + jump.y, yMax);
86
74
  }
87
75
  }
88
76
  else if (autoScrollState.y === types_1.AutoScrollDirection.Back) {
89
- if (scrollPosition.y > 0) {
90
- yNew = Math.max(scrollPosition.y - jump.y, 0);
77
+ if (scrollPosition.value.y > 0) {
78
+ yNew = Math.max(scrollPosition.value.y - jump.y, 0);
91
79
  }
92
80
  }
93
81
  if (xNew !== undefined || yNew !== undefined) {
94
82
  scroll.scrollTo({
95
- x: xNew ?? scrollPosition.x,
96
- y: yNew ?? scrollPosition.y,
83
+ x: xNew ?? scrollPosition.value.x,
84
+ y: yNew ?? scrollPosition.value.y,
97
85
  });
98
86
  scroll.flashScrollIndicators(); // ScrollView typing is missing this method
99
87
  }
100
88
  }, [autoScrollJumpRatio]);
101
- // Start the auto-scrolling interval.
102
- const startScroll = (0, react_1.useCallback)(() => {
103
- if (autoScrollIntervalRef.current) {
104
- return;
105
- }
106
- doScroll();
107
- autoScrollIntervalRef.current = setInterval(doScroll, autoScrollIntervalLength);
108
- }, [doScroll, autoScrollIntervalLength]);
109
- // Stop the auto-scrolling interval.
110
- const stopScroll = (0, react_1.useCallback)(() => {
111
- if (autoScrollIntervalRef.current) {
112
- clearInterval(autoScrollIntervalRef.current);
113
- autoScrollIntervalRef.current = undefined;
114
- }
115
- }, []);
116
- // If startScroll changes, refresh our interval.
117
- (0, react_1.useEffect)(() => {
118
- if (autoScrollIntervalRef.current) {
119
- stopScroll();
120
- startScroll();
121
- }
122
- }, [stopScroll, startScroll]);
89
+ const { id, containerMeasurementsRef, contentSizeRef, onContentSizeChange, onMeasureContainer, onScroll, scrollRef, scrollPosition, setScrollRefs, startScroll, stopScroll, } = (0, useDraxScrollHandler_1.useDraxScrollHandler)({
90
+ idProp,
91
+ onContentSizeChangeProp,
92
+ onScrollProp: props?.onScroll,
93
+ forwardedRef,
94
+ doScroll,
95
+ });
123
96
  // Clear auto-scroll direction and stop the auto-scrolling interval.
124
97
  const resetScroll = (0, react_1.useCallback)(() => {
125
98
  const autoScrollState = autoScrollStateRef.current;
@@ -127,10 +100,6 @@ const DraxScrollViewUnforwarded = (props, forwardedRef) => {
127
100
  autoScrollState.y = types_1.AutoScrollDirection.None;
128
101
  stopScroll();
129
102
  }, [stopScroll]);
130
- // Track the size of the container view.
131
- const onMeasureContainer = (0, react_1.useCallback)((measurements) => {
132
- containerMeasurementsRef.current = measurements;
133
- }, []);
134
103
  // Monitor drag-over events to react with auto-scrolling.
135
104
  const onMonitorDragOver = (0, react_1.useCallback)((event) => {
136
105
  const { monitorOffsetRatio } = event;
@@ -159,39 +128,9 @@ const DraxScrollViewUnforwarded = (props, forwardedRef) => {
159
128
  else {
160
129
  startScroll();
161
130
  }
162
- }, [
163
- stopScroll,
164
- startScroll,
165
- autoScrollBackThreshold,
166
- autoScrollForwardThreshold,
167
- ]);
168
- // Set the ScrollView and node handle refs.
169
- const setScrollViewRefs = (0, react_1.useCallback)((ref) => {
170
- scrollRef.current = ref;
171
- nodeHandleRef.current = ref && (0, react_native_1.findNodeHandle)(ref);
172
- if (forwardedRef) {
173
- if (typeof forwardedRef === 'function') {
174
- forwardedRef(ref);
175
- }
176
- else {
177
- // eslint-disable-next-line no-param-reassign
178
- forwardedRef.current = ref;
179
- }
180
- }
181
- }, [forwardedRef]);
182
- // Track content size.
183
- const onContentSizeChange = (0, react_1.useCallback)((width, height) => {
184
- contentSizeRef.current = { x: width, y: height };
185
- return onContentSizeChangeProp?.(width, height);
186
- }, [onContentSizeChangeProp]);
187
- // Update tracked scroll position when list is scrolled.
188
- const onScroll = (0, react_1.useCallback)((event) => {
189
- const { nativeEvent: { contentOffset } } = event;
190
- scrollPositionRef.current = { ...contentOffset };
191
- return onScrollProp?.(event);
192
- }, [onScrollProp]);
193
- return id ? (react_1.default.createElement(DraxView_1.DraxView, { id: id, style: style, scrollPositionRef: scrollPositionRef, onMeasure: onMeasureContainer, onMonitorDragOver: onMonitorDragOver, onMonitorDragExit: resetScroll, onMonitorDragEnd: resetScroll, onMonitorDragDrop: resetScroll },
194
- react_1.default.createElement(DraxSubprovider_1.DraxSubprovider, { parent: { id, nodeHandleRef } },
195
- react_1.default.createElement(react_native_1.ScrollView, { ...scrollViewProps, ref: setScrollViewRefs, onContentSizeChange: onContentSizeChange, onScroll: onScroll, scrollEventThrottle: scrollEventThrottle }, children)))) : null;
131
+ }, [stopScroll, startScroll, autoScrollBackThreshold, autoScrollForwardThreshold]);
132
+ return id ? (react_1.default.createElement(DraxView_1.DraxView, { id: id, style: style, scrollPosition: scrollPosition, onMeasure: onMeasureContainer, onMonitorDragOver: onMonitorDragOver, onMonitorDragExit: resetScroll, onMonitorDragEnd: resetScroll, onMonitorDragDrop: resetScroll },
133
+ react_1.default.createElement(DraxSubprovider_1.DraxSubprovider, { parent: { id, viewRef: scrollRef } },
134
+ react_1.default.createElement(react_native_reanimated_1.default.ScrollView, { ...scrollViewProps, ref: setScrollRefs, onContentSizeChange: onContentSizeChange, scrollEventThrottle: scrollEventThrottle, onScroll: onScroll }, children)))) : null;
196
135
  };
197
136
  exports.DraxScrollView = (0, react_1.forwardRef)(DraxScrollViewUnforwarded);
@@ -1,3 +1,3 @@
1
- import { FunctionComponent } from 'react';
1
+ import React, { PropsWithChildren } from 'react';
2
2
  import { DraxSubproviderProps } from './types';
3
- export declare const DraxSubprovider: FunctionComponent<DraxSubproviderProps>;
3
+ export declare const DraxSubprovider: ({ parent, children }: PropsWithChildren<DraxSubproviderProps>) => React.JSX.Element;
@@ -13,6 +13,6 @@ const DraxSubprovider = ({ parent, children }) => {
13
13
  ...contextValue,
14
14
  parent,
15
15
  };
16
- return (react_1.default.createElement(DraxContext_1.DraxContext.Provider, { value: subContextValue }, children));
16
+ return react_1.default.createElement(DraxContext_1.DraxContext.Provider, { value: subContextValue }, children);
17
17
  };
18
18
  exports.DraxSubprovider = DraxSubprovider;
@@ -1,3 +1,8 @@
1
- import { PropsWithChildren } from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { DraxViewProps } from './types';
3
- export declare const DraxView: ({ onDragStart, onDrag, onDragEnter, onDragOver, onDragExit, onDragEnd, onDragDrop, onSnapbackEnd, onReceiveDragEnter, onReceiveDragOver, onReceiveDragExit, onReceiveDragDrop, onMonitorDragStart, onMonitorDragEnter, onMonitorDragOver, onMonitorDragExit, onMonitorDragEnd, onMonitorDragDrop, animateSnapback, snapbackDelay, snapbackDuration, snapbackAnimator, payload, dragPayload, receiverPayload, style, dragInactiveStyle, draggingStyle, draggingWithReceiverStyle, draggingWithoutReceiverStyle, dragReleasedStyle, hoverStyle, hoverDraggingStyle, hoverDraggingWithReceiverStyle, hoverDraggingWithoutReceiverStyle, hoverDragReleasedStyle, receiverInactiveStyle, receivingStyle, otherDraggingStyle, otherDraggingWithReceiverStyle, otherDraggingWithoutReceiverStyle, renderContent, renderHoverContent, registration, onMeasure, scrollPositionRef, lockDragXPosition, lockDragYPosition, children, noHover, isParent, longPressDelay, id: idProp, parent: parentProp, draggable: draggableProp, receptive: receptiveProp, monitoring: monitoringProp, ...props }: PropsWithChildren<DraxViewProps>) => JSX.Element;
3
+ export declare const DraxView: React.MemoExoticComponent<(props: DraxViewProps) => ReactNode>;
4
+ type IReanimatedView = DraxViewProps & {
5
+ id: string;
6
+ };
7
+ export declare const DraxReanimatedView: React.MemoExoticComponent<(props: IReanimatedView) => ReactNode>;
8
+ export {};