react-native-sortable-dynamic 0.1.1 → 0.2.1
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/README.md +54 -50
- package/lib/commonjs/Config.js +12 -12
- package/lib/commonjs/Config.js.map +1 -1
- package/lib/commonjs/SortableContainer.js +115 -0
- package/lib/commonjs/SortableContainer.js.map +1 -0
- package/lib/commonjs/SortableItem.js +61 -0
- package/lib/commonjs/SortableItem.js.map +1 -0
- package/lib/commonjs/{Item.js → SortableItemWrapper.js} +31 -16
- package/lib/commonjs/SortableItemWrapper.js.map +1 -0
- package/lib/commonjs/SortableView.js +70 -0
- package/lib/commonjs/SortableView.js.map +1 -0
- package/lib/commonjs/index.js +3 -17
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Config.js +12 -12
- package/lib/module/Config.js.map +1 -1
- package/lib/module/SortableContainer.js +110 -0
- package/lib/module/SortableContainer.js.map +1 -0
- package/lib/module/SortableItem.js +58 -0
- package/lib/module/SortableItem.js.map +1 -0
- package/lib/module/{Item.js → SortableItemWrapper.js} +31 -16
- package/lib/module/SortableItemWrapper.js.map +1 -0
- package/lib/module/SortableView.js +67 -0
- package/lib/module/SortableView.js.map +1 -0
- package/lib/module/index.js +1 -3
- package/lib/module/index.js.map +1 -1
- package/package.json +6 -6
- package/src/Config.js +12 -12
- package/src/SortableContainer.js +110 -0
- package/src/SortableItem.js +57 -0
- package/src/{Item.js → SortableItemWrapper.js} +30 -16
- package/src/SortableView.js +65 -0
- package/src/index.js +1 -3
- package/lib/commonjs/Item.js.map +0 -1
- package/lib/commonjs/SortableList.js +0 -91
- package/lib/commonjs/SortableList.js.map +0 -1
- package/lib/commonjs/Tile.js +0 -56
- package/lib/commonjs/Tile.js.map +0 -1
- package/lib/module/Item.js.map +0 -1
- package/lib/module/SortableList.js +0 -86
- package/lib/module/SortableList.js.map +0 -1
- package/lib/module/Tile.js +0 -53
- package/lib/module/Tile.js.map +0 -1
- package/src/SortableList.js +0 -86
- package/src/Tile.js +0 -47
package/lib/module/Tile.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { TouchableOpacity } from 'react-native';
|
|
5
|
-
import { useSortableConfig } from "./Config.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Tile Component
|
|
9
|
-
*
|
|
10
|
-
* This component represents a single tile in the sortable grid. It is designed to be flexible and
|
|
11
|
-
* allows for user interactions such as press and long press. The size of each tile is dynamically
|
|
12
|
-
* adjusted based on the configuration provided by `SortableListProvider`.
|
|
13
|
-
*
|
|
14
|
-
* Props:
|
|
15
|
-
* @param {function} onPress - Callback function called when the tile is pressed.
|
|
16
|
-
* @param {function} onLongPress - Callback function called when the tile is long-pressed.
|
|
17
|
-
* @param {number} activeOpacity - The opacity of the tile when it is pressed. Default is 0.7.
|
|
18
|
-
* @param {React.ReactNode} children - The content to render inside the tile.
|
|
19
|
-
*
|
|
20
|
-
* Usage:
|
|
21
|
-
*
|
|
22
|
-
* <Tile onPress={handlePress} onLongPress={handleLongPress}>
|
|
23
|
-
* <Text>Tile Content</Text>
|
|
24
|
-
* </Tile>
|
|
25
|
-
*/
|
|
26
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
27
|
-
const Tile = ({
|
|
28
|
-
onPress,
|
|
29
|
-
onLongPress,
|
|
30
|
-
activeOpacity = 0.7,
|
|
31
|
-
children
|
|
32
|
-
}) => {
|
|
33
|
-
// Get the size of the tile from the sortable config context
|
|
34
|
-
const {
|
|
35
|
-
SIZE
|
|
36
|
-
} = useSortableConfig();
|
|
37
|
-
|
|
38
|
-
// Define the style for the tile, ensuring that its size is consistent across the grid
|
|
39
|
-
const containerStyle = {
|
|
40
|
-
width: SIZE,
|
|
41
|
-
height: SIZE
|
|
42
|
-
};
|
|
43
|
-
return /*#__PURE__*/_jsx(TouchableOpacity, {
|
|
44
|
-
style: containerStyle,
|
|
45
|
-
onPress: onPress,
|
|
46
|
-
onLongPress: onLongPress,
|
|
47
|
-
activeOpacity: activeOpacity // Control the opacity when the tile is pressed
|
|
48
|
-
,
|
|
49
|
-
children: children
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
export default Tile;
|
|
53
|
-
//# sourceMappingURL=Tile.js.map
|
package/lib/module/Tile.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","TouchableOpacity","useSortableConfig","jsx","_jsx","Tile","onPress","onLongPress","activeOpacity","children","SIZE","containerStyle","width","height","style"],"sourceRoot":"../../src","sources":["Tile.js"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,gBAAgB,QAAQ,cAAc;AAC/C,SAASC,iBAAiB,QAAQ,aAAU;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAlBA,SAAAC,GAAA,IAAAC,IAAA;AAoBA,MAAMC,IAAI,GAAGA,CAAC;EAAEC,OAAO;EAAEC,WAAW;EAAEC,aAAa,GAAG,GAAG;EAAEC;AAAS,CAAC,KAAK;EACxE;EACA,MAAM;IAAEC;EAAK,CAAC,GAAGR,iBAAiB,CAAC,CAAC;;EAEpC;EACA,MAAMS,cAAc,GAAG;IACrBC,KAAK,EAAEF,IAAI;IACXG,MAAM,EAAEH;EACV,CAAC;EAED,oBACEN,IAAA,CAACH,gBAAgB;IACfa,KAAK,EAAEH,cAAe;IACtBL,OAAO,EAAEA,OAAQ;IACjBC,WAAW,EAAEA,WAAY;IACzBC,aAAa,EAAEA,aAAc,CAAC;IAAA;IAAAC,QAAA,EAE7BA;EAAQ,CACO,CAAC;AAEvB,CAAC;AAED,eAAeJ,IAAI","ignoreList":[]}
|
package/src/SortableList.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import React, { memo } from 'react';
|
|
2
|
-
import Animated, {
|
|
3
|
-
useAnimatedRef,
|
|
4
|
-
useAnimatedScrollHandler,
|
|
5
|
-
useSharedValue,
|
|
6
|
-
} from 'react-native-reanimated';
|
|
7
|
-
import Item from './Item';
|
|
8
|
-
import { useSortableConfig } from './Config';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* SortableList Component
|
|
12
|
-
*
|
|
13
|
-
* This component renders a scrollable list of items that can be reordered using drag-and-drop gestures.
|
|
14
|
-
* It manages the overall layout of the items and provides the necessary props to each child `Item` component
|
|
15
|
-
* to enable dragging, scrolling, and reordering functionality.
|
|
16
|
-
*
|
|
17
|
-
* Props:
|
|
18
|
-
* @param {React.ReactNode[]} children - The list of items to render inside the sortable list.
|
|
19
|
-
* @param {boolean} editing - Whether the list is in editing mode, enabling drag-and-drop.
|
|
20
|
-
* @param {Array} tiles - Array of tile data to manage the reordering state.
|
|
21
|
-
* @param {function} onDragEnd - Callback function called with the updated positions when the drag ends.
|
|
22
|
-
*
|
|
23
|
-
* Usage:
|
|
24
|
-
*
|
|
25
|
-
* <SortableList editing={isEditing} tiles={tiles} onDragEnd={handleDragEnd}>
|
|
26
|
-
* {tiles.map((tile) => (
|
|
27
|
-
* <YourTileComponent key={tile.id} id={tile.id} />
|
|
28
|
-
* ))}
|
|
29
|
-
* </SortableList>
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
const SortableList = ({ children, editing, tiles, onDragEnd }) => {
|
|
33
|
-
// Get the configuration for columns and size from context
|
|
34
|
-
const { COL, SIZE } = useSortableConfig();
|
|
35
|
-
|
|
36
|
-
// Shared values to track scrolling and item positions
|
|
37
|
-
const scrollY = useSharedValue(0); // Current scroll position
|
|
38
|
-
const scrollView = useAnimatedRef(); // Reference to the scroll view
|
|
39
|
-
const positions = useSharedValue(
|
|
40
|
-
children.reduce(
|
|
41
|
-
(acc, child, index) => ({ ...acc, [child.props.id]: index }),
|
|
42
|
-
{}
|
|
43
|
-
)
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// Scroll event handler to update scrollY shared value
|
|
47
|
-
const onScroll = useAnimatedScrollHandler({
|
|
48
|
-
onScroll: ({ contentOffset: { y } }) => {
|
|
49
|
-
scrollY.value = y;
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<Animated.ScrollView
|
|
55
|
-
onScroll={onScroll}
|
|
56
|
-
ref={scrollView}
|
|
57
|
-
contentContainerStyle={{
|
|
58
|
-
// Calculate the total height needed for the scroll view content
|
|
59
|
-
height: Math.ceil(children.length / COL) * SIZE,
|
|
60
|
-
}}
|
|
61
|
-
showsVerticalScrollIndicator={false}
|
|
62
|
-
bounces={false}
|
|
63
|
-
scrollEventThrottle={16} // Control scroll event frequency
|
|
64
|
-
>
|
|
65
|
-
{/* Render each child wrapped in an Item component */}
|
|
66
|
-
{children.map((child) => (
|
|
67
|
-
<Item
|
|
68
|
-
key={child.props.id}
|
|
69
|
-
id={child.props.id}
|
|
70
|
-
positions={positions}
|
|
71
|
-
editing={editing}
|
|
72
|
-
draggable={child.props.draggable}
|
|
73
|
-
reorderable={child.props.reorderable}
|
|
74
|
-
tiles={tiles}
|
|
75
|
-
onDragEnd={onDragEnd}
|
|
76
|
-
scrollView={scrollView}
|
|
77
|
-
scrollY={scrollY}
|
|
78
|
-
>
|
|
79
|
-
{child}
|
|
80
|
-
</Item>
|
|
81
|
-
))}
|
|
82
|
-
</Animated.ScrollView>
|
|
83
|
-
);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export default memo(SortableList);
|
package/src/Tile.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { TouchableOpacity } from 'react-native';
|
|
3
|
-
import { useSortableConfig } from './Config';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Tile Component
|
|
7
|
-
*
|
|
8
|
-
* This component represents a single tile in the sortable grid. It is designed to be flexible and
|
|
9
|
-
* allows for user interactions such as press and long press. The size of each tile is dynamically
|
|
10
|
-
* adjusted based on the configuration provided by `SortableListProvider`.
|
|
11
|
-
*
|
|
12
|
-
* Props:
|
|
13
|
-
* @param {function} onPress - Callback function called when the tile is pressed.
|
|
14
|
-
* @param {function} onLongPress - Callback function called when the tile is long-pressed.
|
|
15
|
-
* @param {number} activeOpacity - The opacity of the tile when it is pressed. Default is 0.7.
|
|
16
|
-
* @param {React.ReactNode} children - The content to render inside the tile.
|
|
17
|
-
*
|
|
18
|
-
* Usage:
|
|
19
|
-
*
|
|
20
|
-
* <Tile onPress={handlePress} onLongPress={handleLongPress}>
|
|
21
|
-
* <Text>Tile Content</Text>
|
|
22
|
-
* </Tile>
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const Tile = ({ onPress, onLongPress, activeOpacity = 0.7, children }) => {
|
|
26
|
-
// Get the size of the tile from the sortable config context
|
|
27
|
-
const { SIZE } = useSortableConfig();
|
|
28
|
-
|
|
29
|
-
// Define the style for the tile, ensuring that its size is consistent across the grid
|
|
30
|
-
const containerStyle = {
|
|
31
|
-
width: SIZE,
|
|
32
|
-
height: SIZE,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<TouchableOpacity
|
|
37
|
-
style={containerStyle}
|
|
38
|
-
onPress={onPress}
|
|
39
|
-
onLongPress={onLongPress}
|
|
40
|
-
activeOpacity={activeOpacity} // Control the opacity when the tile is pressed
|
|
41
|
-
>
|
|
42
|
-
{children}
|
|
43
|
-
</TouchableOpacity>
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export default Tile;
|