react-native-reorderable-list 0.15.0 → 0.16.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 (63) hide show
  1. package/README.md +1 -0
  2. package/lib/commonjs/components/NestedReorderableList.js +3 -3
  3. package/lib/commonjs/components/NestedReorderableList.js.map +1 -1
  4. package/lib/commonjs/components/ReorderableList.js +1 -1
  5. package/lib/commonjs/components/ReorderableList.js.map +1 -1
  6. package/lib/commonjs/components/ReorderableListCell.js +4 -2
  7. package/lib/commonjs/components/ReorderableListCell.js.map +1 -1
  8. package/lib/commonjs/components/ReorderableListCore.js +101 -30
  9. package/lib/commonjs/components/ReorderableListCore.js.map +1 -1
  10. package/lib/commonjs/components/ScrollViewContainer.js +7 -4
  11. package/lib/commonjs/components/ScrollViewContainer.js.map +1 -1
  12. package/lib/commonjs/contexts/ReorderableListContext.js.map +1 -1
  13. package/lib/commonjs/contexts/ScrollViewContainerContext.js.map +1 -1
  14. package/lib/commonjs/hooks/index.js +11 -0
  15. package/lib/commonjs/hooks/index.js.map +1 -1
  16. package/lib/commonjs/hooks/useStableCallback.js +21 -0
  17. package/lib/commonjs/hooks/useStableCallback.js.map +1 -0
  18. package/lib/commonjs/types/misc.js.map +1 -1
  19. package/lib/module/components/NestedReorderableList.js +3 -3
  20. package/lib/module/components/NestedReorderableList.js.map +1 -1
  21. package/lib/module/components/ReorderableList.js +1 -1
  22. package/lib/module/components/ReorderableList.js.map +1 -1
  23. package/lib/module/components/ReorderableListCell.js +4 -2
  24. package/lib/module/components/ReorderableListCell.js.map +1 -1
  25. package/lib/module/components/ReorderableListCore.js +103 -32
  26. package/lib/module/components/ReorderableListCore.js.map +1 -1
  27. package/lib/module/components/ScrollViewContainer.js +8 -5
  28. package/lib/module/components/ScrollViewContainer.js.map +1 -1
  29. package/lib/module/contexts/ReorderableListContext.js.map +1 -1
  30. package/lib/module/contexts/ScrollViewContainerContext.js.map +1 -1
  31. package/lib/module/hooks/index.js +1 -0
  32. package/lib/module/hooks/index.js.map +1 -1
  33. package/lib/module/hooks/useStableCallback.js +15 -0
  34. package/lib/module/hooks/useStableCallback.js.map +1 -0
  35. package/lib/module/types/misc.js.map +1 -1
  36. package/lib/typescript/components/ReorderableListCell.d.ts.map +1 -1
  37. package/lib/typescript/components/ReorderableListCore.d.ts +3 -3
  38. package/lib/typescript/components/ReorderableListCore.d.ts.map +1 -1
  39. package/lib/typescript/components/ScrollViewContainer.d.ts.map +1 -1
  40. package/lib/typescript/contexts/ReorderableListContext.d.ts +2 -1
  41. package/lib/typescript/contexts/ReorderableListContext.d.ts.map +1 -1
  42. package/lib/typescript/contexts/ScrollViewContainerContext.d.ts +2 -2
  43. package/lib/typescript/contexts/ScrollViewContainerContext.d.ts.map +1 -1
  44. package/lib/typescript/hooks/index.d.ts +1 -0
  45. package/lib/typescript/hooks/index.d.ts.map +1 -1
  46. package/lib/typescript/hooks/useStableCallback.d.ts +4 -0
  47. package/lib/typescript/hooks/useStableCallback.d.ts.map +1 -0
  48. package/lib/typescript/types/misc.d.ts +3 -1
  49. package/lib/typescript/types/misc.d.ts.map +1 -1
  50. package/lib/typescript/types/props.d.ts +5 -1
  51. package/lib/typescript/types/props.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/src/components/NestedReorderableList.tsx +2 -2
  54. package/src/components/ReorderableList.tsx +1 -1
  55. package/src/components/ReorderableListCell.tsx +12 -3
  56. package/src/components/ReorderableListCore.tsx +124 -42
  57. package/src/components/ScrollViewContainer.tsx +7 -4
  58. package/src/contexts/ReorderableListContext.ts +2 -1
  59. package/src/contexts/ScrollViewContainerContext.ts +2 -2
  60. package/src/hooks/index.ts +1 -0
  61. package/src/hooks/useStableCallback.ts +16 -0
  62. package/src/types/misc.ts +8 -1
  63. package/src/types/props.ts +5 -1
@@ -1,4 +1,4 @@
1
- import React, {forwardRef, useCallback, useMemo} from 'react';
1
+ import React, {forwardRef, useCallback, useMemo, useState} from 'react';
2
2
  import {LayoutChangeEvent, ScrollView} from 'react-native';
3
3
 
4
4
  import {Gesture, GestureDetector} from 'react-native-gesture-handler';
@@ -21,8 +21,9 @@ const ScrollViewContainerWithRef = (
21
21
  ) => {
22
22
  const scrollEnabled = rest.scrollEnabled ?? true;
23
23
 
24
+ const [scrollViewForceDisableScroll, setScrollViewForceDisableScroll] =
25
+ useState(false);
24
26
  const scrollViewScrollEnabledProp = usePropAsSharedValue(scrollEnabled);
25
- const scrollViewCurrentScrollEnabled = useSharedValue(scrollEnabled);
26
27
  const scrollViewContainerRef = useAnimatedRef<Animated.ScrollView>();
27
28
  const scrollViewScrollOffsetY = useSharedValue(0);
28
29
  const scrollViewPageY = useSharedValue(0);
@@ -62,8 +63,8 @@ const ScrollViewContainerWithRef = (
62
63
  scrollViewHeightY,
63
64
  scrollViewScrollOffsetY,
64
65
  scrollViewScrollEnabledProp,
65
- scrollViewCurrentScrollEnabled,
66
66
  outerScrollGesture,
67
+ setScrollViewForceDisableScroll,
67
68
  }),
68
69
  [
69
70
  scrollViewContainerRef,
@@ -71,8 +72,8 @@ const ScrollViewContainerWithRef = (
71
72
  scrollViewHeightY,
72
73
  scrollViewScrollOffsetY,
73
74
  scrollViewScrollEnabledProp,
74
- scrollViewCurrentScrollEnabled,
75
75
  outerScrollGesture,
76
+ setScrollViewForceDisableScroll,
76
77
  ],
77
78
  );
78
79
 
@@ -103,6 +104,8 @@ const ScrollViewContainerWithRef = (
103
104
  ref={handleRef}
104
105
  onScroll={composedScrollHandler}
105
106
  onLayout={handleLayout}
107
+ // We force disable scroll or let the component prop control it.
108
+ scrollEnabled={scrollViewForceDisableScroll ? false : scrollEnabled}
106
109
  />
107
110
  </GestureDetector>
108
111
  </ScrollViewContainerContext.Provider>
@@ -2,13 +2,14 @@ import React from 'react';
2
2
 
3
3
  import type {SharedValue} from 'react-native-reanimated';
4
4
 
5
- import {ReorderableListCellAnimations} from '../types';
5
+ import {ItemLayoutAnimation, ReorderableListCellAnimations} from '../types';
6
6
 
7
7
  interface ReorderableListContextData {
8
8
  currentIndex: SharedValue<number>;
9
9
  draggedHeight: SharedValue<number>;
10
10
  dragEndHandlers: SharedValue<((from: number, to: number) => void)[][]>;
11
11
  activeIndex: number;
12
+ itemLayoutAnimation: React.MutableRefObject<ItemLayoutAnimation | undefined>;
12
13
  cellAnimations: ReorderableListCellAnimations;
13
14
  }
14
15
 
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, {Dispatch, SetStateAction} from 'react';
2
2
  import {ScrollView} from 'react-native';
3
3
 
4
4
  import {NativeGesture} from 'react-native-gesture-handler';
@@ -10,8 +10,8 @@ interface ScrollViewContainerContextData {
10
10
  scrollViewHeightY: SharedValue<number>;
11
11
  scrollViewScrollOffsetY: SharedValue<number>;
12
12
  scrollViewScrollEnabledProp: SharedValue<boolean>;
13
- scrollViewCurrentScrollEnabled: SharedValue<boolean>;
14
13
  outerScrollGesture: NativeGesture;
14
+ setScrollViewForceDisableScroll: Dispatch<SetStateAction<boolean>>;
15
15
  }
16
16
 
17
17
  export const ScrollViewContainerContext = React.createContext<
@@ -4,3 +4,4 @@ export * from './useIsActive';
4
4
  export * from './useReorderableDrag';
5
5
  export * from './useReorderableDragEnd';
6
6
  export * from './useReorderableDragStart';
7
+ export * from './useStableCallback';
@@ -0,0 +1,16 @@
1
+ import {useCallback, useLayoutEffect, useRef} from 'react';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ type Fn = (...args: any[]) => any;
5
+
6
+ export const useStableCallback = <T extends Fn>(value: T) => {
7
+ const callback = useRef<T>(value);
8
+
9
+ useLayoutEffect(() => {
10
+ callback.current = value;
11
+ });
12
+
13
+ return useCallback((...args: Parameters<T>): ReturnType<T> => {
14
+ return callback.current?.(...args);
15
+ }, []);
16
+ };
package/src/types/misc.ts CHANGED
@@ -1,4 +1,6 @@
1
- import {SharedValue} from 'react-native-reanimated';
1
+ import {ComponentProps} from 'react';
2
+
3
+ import Animated, {SharedValue} from 'react-native-reanimated';
2
4
 
3
5
  export enum ReorderableListState {
4
6
  IDLE = 0,
@@ -7,6 +9,11 @@ export enum ReorderableListState {
7
9
  AUTOSCROLL,
8
10
  }
9
11
 
12
+ export type ItemLayoutAnimation = Exclude<
13
+ ComponentProps<typeof Animated.View>['layout'],
14
+ undefined
15
+ >;
16
+
10
17
  export type SharedValueOrType<T> = {
11
18
  [TKey in keyof T]?: SharedValue<T[TKey]> | T[TKey];
12
19
  };
@@ -20,7 +20,7 @@ import type {
20
20
  import {PanGesture} from 'react-native-gesture-handler';
21
21
  import {SharedValue, useAnimatedScrollHandler} from 'react-native-reanimated';
22
22
 
23
- import {MaximumOneOf, SharedValueOrType} from './misc';
23
+ import {ItemLayoutAnimation, MaximumOneOf, SharedValueOrType} from './misc';
24
24
 
25
25
  export interface ReorderableListReorderEvent {
26
26
  /**
@@ -131,6 +131,10 @@ export interface ReorderableListProps<T>
131
131
  * @deprecated In favor of `panGesture` prop.
132
132
  */
133
133
  panActivateAfterLongPress?: number;
134
+ /**
135
+ * Layout animation when the item is added to and/or removed from the view hierarchy. To skip entering or exiting animations use the LayoutAnimationConfig component from [Reanimated](https://docs.swmansion.com/react-native-reanimated).
136
+ */
137
+ itemLayoutAnimation?: ItemLayoutAnimation;
134
138
  /**
135
139
  * Event fired after an item is released and the list is reordered.
136
140
  */