react-native-sortable-dynamic 0.1.0

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.
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _Config = require("./Config.js");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ /**
13
+ * Tile Component
14
+ *
15
+ * This component represents a single tile in the sortable grid. It is designed to be flexible and
16
+ * allows for user interactions such as press and long press. The size of each tile is dynamically
17
+ * adjusted based on the configuration provided by `SortableListProvider`.
18
+ *
19
+ * Props:
20
+ * @param {function} onPress - Callback function called when the tile is pressed.
21
+ * @param {function} onLongPress - Callback function called when the tile is long-pressed.
22
+ * @param {number} activeOpacity - The opacity of the tile when it is pressed. Default is 0.7.
23
+ * @param {React.ReactNode} children - The content to render inside the tile.
24
+ *
25
+ * Usage:
26
+ *
27
+ * <Tile onPress={handlePress} onLongPress={handleLongPress}>
28
+ * <Text>Tile Content</Text>
29
+ * </Tile>
30
+ */const Tile = ({
31
+ onPress,
32
+ onLongPress,
33
+ activeOpacity = 0.7,
34
+ children
35
+ }) => {
36
+ // Get the size of the tile from the sortable config context
37
+ const {
38
+ SIZE
39
+ } = (0, _Config.useSortableConfig)();
40
+
41
+ // Define the style for the tile, ensuring that its size is consistent across the grid
42
+ const containerStyle = {
43
+ width: SIZE,
44
+ height: SIZE
45
+ };
46
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
47
+ style: containerStyle,
48
+ onPress: onPress,
49
+ onLongPress: onLongPress,
50
+ activeOpacity: activeOpacity // Control the opacity when the tile is pressed
51
+ ,
52
+ children: children
53
+ });
54
+ };
55
+ var _default = exports.default = Tile;
56
+ //# sourceMappingURL=Tile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_Config","_jsxRuntime","e","__esModule","default","Tile","onPress","onLongPress","activeOpacity","children","SIZE","useSortableConfig","containerStyle","width","height","jsx","TouchableOpacity","style","_default","exports"],"sourceRoot":"../../src","sources":["Tile.js"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAA6C,IAAAG,WAAA,GAAAH,OAAA;AAAA,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAEA,MAAMG,IAAI,GAAGA,CAAC;EAAEC,OAAO;EAAEC,WAAW;EAAEC,aAAa,GAAG,GAAG;EAAEC;AAAS,CAAC,KAAK;EACxE;EACA,MAAM;IAAEC;EAAK,CAAC,GAAG,IAAAC,yBAAiB,EAAC,CAAC;;EAEpC;EACA,MAAMC,cAAc,GAAG;IACrBC,KAAK,EAAEH,IAAI;IACXI,MAAM,EAAEJ;EACV,CAAC;EAED,oBACE,IAAAT,WAAA,CAAAc,GAAA,EAAChB,YAAA,CAAAiB,gBAAgB;IACfC,KAAK,EAAEL,cAAe;IACtBN,OAAO,EAAEA,OAAQ;IACjBC,WAAW,EAAEA,WAAY;IACzBC,aAAa,EAAEA,aAAc,CAAC;IAAA;IAAAC,QAAA,EAE7BA;EAAQ,CACO,CAAC;AAEvB,CAAC;AAAC,IAAAS,QAAA,GAAAC,OAAA,CAAAf,OAAA,GAEaC,IAAI","ignoreList":[]}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "SortableList", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _SortableList.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "SortableListProvider", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Config.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "Tile", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _Tile.default;
22
+ }
23
+ });
24
+ var _Config = _interopRequireDefault(require("./Config.js"));
25
+ var _SortableList = _interopRequireDefault(require("./SortableList.js"));
26
+ var _Tile = _interopRequireDefault(require("./Tile.js"));
27
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_Config","_interopRequireDefault","require","_SortableList","_Tile","e","__esModule","default"],"sourceRoot":"../../src","sources":["index.js"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAyC,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ import { Dimensions } from 'react-native';
4
+ import { Easing } from 'react-native-reanimated';
5
+ import React, { createContext, useContext } from 'react';
6
+
7
+ // Get screen width to calculate dynamic sizes
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ const {
10
+ width
11
+ } = Dimensions.get('window');
12
+
13
+ // Default configuration for the sortable list
14
+ const defaultConfig = {
15
+ MARGIN: 10,
16
+ // Default margin between items
17
+ COL: 2,
18
+ // Default number of columns
19
+ // Default size for each item, calculated based on the number of columns and margin
20
+ SIZE: width / 2 - 10 // (width / COL - MARGIN)
21
+ };
22
+
23
+ // Create a Context for the sortable list configuration
24
+ const ConfigContext = /*#__PURE__*/createContext(defaultConfig);
25
+
26
+ // Custom hook to use the sortable configuration context
27
+ export const useSortableConfig = () => useContext(ConfigContext);
28
+
29
+ // Configuration for animation settings
30
+ export const animationConfig = {
31
+ easing: Easing.inOut(Easing.ease),
32
+ duration: 350
33
+ };
34
+
35
+ // Helper function to calculate the item's position based on its index
36
+ // This is used to position items in a grid layout
37
+ export const getPosition = (position, COL, SIZE) => {
38
+ 'worklet';
39
+
40
+ // Necessary for Reanimated 2 to run this function on the UI thread
41
+ return {
42
+ x: position % COL === 0 ? 0 : SIZE * (position % COL),
43
+ y: Math.floor(position / COL) * SIZE
44
+ };
45
+ };
46
+
47
+ // Helper function to determine the new order of items during drag-and-drop
48
+ export const getOrder = (tx, ty, max, COL, SIZE) => {
49
+ 'worklet';
50
+
51
+ // Necessary for Reanimated 2 to run this function on the UI thread
52
+ const x = Math.round(tx / SIZE) * SIZE;
53
+ const y = Math.round(ty / SIZE) * SIZE;
54
+ const row = Math.max(y, 0) / SIZE;
55
+ const col = Math.max(x, 0) / SIZE;
56
+ return Math.min(row * COL + col, max);
57
+ };
58
+
59
+ /**
60
+ * SortableListProvider component
61
+ *
62
+ * Wrap your sortable list components with this provider to set custom configuration.
63
+ *
64
+ * @param {Object} config - Custom configuration to override the default settings.
65
+ * @param {number} config.MARGIN - Margin between items.
66
+ * @param {number} config.COL - Number of columns in the grid.
67
+ * @param {React.ReactNode} children - Child components that will use this configuration.
68
+ *
69
+ * Usage:
70
+ *
71
+ * <SortableListProvider config={{ MARGIN: 15, COL: 3 }}>
72
+ * <YourSortableList />
73
+ * </SortableListProvider>
74
+ */
75
+ const SortableListProvider = ({
76
+ children,
77
+ config
78
+ }) => {
79
+ // Merge custom config with the default configuration
80
+ const mergedConfig = {
81
+ ...defaultConfig,
82
+ ...config
83
+ };
84
+
85
+ // Recalculate SIZE based on COL and MARGIN
86
+ mergedConfig.SIZE = width / mergedConfig.COL - mergedConfig.MARGIN;
87
+ return /*#__PURE__*/_jsx(ConfigContext.Provider, {
88
+ value: mergedConfig,
89
+ children: children
90
+ });
91
+ };
92
+ export default SortableListProvider;
93
+ //# sourceMappingURL=Config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Dimensions","Easing","React","createContext","useContext","jsx","_jsx","width","get","defaultConfig","MARGIN","COL","SIZE","ConfigContext","useSortableConfig","animationConfig","easing","inOut","ease","duration","getPosition","position","x","y","Math","floor","getOrder","tx","ty","max","round","row","col","min","SortableListProvider","children","config","mergedConfig","Provider","value"],"sourceRoot":"../../src","sources":["Config.js"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,MAAM,QAAQ,yBAAyB;AAChD,OAAOC,KAAK,IAAIC,aAAa,EAAEC,UAAU,QAAQ,OAAO;;AAExD;AAAA,SAAAC,GAAA,IAAAC,IAAA;AACA,MAAM;EAAEC;AAAM,CAAC,GAAGP,UAAU,CAACQ,GAAG,CAAC,QAAQ,CAAC;;AAE1C;AACA,MAAMC,aAAa,GAAG;EACpBC,MAAM,EAAE,EAAE;EAAE;EACZC,GAAG,EAAE,CAAC;EAAE;EACR;EACAC,IAAI,EAAEL,KAAK,GAAG,CAAC,GAAG,EAAE,CAAE;AACxB,CAAC;;AAED;AACA,MAAMM,aAAa,gBAAGV,aAAa,CAACM,aAAa,CAAC;;AAElD;AACA,OAAO,MAAMK,iBAAiB,GAAGA,CAAA,KAAMV,UAAU,CAACS,aAAa,CAAC;;AAEhE;AACA,OAAO,MAAME,eAAe,GAAG;EAC7BC,MAAM,EAAEf,MAAM,CAACgB,KAAK,CAAChB,MAAM,CAACiB,IAAI,CAAC;EACjCC,QAAQ,EAAE;AACZ,CAAC;;AAED;AACA;AACA,OAAO,MAAMC,WAAW,GAAGA,CAACC,QAAQ,EAAEV,GAAG,EAAEC,IAAI,KAAK;EAClD,SAAS;;EAAE;EACX,OAAO;IACLU,CAAC,EAAED,QAAQ,GAAGV,GAA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AAoB","ignoreList":[]}
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+
3
+ import React, { useEffect } from 'react';
4
+ import { Dimensions, StyleSheet } from 'react-native';
5
+ import Animated, { useAnimatedGestureHandler, useAnimatedStyle, useAnimatedReaction, withSpring, scrollTo, withTiming, useSharedValue, runOnJS } from 'react-native-reanimated';
6
+ import { PanGestureHandler } from 'react-native-gesture-handler';
7
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
8
+ import { animationConfig, getOrder, getPosition } from "./Config.js";
9
+ import { useSortableConfig } from "./Config.js";
10
+
11
+ /**
12
+ * Item Component
13
+ *
14
+ * This component represents a draggable item in the sortable grid. It manages the gesture handling
15
+ * and animations needed to drag and reorder the item within the grid.
16
+ *
17
+ * Props:
18
+ * @param {React.ReactNode} children - The content to render inside the item.
19
+ * @param {object} positions - Shared value that contains the current positions of all items.
20
+ * @param {number} id - Unique identifier for the item.
21
+ * @param {function} onDragEnd - Callback function triggered when dragging ends.
22
+ * @param {object} scrollView - Reference to the scroll view for scrolling during drag.
23
+ * @param {object} scrollY - Shared value representing the current scroll position.
24
+ * @param {boolean} editing - Whether the list is in editing mode.
25
+ * @param {boolean} draggable - Whether the item is draggable (default: true).
26
+ * @param {Array} tiles - Array of tile items used to check reorderable state.
27
+ */
28
+ import { jsx as _jsx } from "react/jsx-runtime";
29
+ const Item = ({
30
+ children,
31
+ positions,
32
+ id,
33
+ onDragEnd,
34
+ scrollView,
35
+ scrollY,
36
+ editing,
37
+ draggable = true,
38
+ tiles
39
+ }) => {
40
+ // Get safe area insets for accurate height calculation
41
+ const inset = useSafeAreaInsets();
42
+ const containerHeight = Dimensions.get('window').height - inset.top - inset.bottom;
43
+
44
+ // Get the configuration for columns and size
45
+ const {
46
+ COL,
47
+ SIZE
48
+ } = useSortableConfig();
49
+
50
+ // Calculate content height based on the number of items
51
+ const contentHeight = Object.keys(positions.value).length / COL * SIZE;
52
+ const isGestureActive = useSharedValue(false); // Whether the item is being actively dragged
53
+
54
+ // Calculate initial position of the item
55
+ const position = getPosition(positions.value[id], COL, SIZE);
56
+ const translateX = useSharedValue(position.x);
57
+ const translateY = useSharedValue(position.y);
58
+
59
+ // Effect to reset isGestureActive when not in editing mode
60
+ useEffect(() => {
61
+ if (!editing) {
62
+ isGestureActive.value = false;
63
+ }
64
+ }, [editing, isGestureActive]);
65
+
66
+ // React to changes in the positions object
67
+ useAnimatedReaction(() => positions.value[id],
68
+ // Track changes to this item's position
69
+ newOrder => {
70
+ if (!isGestureActive.value) {
71
+ const pos = getPosition(newOrder, COL, SIZE);
72
+ translateX.value = withTiming(pos.x, animationConfig);
73
+ translateY.value = withTiming(pos.y, animationConfig);
74
+ }
75
+ });
76
+
77
+ // Gesture handler for dragging
78
+ const onGestureEvent = useAnimatedGestureHandler({
79
+ onStart: (_, ctx) => {
80
+ if (editing && draggable) {
81
+ // Store the starting position
82
+ ctx.x = translateX.value;
83
+ ctx.y = translateY.value;
84
+ isGestureActive.value = false; // TODO: Set to false when grouping is implemented
85
+ }
86
+ },
87
+ onActive: ({
88
+ translationX,
89
+ translationY
90
+ }, ctx) => {
91
+ if (editing && draggable) {
92
+ // Calculate new position
93
+ translateX.value = ctx.x + translationX;
94
+ translateY.value = ctx.y + translationY;
95
+
96
+ // Calculate new order based on position
97
+ const newOrder = getOrder(translateX.value, translateY.value, Object.keys(positions.value).length - 1, COL, SIZE);
98
+ const oldOrder = positions.value[id];
99
+ if (newOrder !== oldOrder) {
100
+ // Find the item to swap positions with
101
+ const idToSwap = Object.keys(positions.value).find(key => positions.value[key] === newOrder);
102
+
103
+ // Only swap if the target item is reorderable
104
+ const targetItem = tiles.find(tile => tile.id === Number(idToSwap));
105
+ if (idToSwap && targetItem?.reorderable !== false) {
106
+ const newPositions = {
107
+ ...positions.value
108
+ };
109
+ newPositions[id] = newOrder;
110
+ newPositions[idToSwap] = oldOrder;
111
+ positions.value = newPositions;
112
+ }
113
+ }
114
+
115
+ // Handle scrolling during drag
116
+ const lowerBound = scrollY.value;
117
+ const upperBound = lowerBound + containerHeight - SIZE;
118
+ const maxScroll = contentHeight - containerHeight;
119
+ const leftToScrollDown = maxScroll - scrollY.value;
120
+
121
+ // Scroll up
122
+ if (translateY.value < lowerBound) {
123
+ const diff = Math.min(lowerBound - translateY.value, lowerBound);
124
+ scrollY.value -= diff;
125
+ scrollTo(scrollView, 0, scrollY.value, false);
126
+ ctx.y -= diff;
127
+ translateY.value = ctx.y + translationY;
128
+ }
129
+ // Scroll down
130
+ if (translateY.value > upperBound) {
131
+ const diff = Math.min(translateY.value - upperBound, leftToScrollDown);
132
+ scrollY.value += diff;
133
+ scrollTo(scrollView, 0, scrollY.value, false);
134
+ ctx.y += diff;
135
+ translateY.value = ctx.y + translationY;
136
+ }
137
+ }
138
+ },
139
+ onEnd: () => {
140
+ if (draggable) {
141
+ // Snap the item back into its place when the drag ends
142
+ const newPosition = getPosition(positions.value[id], COL, SIZE);
143
+ translateX.value = withTiming(newPosition.x, animationConfig, () => {
144
+ isGestureActive.value = false; // Set gesture to inactive
145
+ runOnJS(onDragEnd)(positions.value); // Call onDragEnd on the JS thread
146
+ });
147
+ translateY.value = withTiming(newPosition.y, animationConfig);
148
+ }
149
+ }
150
+ });
151
+
152
+ // Animated style for the item
153
+ const style = useAnimatedStyle(() => {
154
+ const zIndex = isGestureActive.value ? 100 : 0; // Bring the item to front when active
155
+ const scale = editing && isGestureActive.value ? withSpring(1.05) : withSpring(1); // Slightly enlarge the item when dragging
156
+ return {
157
+ position: 'absolute',
158
+ top: 0,
159
+ left: 0,
160
+ width: SIZE,
161
+ height: SIZE,
162
+ zIndex,
163
+ transform: [{
164
+ translateX: translateX.value
165
+ }, {
166
+ translateY: translateY.value
167
+ }, {
168
+ scale
169
+ }]
170
+ };
171
+ });
172
+ return /*#__PURE__*/_jsx(Animated.View, {
173
+ style: style,
174
+ children: /*#__PURE__*/_jsx(PanGestureHandler, {
175
+ enabled: editing,
176
+ onGestureEvent: onGestureEvent,
177
+ children: /*#__PURE__*/_jsx(Animated.View, {
178
+ style: StyleSheet.absoluteFill,
179
+ children: children
180
+ })
181
+ })
182
+ });
183
+ };
184
+ export default Item;
185
+ //# sourceMappingURL=Item.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useEffect","Dimensions","StyleSheet","Animated","useAnimatedGestureHandler","useAnimatedStyle","useAnimatedReaction","withSpring","scrollTo","withTiming","useSharedValue","runOnJS","PanGestureHandler","useSafeAreaInsets","animationConfig","getOrder","getPosition","useSortableConfig","jsx","_jsx","Item","children","positions","id","onDragEnd","scrollView","scrollY","editing","draggable","tiles","inset","containerHeight","get","height","top","bottom","COL","SIZE","contentHeight","Object","keys","value","length","isGestureActive","position","translateX","x","translateY","y","newOrder","pos","onGestureEvent","onStart","_","ctx","onActive","translationX","translationY","oldOrder","idToSwap","find","key","targetItem","tile","Number","reorderable","newPositions","lowerBound","upperBound","maxScroll","leftToScrollDown","diff","Math","min","onEnd","newPosition","style","zIndex","scale","left","width","transform","View","enabled","absoluteFill"],"sourceRoot":"../../src","sources":["Item.js"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,SAASC,UAAU,EAAEC,UAAU,QAAQ,cAAc;AACrD,OAAOC,QAAQ,IACbC,yBAAyB,EACzBC,gBAAgB,EAChBC,mBAAmB,EACnBC,UAAU,EACVC,QAAQ,EACRC,UAAU,EACVC,cAAc,EACdC,OAAO,QACF,yBAAyB;AAChC,SAASC,iBAAiB,QAAQ,8BAA8B;AAChE,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,eAAe,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,aAAU;AACjE,SAASC,iBAAiB,QAAQ,aAAU;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAhBA,SAAAC,GAAA,IAAAC,IAAA;AAkBA,MAAMC,IAAI,GAAGA,CAAC;EACZC,QAAQ;EACRC,SAA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AEA,UAAU,CAACJ;MAAM,CAAC,EAChC;QAAEM,UAAU,EAAEA,UAAU,CAACN;MAAM,CAAC,EAChC;QAAEqC;MAAM,CAAC;IAEb,CAAC;EACH,CAAC,CAAC;EAEF,oBACE3D,IAAA,CAAChB,QAAQ,CAAC+E,IAAI;IAACN,KAAK,EAAEA,KAAM;IAAAvD,QAAA,eAC1BF,IAAA,CAACP,iBAAiB;MAACuE,OAAO,EAAExD,OAAQ;MAACwB,cAAc,EAAEA,cAAe;MAAA9B,QAAA,eAClEF,IAAA,CAAChB,QAAQ,CAAC+E,IAAI;QAACN,KAAK,EAAE1E,UAAU,CAACkF,YAAa;QAAA/D,QAAA,EAC3CA;MAAQ,CACI;IAAC,CACC;EAAC,CACP,CAAC;AAEpB,CAAC;AAED,eAAeD,IAAI","ignoreList":[]}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ import React, { memo } from 'react';
4
+ import Animated, { useAnimatedRef, useAnimatedScrollHandler, useSharedValue } from 'react-native-reanimated';
5
+ import Item from "./Item.js";
6
+ import { useSortableConfig } from "./Config.js";
7
+
8
+ /**
9
+ * SortableList Component
10
+ *
11
+ * This component renders a scrollable list of items that can be reordered using drag-and-drop gestures.
12
+ * It manages the overall layout of the items and provides the necessary props to each child `Item` component
13
+ * to enable dragging, scrolling, and reordering functionality.
14
+ *
15
+ * Props:
16
+ * @param {React.ReactNode[]} children - The list of items to render inside the sortable list.
17
+ * @param {boolean} editing - Whether the list is in editing mode, enabling drag-and-drop.
18
+ * @param {Array} tiles - Array of tile data to manage the reordering state.
19
+ * @param {function} onDragEnd - Callback function called with the updated positions when the drag ends.
20
+ *
21
+ * Usage:
22
+ *
23
+ * <SortableList editing={isEditing} tiles={tiles} onDragEnd={handleDragEnd}>
24
+ * {tiles.map((tile) => (
25
+ * <YourTileComponent key={tile.id} id={tile.id} />
26
+ * ))}
27
+ * </SortableList>
28
+ */
29
+ import { jsx as _jsx } from "react/jsx-runtime";
30
+ const SortableList = ({
31
+ children,
32
+ editing,
33
+ tiles,
34
+ onDragEnd
35
+ }) => {
36
+ // Get the configuration for columns and size from context
37
+ const {
38
+ COL,
39
+ SIZE
40
+ } = useSortableConfig();
41
+
42
+ // Shared values to track scrolling and item positions
43
+ const scrollY = useSharedValue(0); // Current scroll position
44
+ const scrollView = useAnimatedRef(); // Reference to the scroll view
45
+ const positions = useSharedValue(children.reduce((acc, child, index) => ({
46
+ ...acc,
47
+ [child.props.id]: index
48
+ }), {}));
49
+
50
+ // Scroll event handler to update scrollY shared value
51
+ const onScroll = useAnimatedScrollHandler({
52
+ onScroll: ({
53
+ contentOffset: {
54
+ y
55
+ }
56
+ }) => {
57
+ scrollY.value = y;
58
+ }
59
+ });
60
+ return /*#__PURE__*/_jsx(Animated.ScrollView, {
61
+ onScroll: onScroll,
62
+ ref: scrollView,
63
+ contentContainerStyle: {
64
+ // Calculate the total height needed for the scroll view content
65
+ height: Math.ceil(children.length / COL) * SIZE
66
+ },
67
+ showsVerticalScrollIndicator: false,
68
+ bounces: false,
69
+ scrollEventThrottle: 16 // Control scroll event frequency
70
+ ,
71
+ children: children.map(child => /*#__PURE__*/_jsx(Item, {
72
+ id: child.props.id,
73
+ positions: positions,
74
+ editing: editing,
75
+ draggable: child.props.draggable,
76
+ reorderable: child.props.reorderable,
77
+ tiles: tiles,
78
+ onDragEnd: onDragEnd,
79
+ scrollView: scrollView,
80
+ scrollY: scrollY,
81
+ children: child
82
+ }, child.props.id))
83
+ });
84
+ };
85
+ export default /*#__PURE__*/memo(SortableList);
86
+ //# sourceMappingURL=SortableList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","memo","Animated","useAnimatedRef","useAnimatedScrollHandler","useSharedValue","Item","useSortableConfig","jsx","_jsx","SortableList","children","editing","tiles","onDragEnd","COL","SIZE","scrollY","scrollView","positions","reduce","acc","child","index","props","id","onScroll","contentOffset","y","value","ScrollView","ref","contentContainerStyle","height","Math","ceil","length","showsVerticalScrollIndicator","bounces","scrollEventThrottle","map","draggable","reorderable"],"sourceRoot":"../../src","sources":["SortableList.js"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,IAAI,QAAQ,OAAO;AACnC,OAAOC,QAAQ,IACbC,cAAc,EACdC,wBAAwB,EACxBC,cAAc,QACT,yBAAyB;AAChC,OAAOC,IAAI,MAAM,WAAQ;AACzB,SAASC,iBAAiB,QAAQ,aAAU;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AApBA,SAAAC,GAAA,IAAAC,IAAA;AAsBA,MAAMC,YAAY,GAAGA,CAAC;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,KAAK;EAAEC;AAAU,CAAC,KAAK;EAChE;EACA,MAAM;IAAEC,GAAG;IAAEC;EAAK,CAAC,GAAGT,iBAAiB,CAAC,CAAC;;EAEzC;EACA,MAAMU,OAAO,GAAGZ,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;EACnC,MAAMa,UAAU,GAAGf,cAAc,CAAC,CAAC,CAAC,CAAC;EACrC,MAAMgB,SAAS,GAAGd,cAAc,CAC9BM,QAAQ,CAACS,MAAM,CACb,CAACC,GAAG,EAAEC,KAAK,EAAEC,KAAK,MAAM;IAAE,GAAGF,GAAG;IAAE,CAACC,KAAK,CAACE,KAAK,CAACC,EAAE,GAAGF;EAAM,CAAC,CAAC,EAC5D,CAAC,CACH,CACF,CAAC;;EAED;EACA,MAAMG,QAAQ,GAAGtB,wBAAwB,CAAC;IACxCsB,QAAQ,EAAEA,CAAC;MAAEC,aAAa,EAAE;QAAEC;MAAE;IAAE,CAAC,KAAK;MACtCX,OAAO,CAACY,KAAK,GAAGD,CAAC;IACnB;EACF,CAAC,CAAC;EAEF,oBACEnB,IAAA,CAACP,QAAQ,CAAC4B,UAAU;IAClBJ,QAAQ,EAAEA,QAAS;IACnBK,GAAG,EAAEb,UAAW;IAChBc,qBAAqB,EAAE;MACrB;MACAC,MAAM,EAAEC,IAAI,CAACC,IAAI,CAACxB,QAAQ,CAACyB,MAAM,GAAGrB,GAAG,CAAC,GAAGC;IAC7C,CAAE;IACFqB,4BAA4B,EAAE,KAAM;IACpCC,OAAO,EAAE,KAAM;IACfC,mBAAmB,EAAE,EAAG,CAAC;IAAA;IAAA5B,QAAA,EAGxBA,QAAQ,CAAC6B,GAAG,CAAElB,KAAK,iBAClBb,IAAA,CAACH,IAAI;MAEHmB,EAAE,EAAEH,KAAK,CAACE,KAAK,CAACC,EAAG;MACnBN,SAAS,EAAEA,SAAU;MACrBP,OAAO,EAAEA,OAAQ;MACjB6B,SAAS,EAAEnB,KAAK,CAACE,KAAK,CAACiB,SAAU;MACjCC,WAAW,EAAEpB,KAAK,CAACE,KAAK,CAACkB,WAAY;MACrC7B,KAAK,EAAEA,KAAM;MACbC,SAAS,EAAEA,SAAU;MACrBI,UAAU,EAAEA,UAAW;MACvBD,OAAO,EAAEA,OAAQ;MAAAN,QAAA,EAEhBW;IAAK,GAXDA,KAAK,CAACE,KAAK,CAACC,EAYb,CACP;EAAC,CACiB,CAAC;AAE1B,CAAC;AAED,4BAAexB,IAAI,CAACS,YAAY,CAAC","ignoreList":[]}
@@ -0,0 +1,53 @@
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
@@ -0,0 +1 @@
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":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ export { default as SortableListProvider } from "./Config.js";
4
+ export { default as SortableList } from "./SortableList.js";
5
+ export { default as Tile } from "./Tile.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["default","SortableListProvider","SortableList","Tile"],"sourceRoot":"../../src","sources":["index.js"],"mappings":";;AAAA,SAASA,OAAO,IAAIC,oBAAoB,QAAQ,aAAU;AAC1D,SAASD,OAAO,IAAIE,YAAY,QAAQ,mBAAgB;AACxD,SAASF,OAAO,IAAIG,IAAI,QAAQ,WAAQ","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1 @@
1
+ {"type":"module"}