react-native-reorderable-list 0.6.1 → 0.7.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 (118) hide show
  1. package/README.md +28 -3
  2. package/lib/commonjs/components/NestedReorderableList.js +41 -0
  3. package/lib/commonjs/components/NestedReorderableList.js.map +1 -0
  4. package/lib/commonjs/components/ReorderableList.js +29 -0
  5. package/lib/commonjs/components/ReorderableList.js.map +1 -0
  6. package/lib/commonjs/components/ReorderableListCell.js +1 -3
  7. package/lib/commonjs/components/ReorderableListCell.js.map +1 -1
  8. package/lib/commonjs/components/{ReorderableList/ReorderableList.js → ReorderableListCore/ReorderableListCore.js} +35 -10
  9. package/lib/commonjs/components/ReorderableListCore/ReorderableListCore.js.map +1 -0
  10. package/lib/commonjs/components/ReorderableListCore/constants.js +31 -0
  11. package/lib/commonjs/components/ReorderableListCore/constants.js.map +1 -0
  12. package/lib/commonjs/components/ReorderableListCore/index.js +17 -0
  13. package/lib/commonjs/components/ReorderableListCore/index.js.map +1 -0
  14. package/lib/commonjs/components/{ReorderableList/useReorderableList.js → ReorderableListCore/useReorderableListCore.js} +176 -70
  15. package/lib/commonjs/components/ReorderableListCore/useReorderableListCore.js.map +1 -0
  16. package/lib/commonjs/components/ScrollViewContainer.js +53 -0
  17. package/lib/commonjs/components/ScrollViewContainer.js.map +1 -0
  18. package/lib/commonjs/components/index.js +22 -0
  19. package/lib/commonjs/components/index.js.map +1 -1
  20. package/lib/commonjs/contexts/ScrollViewContainerContext.js +10 -0
  21. package/lib/commonjs/contexts/ScrollViewContainerContext.js.map +1 -0
  22. package/lib/commonjs/contexts/index.js +11 -0
  23. package/lib/commonjs/contexts/index.js.map +1 -1
  24. package/lib/commonjs/index.js +12 -0
  25. package/lib/commonjs/index.js.map +1 -1
  26. package/lib/module/components/NestedReorderableList.js +33 -0
  27. package/lib/module/components/NestedReorderableList.js.map +1 -0
  28. package/lib/module/components/ReorderableList.js +21 -0
  29. package/lib/module/components/ReorderableList.js.map +1 -0
  30. package/lib/module/components/ReorderableListCell.js +1 -3
  31. package/lib/module/components/ReorderableListCell.js.map +1 -1
  32. package/lib/module/components/{ReorderableList/ReorderableList.js → ReorderableListCore/ReorderableListCore.js} +39 -14
  33. package/lib/module/components/ReorderableListCore/ReorderableListCore.js.map +1 -0
  34. package/lib/module/components/ReorderableListCore/constants.js +25 -0
  35. package/lib/module/components/ReorderableListCore/constants.js.map +1 -0
  36. package/lib/module/components/ReorderableListCore/index.js +2 -0
  37. package/lib/module/components/ReorderableListCore/index.js.map +1 -0
  38. package/lib/module/components/{ReorderableList/useReorderableList.js → ReorderableListCore/useReorderableListCore.js} +177 -71
  39. package/lib/module/components/ReorderableListCore/useReorderableListCore.js.map +1 -0
  40. package/lib/module/components/ScrollViewContainer.js +44 -0
  41. package/lib/module/components/ScrollViewContainer.js.map +1 -0
  42. package/lib/module/components/index.js +2 -0
  43. package/lib/module/components/index.js.map +1 -1
  44. package/lib/module/contexts/ScrollViewContainerContext.js +3 -0
  45. package/lib/module/contexts/ScrollViewContainerContext.js.map +1 -0
  46. package/lib/module/contexts/index.js +1 -0
  47. package/lib/module/contexts/index.js.map +1 -1
  48. package/lib/module/index.js +2 -2
  49. package/lib/module/index.js.map +1 -1
  50. package/lib/typescript/components/NestedReorderableList.d.ts +5 -0
  51. package/lib/typescript/components/NestedReorderableList.d.ts.map +1 -0
  52. package/lib/typescript/components/ReorderableList.d.ts +5 -0
  53. package/lib/typescript/components/ReorderableList.d.ts.map +1 -0
  54. package/lib/typescript/components/ReorderableListCell.d.ts.map +1 -1
  55. package/lib/typescript/components/ReorderableListCore/ReorderableListCore.d.ts +20 -0
  56. package/lib/typescript/components/ReorderableListCore/ReorderableListCore.d.ts.map +1 -0
  57. package/lib/typescript/components/ReorderableListCore/constants.d.ts +6 -0
  58. package/lib/typescript/components/ReorderableListCore/constants.d.ts.map +1 -0
  59. package/lib/typescript/components/ReorderableListCore/index.d.ts +2 -0
  60. package/lib/typescript/components/ReorderableListCore/index.d.ts.map +1 -0
  61. package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts +44 -0
  62. package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts.map +1 -0
  63. package/lib/typescript/components/ScrollViewContainer.d.ts +4 -0
  64. package/lib/typescript/components/ScrollViewContainer.d.ts.map +1 -0
  65. package/lib/typescript/components/index.d.ts +2 -0
  66. package/lib/typescript/components/index.d.ts.map +1 -1
  67. package/lib/typescript/contexts/ScrollViewContainerContext.d.ts +15 -0
  68. package/lib/typescript/contexts/ScrollViewContainerContext.d.ts.map +1 -0
  69. package/lib/typescript/contexts/index.d.ts +1 -0
  70. package/lib/typescript/contexts/index.d.ts.map +1 -1
  71. package/lib/typescript/index.d.ts +3 -3
  72. package/lib/typescript/index.d.ts.map +1 -1
  73. package/lib/typescript/types/props.d.ts +13 -1
  74. package/lib/typescript/types/props.d.ts.map +1 -1
  75. package/package.json +15 -7
  76. package/src/components/NestedReorderableList.tsx +43 -0
  77. package/src/components/ReorderableList.tsx +29 -0
  78. package/src/components/ReorderableListCell.tsx +1 -3
  79. package/src/components/ReorderableListCore/ReorderableListCore.tsx +162 -0
  80. package/src/components/ReorderableListCore/constants.ts +31 -0
  81. package/src/components/ReorderableListCore/index.ts +1 -0
  82. package/src/components/{ReorderableList/useReorderableList.ts → ReorderableListCore/useReorderableListCore.ts} +261 -89
  83. package/src/components/ScrollViewContainer.tsx +74 -0
  84. package/src/components/index.ts +2 -0
  85. package/src/contexts/ScrollViewContainerContext.ts +18 -0
  86. package/src/contexts/index.ts +1 -0
  87. package/src/index.ts +10 -1
  88. package/src/types/props.ts +21 -1
  89. package/lib/commonjs/components/ReorderableList/ReorderableList.js.map +0 -1
  90. package/lib/commonjs/components/ReorderableList/constants.ios.js +0 -10
  91. package/lib/commonjs/components/ReorderableList/constants.ios.js.map +0 -1
  92. package/lib/commonjs/components/ReorderableList/constants.js +0 -10
  93. package/lib/commonjs/components/ReorderableList/constants.js.map +0 -1
  94. package/lib/commonjs/components/ReorderableList/index.js +0 -17
  95. package/lib/commonjs/components/ReorderableList/index.js.map +0 -1
  96. package/lib/commonjs/components/ReorderableList/useReorderableList.js.map +0 -1
  97. package/lib/module/components/ReorderableList/ReorderableList.js.map +0 -1
  98. package/lib/module/components/ReorderableList/constants.ios.js +0 -4
  99. package/lib/module/components/ReorderableList/constants.ios.js.map +0 -1
  100. package/lib/module/components/ReorderableList/constants.js +0 -4
  101. package/lib/module/components/ReorderableList/constants.js.map +0 -1
  102. package/lib/module/components/ReorderableList/index.js +0 -2
  103. package/lib/module/components/ReorderableList/index.js.map +0 -1
  104. package/lib/module/components/ReorderableList/useReorderableList.js.map +0 -1
  105. package/lib/typescript/components/ReorderableList/ReorderableList.d.ts +0 -8
  106. package/lib/typescript/components/ReorderableList/ReorderableList.d.ts.map +0 -1
  107. package/lib/typescript/components/ReorderableList/constants.d.ts +0 -3
  108. package/lib/typescript/components/ReorderableList/constants.d.ts.map +0 -1
  109. package/lib/typescript/components/ReorderableList/constants.ios.d.ts +0 -3
  110. package/lib/typescript/components/ReorderableList/constants.ios.d.ts.map +0 -1
  111. package/lib/typescript/components/ReorderableList/index.d.ts +0 -2
  112. package/lib/typescript/components/ReorderableList/index.d.ts.map +0 -1
  113. package/lib/typescript/components/ReorderableList/useReorderableList.d.ts +0 -36
  114. package/lib/typescript/components/ReorderableList/useReorderableList.d.ts.map +0 -1
  115. package/src/components/ReorderableList/ReorderableList.tsx +0 -109
  116. package/src/components/ReorderableList/constants.ios.ts +0 -3
  117. package/src/components/ReorderableList/constants.ts +0 -3
  118. package/src/components/ReorderableList/index.ts +0 -1
@@ -0,0 +1,162 @@
1
+ import React, {useCallback, useMemo} from 'react';
2
+ import {
3
+ CellRendererProps,
4
+ FlatList,
5
+ FlatListProps,
6
+ Platform,
7
+ ScrollView,
8
+ } from 'react-native';
9
+
10
+ import {
11
+ Gesture,
12
+ GestureDetector,
13
+ NativeGesture,
14
+ } from 'react-native-gesture-handler';
15
+ import Animated, {SharedValue} from 'react-native-reanimated';
16
+
17
+ import {AUTOSCROLL_CONFIG} from './constants';
18
+ import {useReorderableListCore} from './useReorderableListCore';
19
+ import {ReorderableListContext} from '../../contexts';
20
+ import type {ReorderableListProps} from '../../types';
21
+ import {ReorderableListCell} from '../ReorderableListCell';
22
+
23
+ const AnimatedFlatList = Animated.createAnimatedComponent(
24
+ FlatList,
25
+ ) as unknown as <T>(
26
+ props: FlatListProps<T> & {ref?: React.Ref<FlatList<T>>},
27
+ ) => React.ReactElement;
28
+
29
+ interface ReorderableListCoreProps<T> extends ReorderableListProps<T> {
30
+ // not optional but undefined to avoid forgetting to pass a prop
31
+ scrollViewContainerRef: React.RefObject<ScrollView> | undefined;
32
+ scrollViewHeightY: SharedValue<number> | undefined;
33
+ scrollViewScrollOffsetY: SharedValue<number> | undefined;
34
+ scrollViewScrollEnabled: SharedValue<boolean> | undefined;
35
+ outerScrollGesture: NativeGesture | undefined;
36
+ initialScrollViewScrollEnabled: boolean | undefined;
37
+ scrollable: boolean | undefined;
38
+ scrollEnabled: boolean | undefined;
39
+ }
40
+
41
+ const ReorderableListCore = <T,>(
42
+ {
43
+ data,
44
+ autoscrollThreshold = 0.1,
45
+ autoscrollSpeedScale = 1,
46
+ autoscrollDelay = AUTOSCROLL_CONFIG.delay,
47
+ animationDuration = 200,
48
+ dragReorderThreshold = 0.2,
49
+ onLayout,
50
+ onReorder,
51
+ onScroll,
52
+ onDragEnd,
53
+ keyExtractor,
54
+ extraData,
55
+ scrollViewContainerRef,
56
+ scrollViewHeightY,
57
+ scrollViewScrollOffsetY,
58
+ scrollViewScrollEnabled,
59
+ scrollEnabled,
60
+ initialScrollViewScrollEnabled,
61
+ scrollable,
62
+ outerScrollGesture,
63
+ ...rest
64
+ }: ReorderableListCoreProps<T>,
65
+ ref: React.ForwardedRef<FlatList<T>>,
66
+ ) => {
67
+ const {
68
+ gestureHandler,
69
+ handleScroll,
70
+ handleFlatListLayout,
71
+ handleRef,
72
+ startDrag,
73
+ listContextValue,
74
+ itemOffset,
75
+ itemHeight,
76
+ dragY,
77
+ draggedIndex,
78
+ duration,
79
+ } = useReorderableListCore({
80
+ ref,
81
+ autoscrollThreshold,
82
+ autoscrollSpeedScale,
83
+ autoscrollDelay,
84
+ animationDuration,
85
+ dragReorderThreshold,
86
+ onLayout,
87
+ onReorder,
88
+ onScroll,
89
+ onDragEnd,
90
+ scrollViewContainerRef,
91
+ scrollViewHeightY,
92
+ scrollViewScrollOffsetY,
93
+ scrollViewScrollEnabled,
94
+ // flatlist will default to true if we pass explicitly undefined,
95
+ // but internally we would treat it as false, so we force true
96
+ initialScrollEnabled:
97
+ typeof scrollEnabled === 'undefined' ? true : scrollEnabled,
98
+ initialScrollViewScrollEnabled:
99
+ typeof initialScrollViewScrollEnabled === 'undefined'
100
+ ? true
101
+ : initialScrollViewScrollEnabled,
102
+ nestedScrollable: scrollable,
103
+ });
104
+
105
+ const combinedGesture = useMemo(() => {
106
+ // android is able to handle nested scroll view, but not the full height ones like iOS
107
+ if (outerScrollGesture && !(Platform.OS === 'android' && scrollable)) {
108
+ return Gesture.Simultaneous(outerScrollGesture, gestureHandler);
109
+ }
110
+
111
+ return gestureHandler;
112
+ }, [scrollable, outerScrollGesture, gestureHandler]);
113
+
114
+ const renderAnimatedCell = useCallback(
115
+ ({cellKey, ...props}: CellRendererProps<T>) => (
116
+ <ReorderableListCell
117
+ {...props}
118
+ // forces remount with key change on reorder
119
+ key={`${cellKey}+${props.index}`}
120
+ itemOffset={itemOffset}
121
+ itemHeight={itemHeight}
122
+ dragY={dragY}
123
+ draggedIndex={draggedIndex}
124
+ animationDuration={duration}
125
+ startDrag={startDrag}
126
+ />
127
+ ),
128
+ [itemOffset, itemHeight, dragY, draggedIndex, duration, startDrag],
129
+ );
130
+
131
+ return (
132
+ <ReorderableListContext.Provider value={listContextValue}>
133
+ <GestureDetector gesture={combinedGesture}>
134
+ <AnimatedFlatList
135
+ {...rest}
136
+ ref={handleRef}
137
+ data={data}
138
+ CellRendererComponent={renderAnimatedCell}
139
+ onLayout={handleFlatListLayout}
140
+ onScroll={handleScroll}
141
+ scrollEventThrottle={1}
142
+ horizontal={false}
143
+ removeClippedSubviews={false}
144
+ keyExtractor={keyExtractor}
145
+ extraData={extraData}
146
+ numColumns={1}
147
+ scrollEnabled={scrollEnabled}
148
+ />
149
+ </GestureDetector>
150
+ </ReorderableListContext.Provider>
151
+ );
152
+ };
153
+
154
+ const MemoizedReorderableListCore = React.memo(
155
+ React.forwardRef(ReorderableListCore),
156
+ ) as <T>(
157
+ props: ReorderableListCoreProps<T> & {
158
+ ref?: React.ForwardedRef<FlatList<T> | null>;
159
+ },
160
+ ) => React.ReactElement;
161
+
162
+ export {MemoizedReorderableListCore as ReorderableListCore};
@@ -0,0 +1,31 @@
1
+ import {Platform} from 'react-native';
2
+
3
+ const IOS_CONFIG = {
4
+ delay: 80,
5
+ increment: 100,
6
+ };
7
+
8
+ const ANDROID_FABRIC_CONFIG = {
9
+ delay: 50,
10
+ increment: 80,
11
+ };
12
+
13
+ const ANDROID_PAPER_CONFIG = {
14
+ delay: 10,
15
+ increment: 4,
16
+ };
17
+
18
+ export const IS_FABRIC =
19
+ global && typeof global === 'object' && 'nativeFabricUIManager' in global;
20
+
21
+ export const AUTOSCROLL_CONFIG = Platform.select({
22
+ // autoscroll behaves differently with Fabric and Paper on Android
23
+ android: IS_FABRIC ? ANDROID_FABRIC_CONFIG : ANDROID_PAPER_CONFIG,
24
+ ios: IOS_CONFIG,
25
+
26
+ // unsupported platforms
27
+ web: IOS_CONFIG,
28
+ macos: IOS_CONFIG,
29
+ windows: IOS_CONFIG,
30
+ native: IOS_CONFIG,
31
+ });
@@ -0,0 +1 @@
1
+ export * from './ReorderableListCore';