react-native-reorderable-list 0.4.0 → 0.5.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.
Files changed (162) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +118 -60
  3. package/lib/commonjs/components/ReorderableList/ReorderableList.js +91 -0
  4. package/lib/commonjs/components/ReorderableList/ReorderableList.js.map +1 -0
  5. package/lib/commonjs/components/ReorderableList/constants.ios.js +10 -0
  6. package/lib/commonjs/components/ReorderableList/constants.ios.js.map +1 -0
  7. package/lib/commonjs/components/ReorderableList/constants.js +10 -0
  8. package/lib/commonjs/components/ReorderableList/constants.js.map +1 -0
  9. package/lib/commonjs/components/ReorderableList/index.js +17 -0
  10. package/lib/commonjs/components/ReorderableList/index.js.map +1 -0
  11. package/lib/commonjs/components/ReorderableList/useReorderableList.js +313 -0
  12. package/lib/commonjs/components/ReorderableList/useReorderableList.js.map +1 -0
  13. package/lib/commonjs/components/ReorderableListCell.js +93 -0
  14. package/lib/commonjs/components/ReorderableListCell.js.map +1 -0
  15. package/lib/commonjs/components/ReorderableListItem.js +87 -0
  16. package/lib/commonjs/components/ReorderableListItem.js.map +1 -0
  17. package/lib/commonjs/components/index.js +39 -0
  18. package/lib/commonjs/components/index.js.map +1 -0
  19. package/lib/commonjs/contexts/ReorderableCellContext.js +10 -0
  20. package/lib/commonjs/contexts/ReorderableCellContext.js.map +1 -0
  21. package/lib/commonjs/contexts/ReorderableListContext.js +10 -0
  22. package/lib/commonjs/contexts/ReorderableListContext.js.map +1 -0
  23. package/lib/commonjs/contexts/index.js +28 -0
  24. package/lib/commonjs/contexts/index.js.map +1 -0
  25. package/lib/commonjs/hooks/index.js +50 -0
  26. package/lib/commonjs/hooks/index.js.map +1 -0
  27. package/lib/commonjs/hooks/useContext.js +16 -0
  28. package/lib/commonjs/hooks/useContext.js.map +1 -0
  29. package/lib/commonjs/hooks/useReorderableDrag.js +16 -0
  30. package/lib/commonjs/hooks/useReorderableDrag.js.map +1 -0
  31. package/lib/commonjs/hooks/useReorderableDragEnd.js +25 -0
  32. package/lib/commonjs/hooks/useReorderableDragEnd.js.map +1 -0
  33. package/lib/commonjs/hooks/useReorderableDragStart.js +22 -0
  34. package/lib/commonjs/hooks/useReorderableDragStart.js.map +1 -0
  35. package/lib/commonjs/index.js +41 -0
  36. package/lib/commonjs/index.js.map +1 -0
  37. package/lib/commonjs/types/index.js +28 -0
  38. package/lib/commonjs/types/index.js.map +1 -0
  39. package/lib/commonjs/types/misc.js +14 -0
  40. package/lib/commonjs/types/misc.js.map +1 -0
  41. package/lib/commonjs/types/props.js +6 -0
  42. package/lib/commonjs/types/props.js.map +1 -0
  43. package/lib/commonjs/utils.js +23 -0
  44. package/lib/commonjs/utils.js.map +1 -0
  45. package/lib/module/components/ReorderableList/ReorderableList.js +83 -0
  46. package/lib/module/components/ReorderableList/ReorderableList.js.map +1 -0
  47. package/lib/module/components/ReorderableList/constants.ios.js +4 -0
  48. package/lib/module/components/ReorderableList/constants.ios.js.map +1 -0
  49. package/lib/module/components/ReorderableList/constants.js +4 -0
  50. package/lib/module/components/ReorderableList/constants.js.map +1 -0
  51. package/lib/module/components/ReorderableList/index.js +2 -0
  52. package/lib/module/components/ReorderableList/index.js.map +1 -0
  53. package/lib/module/components/ReorderableList/useReorderableList.js +304 -0
  54. package/lib/module/components/ReorderableList/useReorderableList.js.map +1 -0
  55. package/lib/module/components/ReorderableListCell.js +85 -0
  56. package/lib/module/components/ReorderableListCell.js.map +1 -0
  57. package/lib/module/components/ReorderableListItem.js +78 -0
  58. package/lib/module/components/ReorderableListItem.js.map +1 -0
  59. package/lib/module/components/index.js +4 -0
  60. package/lib/module/components/index.js.map +1 -0
  61. package/lib/module/contexts/ReorderableCellContext.js +3 -0
  62. package/lib/module/contexts/ReorderableCellContext.js.map +1 -0
  63. package/lib/module/contexts/ReorderableListContext.js +3 -0
  64. package/lib/module/contexts/ReorderableListContext.js.map +1 -0
  65. package/lib/module/contexts/index.js +3 -0
  66. package/lib/module/contexts/index.js.map +1 -0
  67. package/lib/module/hooks/index.js +5 -0
  68. package/lib/module/hooks/index.js.map +1 -0
  69. package/lib/module/hooks/useContext.js +9 -0
  70. package/lib/module/hooks/useContext.js.map +1 -0
  71. package/lib/module/hooks/useReorderableDrag.js +9 -0
  72. package/lib/module/hooks/useReorderableDrag.js.map +1 -0
  73. package/lib/module/hooks/useReorderableDragEnd.js +18 -0
  74. package/lib/module/hooks/useReorderableDragEnd.js.map +1 -0
  75. package/lib/module/hooks/useReorderableDragStart.js +15 -0
  76. package/lib/module/hooks/useReorderableDragStart.js.map +1 -0
  77. package/lib/module/index.js +6 -0
  78. package/lib/module/index.js.map +1 -0
  79. package/lib/module/types/index.js +3 -0
  80. package/lib/module/types/index.js.map +1 -0
  81. package/lib/module/types/misc.js +8 -0
  82. package/lib/module/types/misc.js.map +1 -0
  83. package/lib/module/types/props.js +2 -0
  84. package/lib/module/types/props.js.map +1 -0
  85. package/lib/module/utils.js +16 -0
  86. package/lib/module/utils.js.map +1 -0
  87. package/lib/typescript/components/ReorderableList/ReorderableList.d.ts +8 -0
  88. package/lib/typescript/components/ReorderableList/ReorderableList.d.ts.map +1 -0
  89. package/lib/typescript/components/ReorderableList/constants.d.ts +3 -0
  90. package/lib/typescript/components/ReorderableList/constants.d.ts.map +1 -0
  91. package/lib/typescript/components/ReorderableList/constants.ios.d.ts +3 -0
  92. package/lib/typescript/components/ReorderableList/constants.ios.d.ts.map +1 -0
  93. package/lib/typescript/components/ReorderableList/index.d.ts +2 -0
  94. package/lib/typescript/components/ReorderableList/index.d.ts.map +1 -0
  95. package/lib/typescript/components/ReorderableList/useReorderableList.d.ts +34 -0
  96. package/lib/typescript/components/ReorderableList/useReorderableList.d.ts.map +1 -0
  97. package/lib/typescript/components/ReorderableListCell.d.ts +15 -0
  98. package/lib/typescript/components/ReorderableListCell.d.ts.map +1 -0
  99. package/lib/typescript/components/ReorderableListItem.d.ts +4 -0
  100. package/lib/typescript/components/ReorderableListItem.d.ts.map +1 -0
  101. package/lib/typescript/components/index.d.ts +4 -0
  102. package/lib/typescript/components/index.d.ts.map +1 -0
  103. package/lib/typescript/contexts/ReorderableCellContext.d.ts +11 -0
  104. package/lib/typescript/contexts/ReorderableCellContext.d.ts.map +1 -0
  105. package/lib/typescript/contexts/ReorderableListContext.d.ts +9 -0
  106. package/lib/typescript/contexts/ReorderableListContext.d.ts.map +1 -0
  107. package/lib/typescript/contexts/index.d.ts +3 -0
  108. package/lib/typescript/contexts/index.d.ts.map +1 -0
  109. package/lib/typescript/hooks/index.d.ts +5 -0
  110. package/lib/typescript/hooks/index.d.ts.map +1 -0
  111. package/lib/typescript/hooks/useContext.d.ts +3 -0
  112. package/lib/typescript/hooks/useContext.d.ts.map +1 -0
  113. package/lib/typescript/hooks/useReorderableDrag.d.ts +2 -0
  114. package/lib/typescript/hooks/useReorderableDrag.d.ts.map +1 -0
  115. package/lib/typescript/hooks/useReorderableDragEnd.d.ts +2 -0
  116. package/lib/typescript/hooks/useReorderableDragEnd.d.ts.map +1 -0
  117. package/lib/typescript/hooks/useReorderableDragStart.d.ts +2 -0
  118. package/lib/typescript/hooks/useReorderableDragStart.d.ts.map +1 -0
  119. package/lib/typescript/index.d.ts +7 -0
  120. package/lib/typescript/index.d.ts.map +1 -0
  121. package/lib/typescript/types/index.d.ts +3 -0
  122. package/lib/typescript/types/index.d.ts.map +1 -0
  123. package/lib/typescript/types/misc.d.ts +7 -0
  124. package/lib/typescript/types/misc.d.ts.map +1 -0
  125. package/lib/typescript/types/props.d.ts +90 -0
  126. package/lib/typescript/types/props.d.ts.map +1 -0
  127. package/lib/typescript/utils.d.ts +12 -0
  128. package/lib/typescript/utils.d.ts.map +1 -0
  129. package/package.json +199 -36
  130. package/src/components/ReorderableList/ReorderableList.tsx +117 -0
  131. package/src/components/ReorderableList/constants.ios.ts +3 -0
  132. package/src/components/ReorderableList/constants.ts +3 -0
  133. package/src/components/ReorderableList/index.ts +1 -0
  134. package/src/components/ReorderableList/useReorderableList.ts +489 -0
  135. package/src/components/ReorderableListCell.tsx +138 -0
  136. package/src/components/ReorderableListItem.tsx +108 -0
  137. package/src/components/index.ts +3 -0
  138. package/src/contexts/ReorderableCellContext.ts +14 -0
  139. package/src/contexts/ReorderableListContext.ts +12 -0
  140. package/src/contexts/index.ts +2 -0
  141. package/src/hooks/index.ts +4 -0
  142. package/src/hooks/useContext.ts +11 -0
  143. package/src/hooks/useReorderableDrag.ts +7 -0
  144. package/src/hooks/useReorderableDragEnd.ts +21 -0
  145. package/src/hooks/useReorderableDragStart.ts +18 -0
  146. package/src/index.ts +26 -0
  147. package/src/types/index.ts +2 -0
  148. package/src/types/misc.ts +6 -0
  149. package/src/types/props.ts +101 -0
  150. package/src/utils.ts +15 -0
  151. package/dist/components/ReorderableList.d.ts +0 -7
  152. package/dist/components/ReorderableList.js +0 -314
  153. package/dist/components/ReorderableListItem.d.ts +0 -14
  154. package/dist/components/ReorderableListItem.js +0 -57
  155. package/dist/hooks/useAnimatedSharedValues.d.ts +0 -3
  156. package/dist/hooks/useAnimatedSharedValues.js +0 -33
  157. package/dist/index.d.ts +0 -4
  158. package/dist/index.js +0 -2
  159. package/dist/types/misc.d.ts +0 -15
  160. package/dist/types/misc.js +0 -7
  161. package/dist/types/props.d.ts +0 -29
  162. package/dist/types/props.js +0 -1
@@ -0,0 +1,108 @@
1
+ import React, {useCallback, useMemo} from 'react';
2
+
3
+ import Animated, {
4
+ Easing,
5
+ useAnimatedStyle,
6
+ useSharedValue,
7
+ withTiming,
8
+ } from 'react-native-reanimated';
9
+
10
+ import {useReorderableDragEnd, useReorderableDragStart} from '../hooks';
11
+ import type {ReorderableListItemProps} from '../types';
12
+
13
+ const scaleDefaultConfig = {
14
+ enabled: true,
15
+ valueEnd: 1,
16
+ valueStart: 1.025,
17
+ easingStart: Easing.in(Easing.ease),
18
+ easingEnd: Easing.out(Easing.ease),
19
+ duration: 200,
20
+ };
21
+
22
+ const opacityDefaultConfig = {
23
+ enabled: true,
24
+ valueEnd: 1,
25
+ valueStart: 0.75,
26
+ easingStart: Easing.in(Easing.ease),
27
+ easingEnd: Easing.out(Easing.ease),
28
+ duration: 200,
29
+ };
30
+
31
+ export const ReorderableListItem: React.FC<ReorderableListItemProps> = ({
32
+ scaleAnimationConfig = scaleDefaultConfig,
33
+ opacityAnimationConfig = opacityDefaultConfig,
34
+ ...rest
35
+ }) => {
36
+ const scaleConfigWithDefaults = useMemo(
37
+ () => ({
38
+ ...scaleDefaultConfig,
39
+ ...scaleAnimationConfig,
40
+ }),
41
+ [scaleAnimationConfig],
42
+ );
43
+ const opacityConfigWithDefaults = useMemo(
44
+ () => ({
45
+ ...opacityDefaultConfig,
46
+ ...opacityAnimationConfig,
47
+ }),
48
+ [opacityAnimationConfig],
49
+ );
50
+ const scale = useSharedValue(
51
+ scaleConfigWithDefaults.enabled ? scaleConfigWithDefaults.valueEnd : 1,
52
+ );
53
+ const opacity = useSharedValue(
54
+ opacityConfigWithDefaults.enabled ? opacityConfigWithDefaults.valueEnd : 1,
55
+ );
56
+
57
+ useReorderableDragStart(
58
+ useCallback(() => {
59
+ 'worklet';
60
+ if (scaleConfigWithDefaults.enabled) {
61
+ scale.value = withTiming(scaleConfigWithDefaults.valueStart, {
62
+ easing: scaleConfigWithDefaults.easingStart,
63
+ duration: scaleConfigWithDefaults.duration,
64
+ });
65
+ }
66
+
67
+ if (opacityConfigWithDefaults.enabled) {
68
+ opacity.value = withTiming(opacityConfigWithDefaults.valueStart, {
69
+ easing: opacityConfigWithDefaults.easingStart,
70
+ duration: opacityConfigWithDefaults.duration,
71
+ });
72
+ }
73
+ }, [opacity, scale, opacityConfigWithDefaults, scaleConfigWithDefaults]),
74
+ );
75
+
76
+ useReorderableDragEnd(
77
+ useCallback(() => {
78
+ 'worklet';
79
+ if (scaleConfigWithDefaults.enabled) {
80
+ scale.value = withTiming(scaleConfigWithDefaults.valueEnd, {
81
+ easing: scaleConfigWithDefaults.easingEnd,
82
+ duration: scaleConfigWithDefaults.duration,
83
+ });
84
+ }
85
+
86
+ if (opacityConfigWithDefaults.enabled) {
87
+ opacity.value = withTiming(opacityConfigWithDefaults.valueEnd, {
88
+ easing: opacityConfigWithDefaults.easingEnd,
89
+ duration: opacityConfigWithDefaults.duration,
90
+ });
91
+ }
92
+ }, [opacity, scale, opacityConfigWithDefaults, scaleConfigWithDefaults]),
93
+ );
94
+
95
+ const animatedStyle = useAnimatedStyle(
96
+ () => ({
97
+ transform: [
98
+ {
99
+ scale: scale.value,
100
+ },
101
+ ],
102
+ opacity: opacity.value,
103
+ }),
104
+ [scale, opacity],
105
+ );
106
+
107
+ return <Animated.View {...rest} style={[animatedStyle, rest.style]} />;
108
+ };
@@ -0,0 +1,3 @@
1
+ export * from './ReorderableList';
2
+ export * from './ReorderableListCell';
3
+ export * from './ReorderableListItem';
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+
3
+ import type {SharedValue} from 'react-native-reanimated';
4
+
5
+ interface ReorderableCellContextData {
6
+ index: number;
7
+ dragHandler: () => void;
8
+ draggedIndex: SharedValue<number>;
9
+ releasedIndex: SharedValue<number>;
10
+ }
11
+
12
+ export const ReorderableCellContext = React.createContext<
13
+ ReorderableCellContextData | undefined
14
+ >(undefined);
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+
3
+ import type {SharedValue} from 'react-native-reanimated';
4
+
5
+ interface ReorderableListContextData {
6
+ currentIndex: SharedValue<number>;
7
+ draggedHeight: SharedValue<number>;
8
+ }
9
+
10
+ export const ReorderableListContext = React.createContext<
11
+ ReorderableListContextData | undefined
12
+ >(undefined);
@@ -0,0 +1,2 @@
1
+ export * from './ReorderableCellContext';
2
+ export * from './ReorderableListContext';
@@ -0,0 +1,4 @@
1
+ export * from './useReorderableDrag';
2
+ export * from './useReorderableDragStart';
3
+ export * from './useReorderableDragEnd';
4
+ export * from './useContext';
@@ -0,0 +1,11 @@
1
+ import {useContext as useReactContext} from 'react';
2
+
3
+ export const useContext = <T>(context: React.Context<T | undefined>) => {
4
+ const value = useReactContext(context);
5
+
6
+ if (value !== undefined) {
7
+ return value;
8
+ }
9
+
10
+ throw 'Please consume ReorderableList context within its provider.';
11
+ };
@@ -0,0 +1,7 @@
1
+ import {useContext} from './useContext';
2
+ import {ReorderableCellContext} from '../contexts';
3
+
4
+ export const useReorderableDrag = () => {
5
+ const {dragHandler} = useContext(ReorderableCellContext);
6
+ return dragHandler;
7
+ };
@@ -0,0 +1,21 @@
1
+ import {useAnimatedReaction} from 'react-native-reanimated';
2
+
3
+ import {useContext} from './useContext';
4
+ import {ReorderableCellContext, ReorderableListContext} from '../contexts';
5
+
6
+ export const useReorderableDragEnd = (
7
+ onEnd: (from: number, to: number) => void,
8
+ ) => {
9
+ const {currentIndex} = useContext(ReorderableListContext);
10
+ const {releasedIndex, index} = useContext(ReorderableCellContext);
11
+
12
+ useAnimatedReaction(
13
+ () => releasedIndex.value === index,
14
+ newValue => {
15
+ if (newValue) {
16
+ onEnd(index, currentIndex.value);
17
+ }
18
+ },
19
+ [onEnd],
20
+ );
21
+ };
@@ -0,0 +1,18 @@
1
+ import {useAnimatedReaction} from 'react-native-reanimated';
2
+
3
+ import {useContext} from './useContext';
4
+ import {ReorderableCellContext} from '../contexts';
5
+
6
+ export const useReorderableDragStart = (onStart: (index: number) => void) => {
7
+ const {draggedIndex, index} = useContext(ReorderableCellContext);
8
+
9
+ useAnimatedReaction(
10
+ () => draggedIndex.value === index,
11
+ newValue => {
12
+ if (newValue && onStart) {
13
+ onStart(index);
14
+ }
15
+ },
16
+ [onStart],
17
+ );
18
+ };
package/src/index.ts ADDED
@@ -0,0 +1,26 @@
1
+ import {ReorderableList, ReorderableListItem} from './components';
2
+ import {
3
+ useReorderableDrag,
4
+ useReorderableDragEnd,
5
+ useReorderableDragStart,
6
+ } from './hooks';
7
+ import type {
8
+ ReorderableListItemConfig,
9
+ ReorderableListItemProps,
10
+ ReorderableListProps,
11
+ ReorderableListReorderEvent,
12
+ } from './types';
13
+ import {reorderItems} from './utils';
14
+
15
+ export {
16
+ useReorderableDrag,
17
+ useReorderableDragStart,
18
+ useReorderableDragEnd,
19
+ ReorderableListProps,
20
+ ReorderableListReorderEvent,
21
+ ReorderableListItem,
22
+ ReorderableListItemConfig,
23
+ ReorderableListItemProps,
24
+ reorderItems,
25
+ };
26
+ export default ReorderableList;
@@ -0,0 +1,2 @@
1
+ export * from './props';
2
+ export * from './misc';
@@ -0,0 +1,6 @@
1
+ export enum ReorderableListState {
2
+ IDLE = 0,
3
+ DRAGGING,
4
+ RELEASING,
5
+ AUTO_SCROLL,
6
+ }
@@ -0,0 +1,101 @@
1
+ import type {FlatListProps, NativeScrollEvent, ViewProps} from 'react-native';
2
+
3
+ import {EasingFunction} from 'react-native-reanimated';
4
+
5
+ export interface ReorderableListReorderEvent {
6
+ /**
7
+ * Index of the dragged item.
8
+ */
9
+ from: number;
10
+ /**
11
+ * Index where the dragged item was released.
12
+ */
13
+ to: number;
14
+ }
15
+
16
+ type OmittedProps =
17
+ | 'horizontal'
18
+ | 'onScroll'
19
+ | 'scrollEventThrottle'
20
+ | 'removeClippedSubviews'
21
+ | 'CellRendererComponent'
22
+ | 'numColumns';
23
+
24
+ export interface ReorderableListProps<T>
25
+ extends Omit<FlatListProps<T>, OmittedProps> {
26
+ data: T[];
27
+ /**
28
+ * Threshold at the extremety of the list which triggers autoscroll when an item is dragged to it.
29
+ * A value of 0.1 means that 10% of the area at the top and 10% at the bottom of the list will trigger autoscroll
30
+ * when an item is dragged to it. Min value: `0`. Max value: `0.4`. Default: `0.1`.
31
+ */
32
+ autoscrollThreshold?: number;
33
+ /**
34
+ * Scales the autoscroll spreed at which the list scrolls when an item is dragged to the scroll areas. Default: `1`.
35
+ */
36
+ autoscrollSpeedScale?: number;
37
+ /**
38
+ * Delay in between autoscroll triggers. Can be used to tune the autoscroll smoothness.
39
+ * Default Android: `0`.
40
+ * Default iOS: `100`.
41
+ */
42
+ autoscrollDelay?: number;
43
+ /**
44
+ * Specifies the fraction of an item's size at which it will shift when a dragged item crosses over it.
45
+ * For example, a value of 0.2 means the item shifts when the dragged item passes 20% of its height (vertical list). Default is `0.2`.
46
+ */
47
+ dragReorderThreshold?: number;
48
+ /**
49
+ * Duration of the animations in milliseconds.
50
+ * Be aware that users won't be able to drag a new item until the dragged item is released and
51
+ * its animation to its new position ends.
52
+ * Default: `200`.
53
+ */
54
+ animationDuration?: number;
55
+ /**
56
+ * Event fired after an item is released and the list is reordered.
57
+ */
58
+ onReorder: (event: ReorderableListReorderEvent) => void;
59
+ /**
60
+ * Event fired at most once per frame during scrolling. Needs to be a `worklet`. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info.
61
+ */
62
+ onScroll?: (event: NativeScrollEvent) => void;
63
+ }
64
+
65
+ export interface ReorderableListItemConfig {
66
+ /**
67
+ * Value of the animated style on drag end.
68
+ */
69
+ enabled?: boolean;
70
+ /**
71
+ * Value of the animated style on drag end.
72
+ */
73
+ valueEnd?: number;
74
+ /**
75
+ * Value of the animated style on drag start.
76
+ */
77
+ valueStart?: number;
78
+ /**
79
+ * Easing function for the animation to the end value. Default: `Easing.in(Easing.ease)`.
80
+ */
81
+ easingEnd?: EasingFunction;
82
+ /**
83
+ * Easing function for the animation to the start value. Default: `Easing.out(Easing.ease)`.
84
+ */
85
+ easingStart?: EasingFunction;
86
+ /**
87
+ * Duration of the animations in milliseconds. Default: `200`.
88
+ */
89
+ duration?: number;
90
+ }
91
+
92
+ export interface ReorderableListItemProps extends ViewProps {
93
+ /**
94
+ * Config for the `opacity` animation. Enabled by default with custom default options.
95
+ */
96
+ opacityAnimationConfig?: ReorderableListItemConfig;
97
+ /**
98
+ * Config for the `scale` animation. Enabled by default with custom default options.
99
+ */
100
+ scaleAnimationConfig?: ReorderableListItemConfig;
101
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Moves an item in an array to a new index.
3
+ *
4
+ * @template T - The type of elements in the array.
5
+ * @param data - The array of items.
6
+ * @param from - The index of the item to move.
7
+ * @param to - The index to move the item to.
8
+ *
9
+ * @returns A new array with the two items swapped.
10
+ */
11
+ export const reorderItems = <T>(data: T[], from: number, to: number): T[] => {
12
+ const newData = [...data];
13
+ newData.splice(to, 0, newData.splice(from, 1)[0]);
14
+ return newData;
15
+ };
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- import { FlatListProps } from 'react-native';
3
- import { ReorderableListProps } from '../types/props';
4
- declare const _default: <T>(props: ReorderableListProps<T> & {
5
- ref?: React.ForwardedRef<FlatListProps<T>> | undefined;
6
- }) => React.ReactElement;
7
- export default _default;