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
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.useContent = void 0;
27
+ const react_1 = __importStar(require("react"));
28
+ const react_native_1 = require("react-native");
29
+ const react_native_reanimated_1 = require("react-native-reanimated");
30
+ const DraxSubprovider_1 = require("../DraxSubprovider");
31
+ const math_1 = require("../math");
32
+ const transform_1 = require("../transform");
33
+ const types_1 = require("../types");
34
+ const useDraxContext_1 = require("./useDraxContext");
35
+ const useStatus_1 = require("./useStatus");
36
+ const useContent = ({ draxViewProps: { id, style, dragInactiveStyle, draggingStyle, draggingWithReceiverStyle, draggingWithoutReceiverStyle, dragReleasedStyle, otherDraggingStyle, otherDraggingWithReceiverStyle, otherDraggingWithoutReceiverStyle, receiverInactiveStyle, receivingStyle, children, renderContent, renderHoverContent, isParent, scrollPositionOffset, ...props }, viewRef, }) => {
37
+ const { getTrackingDragged, getTrackingReceiver, getAbsoluteViewData } = (0, useDraxContext_1.useDraxContext)();
38
+ const { dragStatus, receiveStatus, anyDragging, anyReceiving } = (0, useStatus_1.useStatus)({
39
+ id,
40
+ otherDraggingStyle,
41
+ otherDraggingWithReceiverStyle,
42
+ otherDraggingWithoutReceiverStyle,
43
+ ...props,
44
+ });
45
+ const dragged = getTrackingDragged();
46
+ const trackingReleasedDraggedRef = (0, react_1.useRef)({});
47
+ (0, react_1.useEffect)(() => {
48
+ if (dragged && dragged.id === id)
49
+ trackingReleasedDraggedRef.current = dragged;
50
+ }, [dragged, id]);
51
+ const receiver = getTrackingReceiver();
52
+ const draggedData = getAbsoluteViewData(dragged?.id);
53
+ // Get full render props for non-hovering view content.
54
+ const getRenderContentProps = (0, react_1.useCallback)(() => {
55
+ const viewData = getAbsoluteViewData(id);
56
+ const measurements = viewData?.measurements;
57
+ const dimensions = measurements && (0, math_1.extractDimensions)(measurements);
58
+ return {
59
+ viewState: {
60
+ data: viewData,
61
+ dragStatus,
62
+ receiveStatus,
63
+ ...dragged?.tracking,
64
+ releasedDragTracking: trackingReleasedDraggedRef.current?.tracking && {
65
+ ...trackingReleasedDraggedRef.current.tracking,
66
+ },
67
+ receivingDrag: receiveStatus !== types_1.DraxViewReceiveStatus.Receiving || !receiver?.id || !draggedData
68
+ ? undefined
69
+ : {
70
+ id: receiver?.id,
71
+ payload: draggedData?.protocol.dragPayload,
72
+ data: draggedData,
73
+ },
74
+ },
75
+ trackingStatus: { dragging: anyDragging, receiving: anyReceiving },
76
+ children,
77
+ dimensions,
78
+ hover: !viewRef,
79
+ };
80
+ }, [children, dragStatus, receiveStatus, anyDragging, anyReceiving, getTrackingDragged]);
81
+ // Combined style for current render-related state.
82
+ const combinedStyle = (0, react_1.useMemo)(() => {
83
+ // Start with base style.
84
+ const styles = [style];
85
+ /** Hover style */
86
+ if (!viewRef) {
87
+ const viewData = getAbsoluteViewData(id);
88
+ const measurements = viewData?.measurements;
89
+ const dimensions = measurements && (0, math_1.extractDimensions)(measurements);
90
+ const combinedHoverStyle = dimensions &&
91
+ (0, transform_1.getCombinedHoverStyle)({ dragStatus, anyReceiving, dimensions }, {
92
+ id,
93
+ style,
94
+ dragInactiveStyle,
95
+ draggingStyle,
96
+ draggingWithReceiverStyle,
97
+ draggingWithoutReceiverStyle,
98
+ dragReleasedStyle,
99
+ otherDraggingStyle,
100
+ otherDraggingWithReceiverStyle,
101
+ otherDraggingWithoutReceiverStyle,
102
+ receiverInactiveStyle,
103
+ receivingStyle,
104
+ children,
105
+ renderContent,
106
+ renderHoverContent,
107
+ isParent,
108
+ ...props,
109
+ });
110
+ styles.push(combinedHoverStyle);
111
+ }
112
+ else {
113
+ // Apply style overrides for drag state.
114
+ if (dragStatus === types_1.DraxViewDragStatus.Dragging) {
115
+ styles.push(draggingStyle);
116
+ if (anyReceiving) {
117
+ styles.push(draggingWithReceiverStyle);
118
+ }
119
+ else {
120
+ styles.push(draggingWithoutReceiverStyle);
121
+ }
122
+ }
123
+ else if (dragStatus === types_1.DraxViewDragStatus.Released) {
124
+ styles.push(dragReleasedStyle);
125
+ }
126
+ else {
127
+ styles.push(dragInactiveStyle);
128
+ if (anyDragging) {
129
+ styles.push(otherDraggingStyle);
130
+ if (anyReceiving) {
131
+ styles.push(otherDraggingWithReceiverStyle);
132
+ }
133
+ else {
134
+ styles.push(otherDraggingWithoutReceiverStyle);
135
+ }
136
+ }
137
+ }
138
+ // Apply style overrides for receiving state.
139
+ if (receiveStatus === types_1.DraxViewReceiveStatus.Receiving) {
140
+ styles.push(receivingStyle);
141
+ }
142
+ else {
143
+ styles.push(receiverInactiveStyle);
144
+ }
145
+ }
146
+ return styles;
147
+ }, [
148
+ style,
149
+ dragStatus,
150
+ receiveStatus,
151
+ draggingStyle,
152
+ anyReceiving,
153
+ draggingWithReceiverStyle,
154
+ draggingWithoutReceiverStyle,
155
+ dragReleasedStyle,
156
+ dragInactiveStyle,
157
+ anyDragging,
158
+ otherDraggingStyle,
159
+ otherDraggingWithReceiverStyle,
160
+ otherDraggingWithoutReceiverStyle,
161
+ receivingStyle,
162
+ receiverInactiveStyle,
163
+ viewRef,
164
+ ]);
165
+ const hoverFlattenedCombinedStyle = !viewRef && (0, transform_1.flattenStylesWithoutLayout)(combinedStyle);
166
+ const flattenedCombinedStyle = viewRef && react_native_1.StyleSheet.flatten(combinedStyle);
167
+ /** Note: Passing Flattened reanimated styles to Reanimated.View is not a good idea... */
168
+ const _combinedStyle = viewRef ? combinedStyle : hoverFlattenedCombinedStyle;
169
+ const animatedHoverStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => {
170
+ if (viewRef) {
171
+ return {};
172
+ }
173
+ return {
174
+ opacity: props.hoverPosition.value.x === 0 && props.hoverPosition.value.y === 0 ? 0 : 1, //prevent flash when release animation finishes.
175
+ transform: [
176
+ {
177
+ translateX: props.hoverPosition?.value?.x -
178
+ ((props.scrollPosition?.value?.x || 0) - (scrollPositionOffset?.x || 0)),
179
+ },
180
+ {
181
+ translateY: props.hoverPosition?.value?.y -
182
+ ((props.scrollPosition?.value?.y || 0) - (scrollPositionOffset?.y || 0)),
183
+ },
184
+ ...(flattenedCombinedStyle?.transform || []),
185
+ ],
186
+ };
187
+ });
188
+ // The rendered React children of this view.
189
+ const renderedChildren = (0, react_1.useMemo)(() => {
190
+ let content;
191
+ const renderDraxContent = !viewRef ? renderHoverContent || renderContent : renderContent;
192
+ if (renderDraxContent) {
193
+ const renderContentProps = getRenderContentProps();
194
+ content = renderDraxContent(renderContentProps);
195
+ }
196
+ else {
197
+ content = children;
198
+ }
199
+ if (isParent && viewRef) {
200
+ // This is a Drax parent, so wrap children in subprovider.
201
+ content = react_1.default.createElement(DraxSubprovider_1.DraxSubprovider, { parent: { id, viewRef } }, content);
202
+ }
203
+ return content;
204
+ }, [renderContent, getRenderContentProps, children, isParent, id, viewRef, renderHoverContent]);
205
+ return {
206
+ renderedChildren,
207
+ combinedStyle: _combinedStyle,
208
+ animatedHoverStyle,
209
+ dragStatus,
210
+ };
211
+ };
212
+ exports.useContent = useContent;
@@ -0,0 +1,5 @@
1
+ import { SharedValue } from 'react-native-reanimated';
2
+ import { DraxViewProps, Position } from '../types';
3
+ export declare const useDraxProtocol: (props: DraxViewProps & {
4
+ id: string;
5
+ }, hoverPosition: SharedValue<Position>) => (scrollPositionValue?: Position) => void;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDraxProtocol = void 0;
4
+ const react_1 = require("react");
5
+ const react_native_reanimated_1 = require("react-native-reanimated");
6
+ const useDraxContext_1 = require("./useDraxContext");
7
+ const useDraxProtocol = (props, hoverPosition) => {
8
+ // Connect with Drax.
9
+ const { updateViewProtocol } = (0, useDraxContext_1.useDraxContext)();
10
+ const _scrollPosition = (0, react_native_reanimated_1.useSharedValue)({ x: 0, y: 0 });
11
+ const scrollPosition = props.scrollPosition || _scrollPosition;
12
+ const updateViewProtocolCallback = (0, react_1.useCallback)((scrollPositionValue) => {
13
+ const dragPayload = props.dragPayload ?? props.payload;
14
+ const receiverPayload = props.receiverPayload ?? props.payload;
15
+ // Pass the event up to the Drax context.
16
+ updateViewProtocol({
17
+ id: props.id,
18
+ protocol: {
19
+ ...props,
20
+ hoverPosition,
21
+ dragPayload,
22
+ receiverPayload,
23
+ scrollPositionValue,
24
+ },
25
+ });
26
+ }, [updateViewProtocol, props, hoverPosition]);
27
+ (0, react_native_reanimated_1.useAnimatedReaction)(() => scrollPosition?.value, scrollPositionValue => {
28
+ (0, react_native_reanimated_1.runOnJS)(updateViewProtocolCallback)(scrollPositionValue);
29
+ });
30
+ return updateViewProtocolCallback;
31
+ };
32
+ exports.useDraxProtocol = useDraxProtocol;
@@ -1,14 +1,8 @@
1
- /// <reference types="react" />
2
- import { Animated } from 'react-native';
3
- import { RegisterViewPayload, UnregisterViewPayload, UpdateViewProtocolPayload, UpdateViewMeasurementsPayload, DraxViewData, DraxViewMeasurements, Position, DraxFoundAbsoluteViewEntry, StartDragPayload, DraxAbsoluteViewEntry, DraxAbsoluteViewData, DraxStateDispatch, DraxSnapbackTarget } from '../types';
4
- interface GetDragPositionDataParams {
5
- parentPosition: Position;
6
- draggedMeasurements: DraxViewMeasurements;
7
- lockXPosition?: boolean;
8
- lockYPosition?: boolean;
9
- }
1
+ import { DraxAbsoluteViewData, DraxAbsoluteViewEntry, DraxFoundAbsoluteViewEntry, DraxProtocol, DraxRegistry, DraxSnapbackTarget, DraxStateDispatch, DraxViewData, DraxViewMeasurements, GetDragPositionDataParams, Position, RegisterViewPayload, StartDragPayload, UnregisterViewPayload, UpdateViewMeasurementsPayload, UpdateViewProtocolPayload } from '../types';
10
2
  /** Create a Drax registry and wire up all of the methods. */
11
3
  export declare const useDraxRegistry: (stateDispatch: DraxStateDispatch) => {
4
+ registryRef: import("react").MutableRefObject<DraxRegistry>;
5
+ getReleaseViews: () => string[];
12
6
  getViewData: (id: string | undefined) => DraxViewData | undefined;
13
7
  getAbsoluteViewData: (id: string | undefined) => DraxAbsoluteViewData | undefined;
14
8
  getTrackingDragged: () => {
@@ -41,19 +35,19 @@ export declare const useDraxRegistry: (stateDispatch: DraxStateDispatch) => {
41
35
  monitors: DraxFoundAbsoluteViewEntry[];
42
36
  receiver: DraxFoundAbsoluteViewEntry | undefined;
43
37
  };
44
- getHoverItems: () => {
45
- internalRenderHoverView: (props: import("../types").DraxInternalRenderHoverViewProps) => import("react").ReactNode;
46
- key: string;
38
+ getHoverItems: (viewIds: string[]) => ({
39
+ scrollPosition: import("react-native-reanimated").SharedValue<Position> | undefined;
40
+ scrollPositionOffset: Position | undefined;
41
+ parentId?: string;
42
+ protocol: DraxProtocol;
43
+ measurements?: DraxViewMeasurements;
44
+ hoverMeasurements?: DraxViewMeasurements;
47
45
  id: string;
48
- hoverPosition: Animated.ValueXY;
49
- dimensions: {
50
- width: number;
51
- height: number;
52
- };
53
- }[];
46
+ } | undefined)[];
54
47
  registerView: (payload: RegisterViewPayload) => void;
55
48
  updateViewProtocol: (payload: UpdateViewProtocolPayload) => void;
56
49
  updateViewMeasurements: (payload: UpdateViewMeasurementsPayload) => void;
50
+ updateHoverViewMeasurements: (payload: UpdateViewMeasurementsPayload) => void;
57
51
  resetReceiver: () => void;
58
52
  resetDrag: (snapbackTarget?: DraxSnapbackTarget) => void;
59
53
  startDrag: (payload: StartDragPayload) => {
@@ -67,11 +61,18 @@ export declare const useDraxRegistry: (stateDispatch: DraxStateDispatch) => {
67
61
  y: number;
68
62
  };
69
63
  dragOffset: Position;
70
- hoverPosition: Animated.ValueXY;
64
+ hoverPosition: import("react-native-reanimated").SharedValue<Position> | {
65
+ value: {
66
+ x: number;
67
+ y: number;
68
+ };
69
+ addListener(): void;
70
+ removeListener(): void;
71
+ modify(): void;
72
+ };
71
73
  };
72
74
  updateDragPosition: (dragAbsolutePosition: Position) => void;
73
75
  updateReceiver: (receiver: DraxFoundAbsoluteViewEntry, dragged: DraxAbsoluteViewEntry) => import("../types").DraxTrackingReceiver | undefined;
74
76
  setMonitorIds: (monitorIds: string[]) => void;
75
77
  unregisterView: (payload: UnregisterViewPayload) => void;
76
78
  };
77
- export {};