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,25 @@
1
+ import { ForwardedRef } from 'react';
2
+ import { FlatList, NativeScrollEvent, NativeSyntheticEvent, ScrollView } from 'react-native';
3
+ import { DraxListProps, DraxViewMeasurements, Position } from '../types';
4
+ type DraxScrollHandlerArgs<T> = {
5
+ idProp?: string;
6
+ onContentSizeChangeProp?: DraxListProps<T>['onContentSizeChange'];
7
+ onScrollProp: DraxListProps<any>['onScroll'];
8
+ forwardedRef?: ForwardedRef<any>;
9
+ doScroll: () => void;
10
+ };
11
+ type ScrollableComponents = FlatList<any> | ScrollView;
12
+ export declare const useDraxScrollHandler: <T extends ScrollableComponents>({ idProp, onContentSizeChangeProp, onScrollProp, forwardedRef, doScroll, }: DraxScrollHandlerArgs<T>) => {
13
+ id: string;
14
+ containerMeasurementsRef: import("react").MutableRefObject<DraxViewMeasurements | undefined>;
15
+ contentSizeRef: import("react").MutableRefObject<Position | undefined>;
16
+ onContentSizeChange: (width: number, height: number) => void | undefined;
17
+ onMeasureContainer: (measurements: DraxViewMeasurements | undefined) => void;
18
+ onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
19
+ scrollRef: import("react-native-reanimated").AnimatedRef<T>;
20
+ scrollPosition: import("react-native-reanimated").SharedValue<Position>;
21
+ setScrollRefs: (ref: T | null) => void;
22
+ startScroll: () => void;
23
+ stopScroll: () => void;
24
+ };
25
+ export {};
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDraxScrollHandler = void 0;
4
+ const react_1 = require("react");
5
+ const react_native_reanimated_1 = require("react-native-reanimated");
6
+ const params_1 = require("../params");
7
+ const useDraxId_1 = require("./useDraxId");
8
+ const useDraxScrollHandler = ({ idProp, onContentSizeChangeProp, onScrollProp, forwardedRef, doScroll, }) => {
9
+ // Scrollable view, used for scrolling.
10
+ const scrollRef = (0, react_native_reanimated_1.useAnimatedRef)();
11
+ // The unique identifer for this view.
12
+ const id = (0, useDraxId_1.useDraxId)(idProp);
13
+ // Container view measurements, for scrolling by percentage.
14
+ const containerMeasurementsRef = (0, react_1.useRef)(undefined);
15
+ // Auto-scrolling interval.
16
+ const scrollIntervalRef = (0, react_1.useRef)(undefined);
17
+ // Content size, for scrolling by percentage.
18
+ const contentSizeRef = (0, react_1.useRef)(undefined);
19
+ const scrollPosition = (0, react_native_reanimated_1.useSharedValue)(params_1.INITIAL_REANIMATED_POSITION.value);
20
+ // Track the size of the container view.
21
+ const onMeasureContainer = (0, react_1.useCallback)((measurements) => {
22
+ containerMeasurementsRef.current = measurements;
23
+ }, []);
24
+ // Track content size.
25
+ const onContentSizeChange = (0, react_1.useCallback)((width, height) => {
26
+ contentSizeRef.current = { x: width, y: height };
27
+ return onContentSizeChangeProp?.(width, height);
28
+ }, [onContentSizeChangeProp]);
29
+ // Update tracked scroll position when list is scrolled.
30
+ const onScroll = (0, react_1.useCallback)((event) => {
31
+ onScrollProp?.(event);
32
+ (0, react_native_reanimated_1.runOnUI)((_event) => {
33
+ scrollPosition.value = {
34
+ x: _event.contentOffset.x,
35
+ y: _event.contentOffset.y,
36
+ };
37
+ })(event.nativeEvent);
38
+ }, [onScrollProp]);
39
+ // Set the ScrollView/FlatList refs.
40
+ const setScrollRefs = (0, react_1.useCallback)((ref) => {
41
+ if (ref) {
42
+ scrollRef(ref);
43
+ if (forwardedRef) {
44
+ if (typeof forwardedRef === 'function') {
45
+ forwardedRef(ref);
46
+ }
47
+ else {
48
+ forwardedRef.current = ref;
49
+ }
50
+ }
51
+ }
52
+ }, [forwardedRef, scrollRef]);
53
+ // Start the auto-scrolling interval.
54
+ const startScroll = (0, react_1.useCallback)(() => {
55
+ if (scrollIntervalRef.current) {
56
+ return;
57
+ }
58
+ doScroll();
59
+ scrollIntervalRef.current = setInterval(doScroll, 250);
60
+ }, [doScroll]);
61
+ // Stop the auto-scrolling interval.
62
+ const stopScroll = (0, react_1.useCallback)(() => {
63
+ if (scrollIntervalRef.current) {
64
+ clearInterval(scrollIntervalRef.current);
65
+ scrollIntervalRef.current = undefined;
66
+ }
67
+ }, []);
68
+ // If startScroll changes, refresh our interval.
69
+ (0, react_1.useEffect)(() => {
70
+ if (scrollIntervalRef.current) {
71
+ stopScroll();
72
+ startScroll();
73
+ }
74
+ }, [stopScroll, startScroll]);
75
+ return {
76
+ id,
77
+ containerMeasurementsRef,
78
+ contentSizeRef,
79
+ onContentSizeChange,
80
+ onMeasureContainer,
81
+ onScroll,
82
+ scrollRef,
83
+ scrollPosition,
84
+ setScrollRefs,
85
+ startScroll,
86
+ stopScroll,
87
+ };
88
+ };
89
+ exports.useDraxScrollHandler = useDraxScrollHandler;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { DraxViewState, DraxStateActionCreators, CreateViewStatePayload, UpdateViewStatePayload, DeleteViewStatePayload, UpdateTrackingStatusPayload } from '../types';
3
2
  /** Collection of Drax action creators */
4
3
  export declare const actions: DraxStateActionCreators;
@@ -6,5 +5,6 @@ export declare const actions: DraxStateActionCreators;
6
5
  export declare const useDraxState: () => {
7
6
  getViewState: (id: string | undefined) => DraxViewState | undefined;
8
7
  getTrackingStatus: () => import("../types").DraxTrackingStatus;
8
+ getAllViewIds: () => string[];
9
9
  dispatch: import("react").Dispatch<import("typesafe-actions").PayloadAction<"createViewState", CreateViewStatePayload> | import("typesafe-actions").PayloadAction<"updateViewState", UpdateViewStatePayload> | import("typesafe-actions").PayloadAction<"deleteViewState", DeleteViewStatePayload> | import("typesafe-actions").PayloadAction<"updateTrackingStatus", UpdateTrackingStatusPayload>>;
10
10
  };
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useDraxState = exports.actions = void 0;
7
+ const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
7
8
  const react_1 = require("react");
8
9
  const typesafe_actions_1 = require("typesafe-actions");
9
- const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
10
10
  const types_1 = require("../types");
11
11
  /** Create the initial empty view state data for a newly registered view. */
12
12
  const createInitialViewState = () => ({
@@ -30,9 +30,12 @@ const createInitialState = () => ({
30
30
  },
31
31
  });
32
32
  /** Selector for a view state by view id. */
33
- const selectViewState = (state, id) => (id === undefined ? undefined : state.viewStateById[id]);
33
+ const selectViewState = (state, id) => id === undefined ? undefined : state.viewStateById[id];
34
34
  /** Selector for tracking status. */
35
35
  const selectTrackingStatus = (state) => state.trackingStatus;
36
+ const selectAllViewIds = (state) => {
37
+ return Object.keys(state.viewStateById);
38
+ };
36
39
  /** Collection of Drax action creators */
37
40
  exports.actions = {
38
41
  createViewState: (0, typesafe_actions_1.createAction)('createViewState')(),
@@ -110,15 +113,15 @@ const useDraxState = () => {
110
113
  const getViewState = (0, react_1.useCallback)((id) => selectViewState(state, id), [state]);
111
114
  /** Get the current tracking status. */
112
115
  const getTrackingStatus = (0, react_1.useCallback)(() => selectTrackingStatus(state), [state]);
116
+ /** Get the current tracking status. */
117
+ const getAllViewIds = (0, react_1.useCallback)(() => selectAllViewIds(state), [state]);
113
118
  /** Create the Drax state object for return, only replacing reference when necessary. */
114
119
  const draxState = (0, react_1.useMemo)(() => ({
115
120
  getViewState,
116
121
  getTrackingStatus,
122
+ getAllViewIds,
117
123
  dispatch,
118
- }), [
119
- getViewState,
120
- getTrackingStatus,
121
- ]);
124
+ }), [getViewState, getTrackingStatus, getAllViewIds]);
122
125
  /*
123
126
  useEffect(() => {
124
127
  console.log(`Rendering drax state ${JSON.stringify(state, null, 2)}`);
@@ -0,0 +1,9 @@
1
+ import Reanimated from 'react-native-reanimated';
2
+ import { DraxViewProps, DraxViewMeasurementHandler } from '../types';
3
+ export declare const useMeasurements: ({ onMeasure, registration, id, parent: parentProp, scrollPosition, ...props }: DraxViewProps & {
4
+ id: string;
5
+ }) => {
6
+ onLayout: () => void;
7
+ viewRef: import("react-native-reanimated").AnimatedRef<Reanimated.View>;
8
+ measureWithHandler: (measurementHandler?: DraxViewMeasurementHandler) => void;
9
+ };
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMeasurements = void 0;
4
+ const react_1 = require("react");
5
+ const react_native_1 = require("react-native");
6
+ const react_native_reanimated_1 = require("react-native-reanimated");
7
+ const useDraxContext_1 = require("./useDraxContext");
8
+ const useMeasurements = ({ onMeasure, registration, id, parent: parentProp, scrollPosition, ...props }) => {
9
+ // The underlying View, for measuring and for subprovider nesting if this is a Drax parent view.
10
+ const viewRef = (0, react_native_reanimated_1.useAnimatedRef)();
11
+ // This view's measurements, for reference.
12
+ const measurementsRef = (0, react_1.useRef)(undefined);
13
+ // Connect with Drax.
14
+ const { updateViewMeasurements, parent: contextParent, registerView, unregisterView, rootViewRef, getAbsoluteViewData, } = (0, useDraxContext_1.useDraxContext)();
15
+ // Identify Drax parent view (if any) from context or prop override.
16
+ const parent = parentProp ?? contextParent;
17
+ const parentId = parent?.id;
18
+ // Identify parent view ref.
19
+ const parentViewRef = parent ? parent.viewRef : rootViewRef;
20
+ // Register and unregister with Drax context when necessary.
21
+ (0, react_1.useEffect)(() => {
22
+ registerView({ id, parentId, scrollPosition });
23
+ // Unregister when we unmount or id changes.
24
+ return () => unregisterView({ id });
25
+ }, [id, parentId, scrollPosition, registerView, unregisterView]);
26
+ // Build a callback which will report our measurements to Drax context,
27
+ // onMeasure, and an optional measurement handler.
28
+ const buildMeasureCallback = (0, react_1.useCallback)((measurementHandler) => (x, y, width, height) => {
29
+ const parentData = getAbsoluteViewData(parent?.id);
30
+ /** @todo Remove workaround for the web */
31
+ const webOffset = react_native_1.Platform.select({
32
+ web: {
33
+ x: parentData?.scrollPosition?.value.x || 0,
34
+ y: parentData?.scrollPosition?.value.y || 0,
35
+ },
36
+ default: {
37
+ x: 0,
38
+ y: 0,
39
+ },
40
+ });
41
+ /*
42
+ * In certain cases (on Android), all of these values can be
43
+ * undefined when the view is not on screen; This should not
44
+ * happen with the measurement functions we're using, but just
45
+ * for the sake of paranoia, we'll check and use undefined
46
+ * for the entire measurements object.
47
+ */
48
+ const measurements = height === undefined
49
+ ? undefined
50
+ : {
51
+ height,
52
+ x: x + webOffset.x,
53
+ y: y + webOffset.y,
54
+ width: width,
55
+ };
56
+ measurementsRef.current = measurements;
57
+ updateViewMeasurements({ id, measurements });
58
+ onMeasure?.(measurements);
59
+ measurementHandler?.(measurements);
60
+ }, [updateViewMeasurements, id, onMeasure]);
61
+ // Callback which will report our measurements to Drax context and onMeasure.
62
+ const updateMeasurements = (0, react_1.useMemo)(() => buildMeasureCallback(), [buildMeasureCallback]);
63
+ // Measure and report our measurements to Drax context, onMeasure, and an
64
+ // optional measurement handler on demand.
65
+ const measureWithHandler = (0, react_1.useCallback)((measurementHandler) => {
66
+ const view = viewRef.current;
67
+ if (view) {
68
+ if (parentViewRef.current) {
69
+ const measureCallback = measurementHandler
70
+ ? buildMeasureCallback(measurementHandler)
71
+ : updateMeasurements;
72
+ // console.log('definitely measuring in reference to something');
73
+ view.measureLayout(
74
+ // @ts-ignore
75
+ parentViewRef.current, measureCallback, () => {
76
+ // console.log('Failed to measure Drax view in relation to parent nodeHandle');
77
+ });
78
+ }
79
+ else {
80
+ // console.log('No parent nodeHandle to measure Drax view in relation to');
81
+ }
82
+ }
83
+ else {
84
+ // console.log('No view to measure');
85
+ }
86
+ }, [viewRef, parentViewRef, buildMeasureCallback, updateMeasurements]);
87
+ // Measure and send our measurements to Drax context and onMeasure, used when this view finishes layout.
88
+ const onLayout = (0, react_1.useCallback)(() => {
89
+ // console.log(`onLayout ${id}`);
90
+ measureWithHandler();
91
+ }, [measureWithHandler]);
92
+ // Establish dimensions/orientation change handler when necessary.
93
+ (0, react_1.useEffect)(() => {
94
+ const handler = ( /* { screen: { width, height } }: { screen: ScaledSize } */) => {
95
+ // console.log(`Dimensions changed to ${width}/${height}`);
96
+ setTimeout(measureWithHandler, 100);
97
+ };
98
+ const listener = react_native_1.Dimensions.addEventListener('change', handler);
99
+ return () => listener.remove();
100
+ }, [measureWithHandler]);
101
+ // Register and unregister externally when necessary.
102
+ (0, react_1.useEffect)(() => {
103
+ if (registration) {
104
+ // Register externally when registration is set.
105
+ registration({
106
+ id,
107
+ measure: measureWithHandler,
108
+ });
109
+ return () => registration(undefined); // Unregister when we unmount or registration changes.
110
+ }
111
+ return undefined;
112
+ }, [id, measureWithHandler, registration]);
113
+ return {
114
+ onLayout,
115
+ viewRef,
116
+ measureWithHandler,
117
+ };
118
+ };
119
+ exports.useMeasurements = useMeasurements;
@@ -0,0 +1,11 @@
1
+ import { SharedValue } from 'react-native-reanimated';
2
+ import { DraxViewDragStatus, DraxViewProps, DraxViewReceiveStatus, Position } from '../types';
3
+ export declare const useStatus: ({ id, otherDraggingStyle, otherDraggingWithReceiverStyle, otherDraggingWithoutReceiverStyle, hoverPosition, }: DraxViewProps & {
4
+ id: string;
5
+ hoverPosition: SharedValue<Position>;
6
+ }) => {
7
+ dragStatus: DraxViewDragStatus;
8
+ receiveStatus: DraxViewReceiveStatus;
9
+ anyReceiving: boolean;
10
+ anyDragging: boolean;
11
+ };
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useStatus = void 0;
4
+ const react_1 = require("react");
5
+ const react_native_reanimated_1 = require("react-native-reanimated");
6
+ const types_1 = require("../types");
7
+ const useDraxContext_1 = require("./useDraxContext");
8
+ const useStatus = ({ id, otherDraggingStyle, otherDraggingWithReceiverStyle, otherDraggingWithoutReceiverStyle, hoverPosition, }) => {
9
+ const [dragStatus, setDragSatatus] = (0, react_1.useState)(types_1.DraxViewDragStatus.Inactive);
10
+ const [receiveStatus, setReceiveStatus] = (0, react_1.useState)(types_1.DraxViewReceiveStatus.Inactive);
11
+ const [anyReceiving, setAnyReceiving] = (0, react_1.useState)(false);
12
+ const [anyDragging, setAnyDragging] = (0, react_1.useState)(false);
13
+ // Connect with Drax.
14
+ const { getTrackingDragged, parentPosition, getReleaseViews } = (0, useDraxContext_1.useDraxContext)();
15
+ const updateState = (0, react_1.useCallback)((position) => {
16
+ const dragged = getTrackingDragged();
17
+ const releaseViews = getReleaseViews();
18
+ if (position.x === 0 && position.y === 0) {
19
+ setDragSatatus(types_1.DraxViewDragStatus.Inactive);
20
+ setAnyReceiving(false);
21
+ }
22
+ else if (releaseViews?.includes(id)) {
23
+ setDragSatatus(types_1.DraxViewDragStatus.Released);
24
+ }
25
+ else if (dragged) {
26
+ if (dragged?.id === id) {
27
+ setDragSatatus(types_1.DraxViewDragStatus.Dragging);
28
+ }
29
+ else {
30
+ setDragSatatus(types_1.DraxViewDragStatus.Inactive);
31
+ }
32
+ if (otherDraggingStyle || otherDraggingWithReceiverStyle || otherDraggingWithoutReceiverStyle) {
33
+ setAnyDragging(true);
34
+ }
35
+ }
36
+ else {
37
+ setAnyDragging(false);
38
+ setDragSatatus(types_1.DraxViewDragStatus.Inactive);
39
+ }
40
+ }, [
41
+ getReleaseViews,
42
+ getTrackingDragged,
43
+ id,
44
+ otherDraggingStyle,
45
+ otherDraggingWithReceiverStyle,
46
+ otherDraggingWithoutReceiverStyle,
47
+ ]);
48
+ (0, react_native_reanimated_1.useAnimatedReaction)(() => hoverPosition.value, position => {
49
+ (0, react_native_reanimated_1.runOnJS)(updateState)(position);
50
+ });
51
+ const updateReceivingState = (0, react_1.useCallback)((position) => {
52
+ const dragged = getTrackingDragged();
53
+ if (position.x === 0 && position.y === 0) {
54
+ const releaseViews = getReleaseViews();
55
+ if (releaseViews?.includes(id) || dragged?.tracking.draggedId === id) {
56
+ setDragSatatus(types_1.DraxViewDragStatus.Released);
57
+ }
58
+ else {
59
+ setReceiveStatus(types_1.DraxViewReceiveStatus.Inactive);
60
+ }
61
+ setAnyReceiving(false);
62
+ }
63
+ else if (dragged) {
64
+ if (dragged?.tracking.receiver) {
65
+ if (dragged?.tracking.receiver?.receiverId === id) {
66
+ setReceiveStatus(types_1.DraxViewReceiveStatus.Receiving);
67
+ }
68
+ else {
69
+ setReceiveStatus(types_1.DraxViewReceiveStatus.Inactive);
70
+ }
71
+ if (otherDraggingWithReceiverStyle) {
72
+ setAnyReceiving(true);
73
+ }
74
+ }
75
+ else {
76
+ setAnyReceiving(false);
77
+ setReceiveStatus(types_1.DraxViewReceiveStatus.Inactive);
78
+ }
79
+ }
80
+ else {
81
+ setReceiveStatus(types_1.DraxViewReceiveStatus.Inactive);
82
+ setAnyReceiving(false);
83
+ }
84
+ }, [getTrackingDragged, id, otherDraggingWithReceiverStyle]);
85
+ (0, react_native_reanimated_1.useAnimatedReaction)(() => parentPosition.value, position => {
86
+ (0, react_native_reanimated_1.runOnJS)(updateReceivingState)(position);
87
+ });
88
+ const status = (0, react_1.useMemo)(() => ({
89
+ dragStatus,
90
+ receiveStatus,
91
+ anyReceiving,
92
+ anyDragging,
93
+ }), [anyDragging, anyReceiving, dragStatus, receiveStatus]);
94
+ return status;
95
+ };
96
+ exports.useStatus = useStatus;
package/build/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from './types';
2
2
  export { DraxContext } from './DraxContext';
3
3
  export { DraxList } from './DraxList';
4
+ export { DraxListItem } from './DraxListItem';
4
5
  export { DraxProvider } from './DraxProvider';
5
6
  export { DraxScrollView } from './DraxScrollView';
6
7
  export { DraxSubprovider } from './DraxSubprovider';
7
8
  export { DraxView } from './DraxView';
9
+ export * from './hooks';
package/build/index.js CHANGED
@@ -14,12 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.DraxView = exports.DraxSubprovider = exports.DraxScrollView = exports.DraxProvider = exports.DraxList = exports.DraxContext = void 0;
17
+ exports.DraxView = exports.DraxSubprovider = exports.DraxScrollView = exports.DraxProvider = exports.DraxListItem = exports.DraxList = exports.DraxContext = void 0;
18
18
  __exportStar(require("./types"), exports);
19
19
  var DraxContext_1 = require("./DraxContext");
20
20
  Object.defineProperty(exports, "DraxContext", { enumerable: true, get: function () { return DraxContext_1.DraxContext; } });
21
21
  var DraxList_1 = require("./DraxList");
22
22
  Object.defineProperty(exports, "DraxList", { enumerable: true, get: function () { return DraxList_1.DraxList; } });
23
+ var DraxListItem_1 = require("./DraxListItem");
24
+ Object.defineProperty(exports, "DraxListItem", { enumerable: true, get: function () { return DraxListItem_1.DraxListItem; } });
23
25
  var DraxProvider_1 = require("./DraxProvider");
24
26
  Object.defineProperty(exports, "DraxProvider", { enumerable: true, get: function () { return DraxProvider_1.DraxProvider; } });
25
27
  var DraxScrollView_1 = require("./DraxScrollView");
@@ -28,3 +30,4 @@ var DraxSubprovider_1 = require("./DraxSubprovider");
28
30
  Object.defineProperty(exports, "DraxSubprovider", { enumerable: true, get: function () { return DraxSubprovider_1.DraxSubprovider; } });
29
31
  var DraxView_1 = require("./DraxView");
30
32
  Object.defineProperty(exports, "DraxView", { enumerable: true, get: function () { return DraxView_1.DraxView; } });
33
+ __exportStar(require("./hooks"), exports);
package/build/math.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DraxViewMeasurements, Position } from './types';
2
2
  export declare const clipMeasurements: (vm: DraxViewMeasurements, cvm: DraxViewMeasurements) => DraxViewMeasurements;
3
- export declare const isPointInside: ({ x, y }: Position, { width, height, x: x0, y: y0, }: DraxViewMeasurements) => boolean;
4
- export declare const getRelativePosition: ({ x, y }: Position, { width, height, x: x0, y: y0, }: DraxViewMeasurements) => {
3
+ export declare const isPointInside: ({ x, y }: Position, { width, height, x: x0, y: y0 }: DraxViewMeasurements) => boolean;
4
+ export declare const getRelativePosition: ({ x, y }: Position, { width, height, x: x0, y: y0 }: DraxViewMeasurements) => {
5
5
  relativePosition: {
6
6
  x: number;
7
7
  y: number;
package/build/math.js CHANGED
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateRandomId = exports.extractDimensions = exports.extractPosition = exports.getRelativePosition = exports.isPointInside = exports.clipMeasurements = void 0;
4
4
  const clipMeasurements = (vm, cvm) => {
5
- let { width, height, x: x0, y: y0, } = vm;
5
+ 'worklet';
6
+ let { width, height, x: x0, y: y0 } = vm;
6
7
  let x1 = x0 + width;
7
8
  let y1 = y0 + height;
8
- const { width: cwidth, height: cheight, x: cx0, y: cy0, } = cvm;
9
+ const { width: cwidth, height: cheight, x: cx0, y: cy0 } = cvm;
9
10
  const cx1 = cx0 + cwidth;
10
11
  const cy1 = cy0 + cheight;
11
12
  if (x0 >= cx1 || x1 <= cx0 || y0 >= cy1 || y1 <= cy0) {
@@ -40,9 +41,9 @@ const clipMeasurements = (vm, cvm) => {
40
41
  };
41
42
  };
42
43
  exports.clipMeasurements = clipMeasurements;
43
- const isPointInside = ({ x, y }, { width, height, x: x0, y: y0, }) => (x >= x0 && y >= y0 && x < x0 + width && y < y0 + height);
44
+ const isPointInside = ({ x, y }, { width, height, x: x0, y: y0 }) => x >= x0 && y >= y0 && x < x0 + width && y < y0 + height;
44
45
  exports.isPointInside = isPointInside;
45
- const getRelativePosition = ({ x, y }, { width, height, x: x0, y: y0, }) => {
46
+ const getRelativePosition = ({ x, y }, { width, height, x: x0, y: y0 }) => {
46
47
  const rx = x - x0;
47
48
  const ry = y - y0;
48
49
  return {
@@ -53,12 +54,15 @@ const getRelativePosition = ({ x, y }, { width, height, x: x0, y: y0, }) => {
53
54
  exports.getRelativePosition = getRelativePosition;
54
55
  const extractPosition = ({ x, y }) => ({ x, y });
55
56
  exports.extractPosition = extractPosition;
56
- const extractDimensions = ({ width, height }) => ({ width, height });
57
+ const extractDimensions = ({ width, height }) => ({
58
+ width,
59
+ height,
60
+ });
57
61
  exports.extractDimensions = extractDimensions;
58
62
  /*
59
63
  * Previously we were using the uuid library to generate unique identifiers for Drax
60
64
  * components. Since we do not need them to be cryptographically secure and likely
61
65
  * won't need very many of them, let's just use this simple function.
62
66
  */
63
- const generateRandomId = () => (`${Math.random().toString(36).substr(2)}${Math.random().toString(36).substr(2)}`);
67
+ const generateRandomId = () => `${Math.random().toString(36).substr(2)}${Math.random().toString(36).substr(2)}`;
64
68
  exports.generateRandomId = generateRandomId;
package/build/params.d.ts CHANGED
@@ -16,3 +16,12 @@ export declare const defaultAutoScrollJumpRatio = 0.2;
16
16
  export declare const defaultAutoScrollBackThreshold = 0.1;
17
17
  /** Default drag-over minimum position threshold for auto-scroll forward, as a fraction relative to content width/length */
18
18
  export declare const defaultAutoScrollForwardThreshold = 0.9;
19
+ export declare const INITIAL_REANIMATED_POSITION: {
20
+ value: {
21
+ x: number;
22
+ y: number;
23
+ };
24
+ addListener(): void;
25
+ removeListener(): void;
26
+ modify(): void;
27
+ };
package/build/params.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultAutoScrollForwardThreshold = exports.defaultAutoScrollBackThreshold = exports.defaultAutoScrollJumpRatio = exports.defaultAutoScrollIntervalLength = exports.defaultScrollEventThrottle = exports.defaultListItemLongPressDelay = exports.defaultLongPressDelay = exports.defaultSnapbackDuration = exports.defaultSnapbackDelay = void 0;
3
+ exports.INITIAL_REANIMATED_POSITION = exports.defaultAutoScrollForwardThreshold = exports.defaultAutoScrollBackThreshold = exports.defaultAutoScrollJumpRatio = exports.defaultAutoScrollIntervalLength = exports.defaultScrollEventThrottle = exports.defaultListItemLongPressDelay = exports.defaultLongPressDelay = exports.defaultSnapbackDuration = exports.defaultSnapbackDelay = void 0;
4
4
  /** Default snapback delay in milliseconds */
5
5
  exports.defaultSnapbackDelay = 100;
6
6
  /** Default snapback duration in milliseconds */
@@ -19,3 +19,9 @@ exports.defaultAutoScrollJumpRatio = 0.2;
19
19
  exports.defaultAutoScrollBackThreshold = 0.1;
20
20
  /** Default drag-over minimum position threshold for auto-scroll forward, as a fraction relative to content width/length */
21
21
  exports.defaultAutoScrollForwardThreshold = 0.9;
22
+ exports.INITIAL_REANIMATED_POSITION = {
23
+ value: { x: 0, y: 0 },
24
+ addListener() { },
25
+ removeListener() { },
26
+ modify() { },
27
+ };
@@ -1,4 +1,11 @@
1
- import { Animated, StyleProp, ViewStyle } from 'react-native';
2
- import { AnimatedViewStyleWithoutLayout } from './types';
3
- export declare const flattenStylesWithoutLayout: (styles: StyleProp<Animated.WithAnimatedValue<ViewStyle>>[]) => AnimatedViewStyleWithoutLayout;
4
- export declare const mergeStyleTransform: (style: AnimatedViewStyleWithoutLayout, transform: Animated.WithAnimatedValue<ViewStyle['transform']>) => AnimatedViewStyleWithoutLayout;
1
+ import { PropsWithChildren } from 'react';
2
+ import { StyleProp, ViewStyle } from 'react-native';
3
+ import { AnimatedStyle, ILayoutAnimationBuilder, SharedValue, StyleProps } from 'react-native-reanimated';
4
+ import { AnimatedViewStyleWithoutLayout, DraxViewDragStatus, TReanimatedHoverViewProps, ViewDimensions } from './types';
5
+ export declare const flattenStylesWithoutLayout: (styles: (StyleProps | StyleProp<ViewStyle> | StyleProp<AnimatedStyle<StyleProp<ViewStyle>>> | null)[]) => AnimatedViewStyleWithoutLayout;
6
+ export declare const getCombinedHoverStyle: ({ dragStatus, anyReceiving, dimensions, }: {
7
+ dimensions: ViewDimensions;
8
+ dragStatus: DraxViewDragStatus;
9
+ anyReceiving: boolean;
10
+ }, props: Partial<PropsWithChildren<TReanimatedHoverViewProps>>) => AnimatedViewStyleWithoutLayout;
11
+ export declare const customLayoutTransition: (shiftsRef: SharedValue<number[]>, data?: ArrayLike<any> | null) => ILayoutAnimationBuilder;
@@ -1,17 +1,59 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeStyleTransform = exports.flattenStylesWithoutLayout = void 0;
3
+ exports.customLayoutTransition = exports.getCombinedHoverStyle = exports.flattenStylesWithoutLayout = void 0;
4
4
  const react_native_1 = require("react-native");
5
+ const react_native_reanimated_1 = require("react-native-reanimated");
6
+ const types_1 = require("./types");
5
7
  const flattenStylesWithoutLayout = (styles) => {
6
8
  const { margin, marginHorizontal, marginVertical, marginLeft, marginRight, marginTop, marginBottom, marginStart, marginEnd, left, right, top, bottom, flex, flexBasis, flexDirection, flexGrow, flexShrink, ...flattened } = react_native_1.StyleSheet.flatten(styles);
7
9
  return flattened;
8
10
  };
9
11
  exports.flattenStylesWithoutLayout = flattenStylesWithoutLayout;
10
- const mergeStyleTransform = (style, transform) => ({
11
- ...style,
12
- transform: [
13
- ...(transform ?? []),
14
- ...(style.transform ?? []),
15
- ],
12
+ // Combine hover styles for given internal render props.
13
+ const getCombinedHoverStyle = ({ dragStatus, anyReceiving, dimensions, }, props) => {
14
+ // Start with base style, calculated dimensions, and hover base style.
15
+ const hoverStyles = [
16
+ props?.style,
17
+ dimensions,
18
+ props?.hoverStyle,
19
+ ];
20
+ // Apply style overrides based on state.
21
+ if (dragStatus === types_1.DraxViewDragStatus.Dragging) {
22
+ hoverStyles.push(props?.hoverDraggingStyle);
23
+ if (anyReceiving) {
24
+ hoverStyles.push(props?.hoverDraggingWithReceiverStyle);
25
+ }
26
+ else {
27
+ hoverStyles.push(props?.hoverDraggingWithoutReceiverStyle);
28
+ }
29
+ }
30
+ else if (dragStatus === types_1.DraxViewDragStatus.Released) {
31
+ hoverStyles.push(props?.hoverDragReleasedStyle);
32
+ }
33
+ // Remove any layout styles.
34
+ const flattenedHoverStyle = (0, exports.flattenStylesWithoutLayout)(hoverStyles);
35
+ return flattenedHoverStyle;
36
+ };
37
+ exports.getCombinedHoverStyle = getCombinedHoverStyle;
38
+ const customLayoutTransition = (shiftsRef, data) => ({
39
+ build: () => values => {
40
+ 'worklet';
41
+ const isInternalReordering = shiftsRef.value.length <= (data?.length || 0);
42
+ const duration = isInternalReordering ? 1 : 200;
43
+ return {
44
+ animations: {
45
+ originX: (0, react_native_reanimated_1.withTiming)(values.targetOriginX, { duration }),
46
+ originY: (0, react_native_reanimated_1.withTiming)(values.targetOriginY, { duration }),
47
+ width: (0, react_native_reanimated_1.withSpring)(values.targetWidth),
48
+ height: (0, react_native_reanimated_1.withSpring)(values.targetHeight),
49
+ },
50
+ initialValues: {
51
+ originX: values.currentOriginX,
52
+ originY: values.currentOriginY,
53
+ width: values.currentWidth,
54
+ height: values.currentHeight,
55
+ },
56
+ };
57
+ },
16
58
  });
17
- exports.mergeStyleTransform = mergeStyleTransform;
59
+ exports.customLayoutTransition = customLayoutTransition;