react-native-reorderable-list 0.14.1 → 0.16.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 (70) hide show
  1. package/README.md +4 -2
  2. package/lib/commonjs/components/NestedReorderableList.js +5 -7
  3. package/lib/commonjs/components/NestedReorderableList.js.map +1 -1
  4. package/lib/commonjs/components/ReorderableList.js +3 -7
  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 +94 -33
  9. package/lib/commonjs/components/ReorderableListCore.js.map +1 -1
  10. package/lib/commonjs/components/ScrollViewContainer.js +11 -10
  11. package/lib/commonjs/components/ScrollViewContainer.js.map +1 -1
  12. package/lib/commonjs/contexts/ReorderableListContext.js.map +1 -1
  13. package/lib/commonjs/hooks/index.js +34 -12
  14. package/lib/commonjs/hooks/index.js.map +1 -1
  15. package/lib/commonjs/hooks/usePropAsSharedValue.js +17 -0
  16. package/lib/commonjs/hooks/usePropAsSharedValue.js.map +1 -0
  17. package/lib/commonjs/hooks/useStableCallback.js +21 -0
  18. package/lib/commonjs/hooks/useStableCallback.js.map +1 -0
  19. package/lib/commonjs/types/misc.js.map +1 -1
  20. package/lib/module/components/NestedReorderableList.js +5 -7
  21. package/lib/module/components/NestedReorderableList.js.map +1 -1
  22. package/lib/module/components/ReorderableList.js +3 -7
  23. package/lib/module/components/ReorderableList.js.map +1 -1
  24. package/lib/module/components/ReorderableListCell.js +4 -2
  25. package/lib/module/components/ReorderableListCell.js.map +1 -1
  26. package/lib/module/components/ReorderableListCore.js +95 -34
  27. package/lib/module/components/ReorderableListCore.js.map +1 -1
  28. package/lib/module/components/ScrollViewContainer.js +10 -9
  29. package/lib/module/components/ScrollViewContainer.js.map +1 -1
  30. package/lib/module/contexts/ReorderableListContext.js.map +1 -1
  31. package/lib/module/hooks/index.js +4 -2
  32. package/lib/module/hooks/index.js.map +1 -1
  33. package/lib/module/hooks/usePropAsSharedValue.js +10 -0
  34. package/lib/module/hooks/usePropAsSharedValue.js.map +1 -0
  35. package/lib/module/hooks/useStableCallback.js +15 -0
  36. package/lib/module/hooks/useStableCallback.js.map +1 -0
  37. package/lib/module/types/misc.js.map +1 -1
  38. package/lib/typescript/components/NestedReorderableList.d.ts.map +1 -1
  39. package/lib/typescript/components/ReorderableList.d.ts.map +1 -1
  40. package/lib/typescript/components/ReorderableListCell.d.ts.map +1 -1
  41. package/lib/typescript/components/ReorderableListCore.d.ts +2 -3
  42. package/lib/typescript/components/ReorderableListCore.d.ts.map +1 -1
  43. package/lib/typescript/components/ScrollViewContainer.d.ts.map +1 -1
  44. package/lib/typescript/contexts/ReorderableListContext.d.ts +2 -1
  45. package/lib/typescript/contexts/ReorderableListContext.d.ts.map +1 -1
  46. package/lib/typescript/contexts/ScrollViewContainerContext.d.ts +2 -2
  47. package/lib/typescript/contexts/ScrollViewContainerContext.d.ts.map +1 -1
  48. package/lib/typescript/hooks/index.d.ts +4 -2
  49. package/lib/typescript/hooks/index.d.ts.map +1 -1
  50. package/lib/typescript/hooks/usePropAsSharedValue.d.ts +3 -0
  51. package/lib/typescript/hooks/usePropAsSharedValue.d.ts.map +1 -0
  52. package/lib/typescript/hooks/useStableCallback.d.ts +4 -0
  53. package/lib/typescript/hooks/useStableCallback.d.ts.map +1 -0
  54. package/lib/typescript/types/misc.d.ts +3 -1
  55. package/lib/typescript/types/misc.d.ts.map +1 -1
  56. package/lib/typescript/types/props.d.ts +10 -2
  57. package/lib/typescript/types/props.d.ts.map +1 -1
  58. package/package.json +1 -1
  59. package/src/components/NestedReorderableList.tsx +5 -6
  60. package/src/components/ReorderableList.tsx +4 -5
  61. package/src/components/ReorderableListCell.tsx +12 -3
  62. package/src/components/ReorderableListCore.tsx +113 -49
  63. package/src/components/ScrollViewContainer.tsx +11 -8
  64. package/src/contexts/ReorderableListContext.ts +2 -1
  65. package/src/contexts/ScrollViewContainerContext.ts +2 -2
  66. package/src/hooks/index.ts +4 -2
  67. package/src/hooks/usePropAsSharedValue.ts +13 -0
  68. package/src/hooks/useStableCallback.ts +16 -0
  69. package/src/types/misc.ts +8 -1
  70. package/src/types/props.ts +10 -2
@@ -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
 
@@ -9,9 +9,9 @@ interface ScrollViewContainerContextData {
9
9
  scrollViewPageY: SharedValue<number>;
10
10
  scrollViewHeightY: SharedValue<number>;
11
11
  scrollViewScrollOffsetY: SharedValue<number>;
12
- scrollViewScrollEnabled: SharedValue<boolean>;
12
+ scrollViewScrollEnabledProp: SharedValue<boolean>;
13
+ scrollViewCurrentScrollEnabled: SharedValue<boolean>;
13
14
  outerScrollGesture: NativeGesture;
14
- initialScrollViewScrollEnabled: boolean;
15
15
  }
16
16
 
17
17
  export const ScrollViewContainerContext = React.createContext<
@@ -1,5 +1,7 @@
1
+ export * from './useContext';
2
+ export * from './usePropAsSharedValue';
1
3
  export * from './useIsActive';
2
4
  export * from './useReorderableDrag';
3
- export * from './useReorderableDragStart';
4
5
  export * from './useReorderableDragEnd';
5
- export * from './useContext';
6
+ export * from './useReorderableDragStart';
7
+ export * from './useStableCallback';
@@ -0,0 +1,13 @@
1
+ import {useEffect} from 'react';
2
+
3
+ import {SharedValue, useSharedValue} from 'react-native-reanimated';
4
+
5
+ export const usePropAsSharedValue = <T>(value: T): SharedValue<T> => {
6
+ const sv = useSharedValue(value);
7
+
8
+ useEffect(() => {
9
+ sv.value = value;
10
+ }, [sv, value]);
11
+
12
+ return sv;
13
+ };
@@ -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
  /**
@@ -107,6 +107,10 @@ export interface ReorderableListProps<T>
107
107
  * Allows passing an object with values and/or shared values that can animate a cell, for example by using the `onDragStart` and `onDragEnd` events. Supports view style properties. Override opacity and/or transform to disable the default animation, e.g. `{opacity: 1, transform: []}`.
108
108
  */
109
109
  cellAnimations?: ReorderableListCellAnimations;
110
+ /**
111
+ * Whether dragging items is enabled. Default: `true`.
112
+ */
113
+ dragEnabled?: boolean;
110
114
  /**
111
115
  * Whether the active item should be updated. Enables usage of `useIsActive` hook. Default: `false`.
112
116
  */
@@ -116,7 +120,7 @@ export interface ReorderableListProps<T>
116
120
  */
117
121
  panGesture?: PanGesture;
118
122
  /**
119
- * Wether the pan gestures necessary for dragging are enabled. Default: `true`.
123
+ * Whether the pan gestures necessary for dragging are enabled. Default: `true`.
120
124
  *
121
125
  * @deprecated In favor of `panGesture` prop.
122
126
  */
@@ -127,6 +131,10 @@ export interface ReorderableListProps<T>
127
131
  * @deprecated In favor of `panGesture` prop.
128
132
  */
129
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;
130
138
  /**
131
139
  * Event fired after an item is released and the list is reordered.
132
140
  */