react-native-drax 0.8.1 → 0.9.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.
- package/CHANGELOG.md +34 -1
- package/README.md +5 -3
- package/build/DraxList.d.ts +7 -2
- package/build/DraxList.js +17 -6
- package/build/DraxScrollView.d.ts +5 -2
- package/build/DraxScrollView.js +15 -5
- package/build/math.js +1 -1
- package/build/types.d.ts +2 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,35 @@ Changes marked as (BREAKING) may break your app logic. Changes marked as (BREAKI
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
- Nothing yet
|
|
11
11
|
|
|
12
|
+
## [0.9.2] - 2021-12-08
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- Fixed typo-based math error in view measurement clipping logic (#124)
|
|
16
|
+
|
|
17
|
+
## [0.9.1] - 2021-11-03
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
- Apply `DraxScrollView`'s style to outer `DraxView` instead of inner `ScrollView` (#119)
|
|
21
|
+
- Upgraded tmpl from 1.0.4 to 1.0.5 (dependabot)
|
|
22
|
+
|
|
23
|
+
## [0.9.0] - 2021-11-03
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
- Forward underlying `ScrollView` ref in `DraxScrollView` (#117)
|
|
27
|
+
- Forward underlying `FlatList` ref in `DraxList` (#118)
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- Apply `DraxScrollView`'s style to outer `DraxView` instead of inner `ScrollView` (#119)
|
|
31
|
+
- Elaborated on state of library and contributions in README
|
|
32
|
+
|
|
33
|
+
## [0.8.2] - 2021-09-07
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
- Added `longPressDelay` prop to `DraxList` to override default (#59)
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
- Upgraded path-parse from 1.0.6 to 1.0.7 (dependabot)
|
|
40
|
+
|
|
12
41
|
## [0.8.1] - 2021-08-02
|
|
13
42
|
|
|
14
43
|
### Changed
|
|
@@ -177,7 +206,11 @@ Changes marked as (BREAKING) may break your app logic. Changes marked as (BREAKI
|
|
|
177
206
|
|
|
178
207
|
*(More history to be added later)*
|
|
179
208
|
|
|
180
|
-
[Unreleased]: https://github.com/nuclearpasta/react-native-drax/compare/v0.
|
|
209
|
+
[Unreleased]: https://github.com/nuclearpasta/react-native-drax/compare/v0.9.2...HEAD
|
|
210
|
+
[0.9.2]: https://github.com/nuclearpasta/react-native-drax/compare/v0.9.1...v0.9.2
|
|
211
|
+
[0.9.1]: https://github.com/nuclearpasta/react-native-drax/compare/v0.9.0...v0.9.1
|
|
212
|
+
[0.9.0]: https://github.com/nuclearpasta/react-native-drax/compare/v0.8.2...v0.9.0
|
|
213
|
+
[0.8.2]: https://github.com/nuclearpasta/react-native-drax/compare/v0.8.1...v0.8.2
|
|
181
214
|
[0.8.1]: https://github.com/nuclearpasta/react-native-drax/compare/v0.8.0...v0.8.1
|
|
182
215
|
[0.8.0]: https://github.com/nuclearpasta/react-native-drax/compare/v0.7.2...v0.8.0
|
|
183
216
|
[0.7.2]: https://github.com/nuclearpasta/react-native-drax/compare/v0.7.1...v0.7.2
|
package/README.md
CHANGED
|
@@ -43,10 +43,12 @@ Drax is a declarative drag-and-drop system for React Native, written in TypeScri
|
|
|
43
43
|
|
|
44
44
|
This library adheres to [Semantic Versioning (semver)](https://semver.org/) and is in its [0.y.z initial development phase](https://semver.org/#how-should-i-deal-with-revisions-in-the-0yz-initial-development-phase). It has been released so that early adopters (such as the project author) can begin to use it in production and identify gaps in the functionality. The API is subject to potentially significant rework until version 1.0.0 is released, and any minor version increment before then may include breaking changes. Documentation and full examples are still being written.
|
|
45
45
|
|
|
46
|
+
The author of this library has not had significant availability to work on it for quite a while now, due to higher priority life and work concerns. Newer versions of Drax's major dependencies have been released in that time, and many people have opened issues asking questions about usage and potential features. Relatively small fixes and easy questions are handled reasonably often, but ultimately another round of research, testing, and architecture are what would take this library to the next level of usability. It is not clear when that might happen, but [contributors are welcome](#contributing).
|
|
47
|
+
|
|
46
48
|
<a name="background"></a>
|
|
47
49
|
## Background
|
|
48
50
|
|
|
49
|
-
To give an idea of the problem this library is trying to solve, here is some informal background
|
|
51
|
+
To give an idea of the problem this library is trying to solve, here is some informal background:
|
|
50
52
|
|
|
51
53
|
> In our React Native application we had a screen which showed a
|
|
52
54
|
> FlatList of cards that could be scrolled through or individually
|
|
@@ -187,7 +189,7 @@ Note: these Snack examples will not work in the Web device. You must use an iOS
|
|
|
187
189
|
<a name="contributing"></a>
|
|
188
190
|
## Contributing
|
|
189
191
|
|
|
190
|
-
See the [Contribution Guidelines](CONTRIBUTING.md) for details.
|
|
192
|
+
Issues, pull request, and discussion are all welcome. See the [Contribution Guidelines](CONTRIBUTING.md) for details, and please reach out to [the author](https://github.com/lafiosca) if you would like to participate more significantly.
|
|
191
193
|
|
|
192
194
|
<a name="code-of-conduct"></a>
|
|
193
195
|
## Code of Conduct
|
|
@@ -202,4 +204,4 @@ This software library is licensed under the [MIT License](LICENSE.md).
|
|
|
202
204
|
<a name="acknowledgements"></a>
|
|
203
205
|
## Acknowledgments
|
|
204
206
|
|
|
205
|
-
The
|
|
207
|
+
The initial version of this library was written by [Joe Lafiosca](https://github.com/lafiosca) over the course of December 2019. Joe would like to give thanks to Nuclear Pasta co-founder Mark Thomas for being patient with the development process. Joe would also like to give thanks to Lena Raine, Tom Jenkinson, Rollie Pemberton, David Minnick, Tim Smith, and Danny Baranowsky for providing most of the coding background music that inspired this work.
|
package/build/DraxList.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PropsWithChildren, Ref } from 'react';
|
|
2
|
+
import { FlatList } from 'react-native';
|
|
2
3
|
import { DraxListProps } from './types';
|
|
3
|
-
|
|
4
|
+
declare type DraxListType = <T extends unknown>(props: PropsWithChildren<DraxListProps<T>> & {
|
|
5
|
+
ref?: Ref<FlatList>;
|
|
6
|
+
}) => JSX.Element;
|
|
7
|
+
export declare const DraxList: DraxListType;
|
|
8
|
+
export {};
|
package/build/DraxList.js
CHANGED
|
@@ -31,9 +31,10 @@ const defaultStyles = react_native_1.StyleSheet.create({
|
|
|
31
31
|
draggingStyle: { opacity: 0 },
|
|
32
32
|
dragReleasedStyle: { opacity: 0.5 },
|
|
33
33
|
});
|
|
34
|
-
const
|
|
34
|
+
const DraxListUnforwarded = (props, forwardedRef) => {
|
|
35
|
+
const { data, style, flatListStyle, itemStyles, renderItemContent, renderItemHoverContent, onItemDragStart, onItemDragPositionChange, onItemDragEnd, onItemReorder, viewPropsExtractor, id: idProp, reorderable: reorderableProp, onScroll: onScrollProp, itemsDraggable = true, lockItemDragsToMainAxis = false, longPressDelay = params_1.defaultListItemLongPressDelay, ...flatListProps } = props;
|
|
35
36
|
// Copy the value of the horizontal property for internal use.
|
|
36
|
-
const horizontal =
|
|
37
|
+
const horizontal = flatListProps.horizontal ?? false;
|
|
37
38
|
// Get the item count for internal use.
|
|
38
39
|
const itemCount = data?.length ?? 0;
|
|
39
40
|
// Set a sensible default for reorderable prop.
|
|
@@ -135,7 +136,7 @@ const DraxList = ({ data, style, flatListStyle, itemStyles, renderItemContent, r
|
|
|
135
136
|
const { index, item } = info;
|
|
136
137
|
const originalIndex = originalIndexes[index];
|
|
137
138
|
const { style: itemStyle, draggingStyle = defaultStyles.draggingStyle, dragReleasedStyle = defaultStyles.dragReleasedStyle, ...otherStyleProps } = itemStyles ?? {};
|
|
138
|
-
return (react_1.default.createElement(DraxView_1.DraxView, Object.assign({ style: [itemStyle, { transform: getShiftTransform(originalIndex) }], draggingStyle: draggingStyle, dragReleasedStyle: dragReleasedStyle }, otherStyleProps, { longPressDelay:
|
|
139
|
+
return (react_1.default.createElement(DraxView_1.DraxView, Object.assign({ style: [itemStyle, { transform: getShiftTransform(originalIndex) }], draggingStyle: draggingStyle, dragReleasedStyle: dragReleasedStyle }, otherStyleProps, { longPressDelay: longPressDelay, lockDragXPosition: lockItemDragsToMainAxis && !horizontal, lockDragYPosition: lockItemDragsToMainAxis && horizontal, draggable: itemsDraggable, payload: { index, originalIndex } }, (viewPropsExtractor?.(item) ?? {}), { onDragEnd: resetDraggedItem, onDragDrop: resetDraggedItem, onMeasure: (measurements) => {
|
|
139
140
|
if (originalIndex !== undefined) {
|
|
140
141
|
// console.log(`measuring [${index}, ${originalIndex}]: (${measurements?.x}, ${measurements?.y})`);
|
|
141
142
|
itemMeasurementsRef.current[originalIndex] = measurements;
|
|
@@ -157,6 +158,7 @@ const DraxList = ({ data, style, flatListStyle, itemStyles, renderItemContent, r
|
|
|
157
158
|
itemsDraggable,
|
|
158
159
|
renderItemContent,
|
|
159
160
|
renderItemHoverContent,
|
|
161
|
+
longPressDelay,
|
|
160
162
|
lockItemDragsToMainAxis,
|
|
161
163
|
horizontal,
|
|
162
164
|
]);
|
|
@@ -172,7 +174,16 @@ const DraxList = ({ data, style, flatListStyle, itemStyles, renderItemContent, r
|
|
|
172
174
|
const setFlatListRefs = react_1.useCallback((ref) => {
|
|
173
175
|
flatListRef.current = ref;
|
|
174
176
|
nodeHandleRef.current = ref && react_native_1.findNodeHandle(ref);
|
|
175
|
-
|
|
177
|
+
if (forwardedRef) {
|
|
178
|
+
if (typeof forwardedRef === 'function') {
|
|
179
|
+
forwardedRef(ref);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// eslint-disable-next-line no-param-reassign
|
|
183
|
+
forwardedRef.current = ref;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}, [forwardedRef]);
|
|
176
187
|
// Update tracked scroll position when list is scrolled.
|
|
177
188
|
const onScroll = react_1.useCallback((event) => {
|
|
178
189
|
const { nativeEvent: { contentOffset } } = event;
|
|
@@ -477,6 +488,6 @@ const DraxList = ({ data, style, flatListStyle, itemStyles, renderItemContent, r
|
|
|
477
488
|
const onMonitorDragDrop = react_1.useCallback((eventData) => handleInternalDragEnd(eventData, true), [handleInternalDragEnd]);
|
|
478
489
|
return (react_1.default.createElement(DraxView_1.DraxView, { id: id, style: style, scrollPositionRef: scrollPositionRef, onMeasure: onMeasureContainer, onMonitorDragStart: onMonitorDragStart, onMonitorDragOver: onMonitorDragOver, onMonitorDragExit: onMonitorDragExit, onMonitorDragEnd: onMonitorDragEnd, onMonitorDragDrop: onMonitorDragDrop },
|
|
479
490
|
react_1.default.createElement(DraxSubprovider_1.DraxSubprovider, { parent: { id, nodeHandleRef } },
|
|
480
|
-
react_1.default.createElement(react_native_1.FlatList, Object.assign({},
|
|
491
|
+
react_1.default.createElement(react_native_1.FlatList, Object.assign({}, flatListProps, { style: flatListStyle, ref: setFlatListRefs, renderItem: renderItem, onScroll: onScroll, onContentSizeChange: onContentSizeChange, data: reorderedData })))));
|
|
481
492
|
};
|
|
482
|
-
exports.DraxList =
|
|
493
|
+
exports.DraxList = react_1.forwardRef(DraxListUnforwarded);
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ScrollView } from 'react-native';
|
|
2
3
|
import { DraxScrollViewProps } from './types';
|
|
3
|
-
export declare const DraxScrollView:
|
|
4
|
+
export declare const DraxScrollView: React.ForwardRefExoticComponent<DraxScrollViewProps & {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
} & React.RefAttributes<ScrollView>>;
|
package/build/DraxScrollView.js
CHANGED
|
@@ -27,7 +27,8 @@ const DraxSubprovider_1 = require("./DraxSubprovider");
|
|
|
27
27
|
const hooks_1 = require("./hooks");
|
|
28
28
|
const types_1 = require("./types");
|
|
29
29
|
const params_1 = require("./params");
|
|
30
|
-
const
|
|
30
|
+
const DraxScrollViewUnforwarded = (props, forwardedRef) => {
|
|
31
|
+
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;
|
|
31
32
|
// The unique identifer for this view.
|
|
32
33
|
const id = hooks_1.useDraxId(idProp);
|
|
33
34
|
// Scrollable view, used for scrolling.
|
|
@@ -164,7 +165,16 @@ const DraxScrollView = ({ children, onScroll: onScrollProp, onContentSizeChange:
|
|
|
164
165
|
const setScrollViewRefs = react_1.useCallback((ref) => {
|
|
165
166
|
scrollRef.current = ref;
|
|
166
167
|
nodeHandleRef.current = ref && react_native_1.findNodeHandle(ref);
|
|
167
|
-
|
|
168
|
+
if (forwardedRef) {
|
|
169
|
+
if (typeof forwardedRef === 'function') {
|
|
170
|
+
forwardedRef(ref);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// eslint-disable-next-line no-param-reassign
|
|
174
|
+
forwardedRef.current = ref;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}, [forwardedRef]);
|
|
168
178
|
// Track content size.
|
|
169
179
|
const onContentSizeChange = react_1.useCallback((width, height) => {
|
|
170
180
|
contentSizeRef.current = { x: width, y: height };
|
|
@@ -176,8 +186,8 @@ const DraxScrollView = ({ children, onScroll: onScrollProp, onContentSizeChange:
|
|
|
176
186
|
scrollPositionRef.current = { ...contentOffset };
|
|
177
187
|
return onScrollProp?.(event);
|
|
178
188
|
}, [onScrollProp]);
|
|
179
|
-
return id ? (react_1.default.createElement(DraxView_1.DraxView, { id: id, scrollPositionRef: scrollPositionRef, onMeasure: onMeasureContainer, onMonitorDragOver: onMonitorDragOver, onMonitorDragExit: resetScroll, onMonitorDragEnd: resetScroll, onMonitorDragDrop: resetScroll },
|
|
189
|
+
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 },
|
|
180
190
|
react_1.default.createElement(DraxSubprovider_1.DraxSubprovider, { parent: { id, nodeHandleRef } },
|
|
181
|
-
react_1.default.createElement(react_native_1.ScrollView, Object.assign({},
|
|
191
|
+
react_1.default.createElement(react_native_1.ScrollView, Object.assign({}, scrollViewProps, { ref: setScrollViewRefs, onContentSizeChange: onContentSizeChange, onScroll: onScroll, scrollEventThrottle: scrollEventThrottle }), children)))) : null;
|
|
182
192
|
};
|
|
183
|
-
exports.DraxScrollView =
|
|
193
|
+
exports.DraxScrollView = react_1.forwardRef(DraxScrollViewUnforwarded);
|
package/build/math.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.generateRandomId = exports.extractDimensions = exports.extractPosition =
|
|
|
4
4
|
const clipMeasurements = (vm, cvm) => {
|
|
5
5
|
let { width, height, x: x0, y: y0, } = vm;
|
|
6
6
|
let x1 = x0 + width;
|
|
7
|
-
let y1 = y0 +
|
|
7
|
+
let y1 = y0 + height;
|
|
8
8
|
const { width: cwidth, height: cheight, x: cx0, y: cy0, } = cvm;
|
|
9
9
|
const cx1 = cx0 + cwidth;
|
|
10
10
|
const cy1 = cy0 + cheight;
|
package/build/types.d.ts
CHANGED
|
@@ -661,6 +661,8 @@ export interface DraxListProps<TItem> extends Omit<FlatListProps<TItem>, 'render
|
|
|
661
661
|
itemsDraggable?: boolean;
|
|
662
662
|
/** If true, lock item drags to the list's main axis */
|
|
663
663
|
lockItemDragsToMainAxis?: boolean;
|
|
664
|
+
/** Time in milliseconds view needs to be pressed before drag starts */
|
|
665
|
+
longPressDelay?: number;
|
|
664
666
|
/** Function that receives an item and returns a list of DraxViewProps to apply to that item's DraxView */
|
|
665
667
|
viewPropsExtractor?: (item: TItem) => Partial<DraxViewProps>;
|
|
666
668
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-drax",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "A drag-and-drop system for React Native",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "yarn run tsc",
|
|
14
14
|
"prepublish": "yarn run build"
|
|
15
15
|
},
|
|
16
|
-
"author": "Joe Lafiosca <joe@
|
|
16
|
+
"author": "Joe Lafiosca <joe@proxi.gg>",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"lodash.isequal": "^4.5.0",
|