react-native-sortable-dynamic 0.1.1 → 0.2.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.
Files changed (43) hide show
  1. package/README.md +54 -50
  2. package/lib/commonjs/Config.js +12 -12
  3. package/lib/commonjs/Config.js.map +1 -1
  4. package/lib/commonjs/{SortableList.js → SortableContainer.js} +55 -31
  5. package/lib/commonjs/SortableContainer.js.map +1 -0
  6. package/lib/commonjs/SortableItem.js +61 -0
  7. package/lib/commonjs/SortableItem.js.map +1 -0
  8. package/lib/commonjs/{Item.js → SortableItemWrapper.js} +31 -16
  9. package/lib/commonjs/SortableItemWrapper.js.map +1 -0
  10. package/lib/commonjs/SortableView.js +70 -0
  11. package/lib/commonjs/SortableView.js.map +1 -0
  12. package/lib/commonjs/index.js +3 -17
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/module/Config.js +12 -12
  15. package/lib/module/Config.js.map +1 -1
  16. package/lib/module/SortableContainer.js +110 -0
  17. package/lib/module/SortableContainer.js.map +1 -0
  18. package/lib/module/SortableItem.js +58 -0
  19. package/lib/module/SortableItem.js.map +1 -0
  20. package/lib/module/{Item.js → SortableItemWrapper.js} +31 -16
  21. package/lib/module/SortableItemWrapper.js.map +1 -0
  22. package/lib/module/SortableView.js +67 -0
  23. package/lib/module/SortableView.js.map +1 -0
  24. package/lib/module/index.js +1 -3
  25. package/lib/module/index.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/Config.js +12 -12
  28. package/src/SortableContainer.js +110 -0
  29. package/src/SortableItem.js +57 -0
  30. package/src/{Item.js → SortableItemWrapper.js} +30 -16
  31. package/src/SortableView.js +65 -0
  32. package/src/index.js +1 -3
  33. package/lib/commonjs/Item.js.map +0 -1
  34. package/lib/commonjs/SortableList.js.map +0 -1
  35. package/lib/commonjs/Tile.js +0 -56
  36. package/lib/commonjs/Tile.js.map +0 -1
  37. package/lib/module/Item.js.map +0 -1
  38. package/lib/module/SortableList.js +0 -86
  39. package/lib/module/SortableList.js.map +0 -1
  40. package/lib/module/Tile.js +0 -53
  41. package/lib/module/Tile.js.map +0 -1
  42. package/src/SortableList.js +0 -86
  43. package/src/Tile.js +0 -47
@@ -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;