react-native-reorderable-list 0.9.0 → 0.11.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 (46) hide show
  1. package/README.md +36 -41
  2. package/lib/commonjs/components/ReorderableListCell.js +13 -11
  3. package/lib/commonjs/components/ReorderableListCell.js.map +1 -1
  4. package/lib/commonjs/components/ReorderableListCore/ReorderableListCore.js +4 -0
  5. package/lib/commonjs/components/ReorderableListCore/ReorderableListCore.js.map +1 -1
  6. package/lib/commonjs/components/ReorderableListCore/useReorderableListCore.js +32 -20
  7. package/lib/commonjs/components/ReorderableListCore/useReorderableListCore.js.map +1 -1
  8. package/lib/commonjs/components/helpers.js +32 -0
  9. package/lib/commonjs/components/helpers.js.map +1 -0
  10. package/lib/commonjs/contexts/ReorderableListContext.js.map +1 -1
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/types/misc.js.map +1 -1
  13. package/lib/module/components/ReorderableListCell.js +13 -11
  14. package/lib/module/components/ReorderableListCell.js.map +1 -1
  15. package/lib/module/components/ReorderableListCore/ReorderableListCore.js +4 -0
  16. package/lib/module/components/ReorderableListCore/ReorderableListCore.js.map +1 -1
  17. package/lib/module/components/ReorderableListCore/useReorderableListCore.js +32 -20
  18. package/lib/module/components/ReorderableListCore/useReorderableListCore.js.map +1 -1
  19. package/lib/module/components/helpers.js +25 -0
  20. package/lib/module/components/helpers.js.map +1 -0
  21. package/lib/module/contexts/ReorderableListContext.js.map +1 -1
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/types/misc.js.map +1 -1
  24. package/lib/typescript/components/ReorderableListCell.d.ts.map +1 -1
  25. package/lib/typescript/components/ReorderableListCore/ReorderableListCore.d.ts.map +1 -1
  26. package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts +136 -4
  27. package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts.map +1 -1
  28. package/lib/typescript/components/helpers.d.ts +11 -0
  29. package/lib/typescript/components/helpers.d.ts.map +1 -0
  30. package/lib/typescript/contexts/ReorderableListContext.d.ts +2 -2
  31. package/lib/typescript/contexts/ReorderableListContext.d.ts.map +1 -1
  32. package/lib/typescript/index.d.ts +2 -2
  33. package/lib/typescript/index.d.ts.map +1 -1
  34. package/lib/typescript/types/misc.d.ts +9 -0
  35. package/lib/typescript/types/misc.d.ts.map +1 -1
  36. package/lib/typescript/types/props.d.ts +34 -9
  37. package/lib/typescript/types/props.d.ts.map +1 -1
  38. package/package.json +3 -1
  39. package/src/components/ReorderableListCell.tsx +18 -6
  40. package/src/components/ReorderableListCore/ReorderableListCore.tsx +4 -0
  41. package/src/components/ReorderableListCore/useReorderableListCore.ts +41 -17
  42. package/src/components/helpers.ts +36 -0
  43. package/src/contexts/ReorderableListContext.ts +3 -2
  44. package/src/index.ts +2 -0
  45. package/src/types/misc.ts +10 -0
  46. package/src/types/props.ts +71 -9
@@ -1,7 +1,26 @@
1
- import type {FlatListProps, ScrollViewProps} from 'react-native';
1
+ import type {
2
+ FlatListProps,
3
+ MatrixTransform,
4
+ PerspectiveTransform,
5
+ RotateTransform,
6
+ RotateXTransform,
7
+ RotateYTransform,
8
+ RotateZTransform,
9
+ ScaleTransform,
10
+ ScaleXTransform,
11
+ ScaleYTransform,
12
+ ScrollViewProps,
13
+ SkewXTransform,
14
+ SkewYTransform,
15
+ TranslateXTransform,
16
+ TranslateYTransform,
17
+ ViewStyle,
18
+ } from 'react-native';
2
19
 
3
20
  import {SharedValue, useAnimatedScrollHandler} from 'react-native-reanimated';
4
21
 
22
+ import {MaximumOneOf, SharedValueOrType} from './misc';
23
+
5
24
  export interface ReorderableListReorderEvent {
6
25
  /**
7
26
  * Index of the dragged item.
@@ -20,6 +39,13 @@ export interface ReorderableListDragStartEvent {
20
39
  index: number;
21
40
  }
22
41
 
42
+ export interface ReorderableListIndexChangeEvent {
43
+ /**
44
+ * Index of the dragged item.
45
+ */
46
+ index: number;
47
+ }
48
+
23
49
  export interface ReorderableListDragEndEvent {
24
50
  /**
25
51
  * Index of the dragged item.
@@ -43,11 +69,16 @@ export interface ReorderableListProps<T>
43
69
  extends Omit<FlatListProps<T>, OmittedProps> {
44
70
  data: T[];
45
71
  /**
46
- * Threshold at the extremety of the list which triggers autoscroll when an item is dragged to it.
72
+ * Threshold at the extremety of the list which triggers autoscroll when an item is dragged to it.
47
73
  * 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
48
74
  * when an item is dragged to it. Min value: `0`. Max value: `0.4`. Default: `0.1`.
49
75
  */
50
76
  autoscrollThreshold?: number;
77
+ /**
78
+ * Amount by which the threshold is offset at the extremety of the list.
79
+ * For example, setting `{top: 50}` will make the autoscroll trigger 50 pixels earlier at the top.
80
+ */
81
+ autoscrollThresholdOffset?: {top?: number; bottom?: number};
51
82
  /**
52
83
  * Scales the autoscroll spreed at which the list scrolls when an item is dragged to the scroll areas. Default: `1`.
53
84
  */
@@ -71,7 +102,7 @@ export interface ReorderableListProps<T>
71
102
  */
72
103
  animationDuration?: number;
73
104
  /**
74
- * Allows passing an object with shared values that can animate a cell by using the `onDragStart` and `onDragEnd` events.
105
+ * 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: []}`.
75
106
  */
76
107
  cellAnimations?: ReorderableListCellAnimations;
77
108
  /**
@@ -83,7 +114,7 @@ export interface ReorderableListProps<T>
83
114
  */
84
115
  panEnabled?: boolean;
85
116
  /**
86
- * Duration in milliseconds of a long press on the list before pan gestures, necessary for dragging, are allowed to activate.
117
+ * Duration in milliseconds of the long press on the list before the pan gesture for dragging is allowed to activate.
87
118
  */
88
119
  panActivateAfterLongPress?: number;
89
120
  /**
@@ -102,17 +133,48 @@ export interface ReorderableListProps<T>
102
133
  * Event fired when the dragged item is released. Needs to be a `worklet`. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info.
103
134
  */
104
135
  onDragEnd?: (event: ReorderableListDragEndEvent) => void;
136
+ /**
137
+ * Event fired when the index of the dragged item changes. Needs to be a `worklet`. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info.
138
+ */
139
+ onIndexChange?: (event: ReorderableListIndexChangeEvent) => void;
105
140
  }
106
141
 
107
- export interface ReorderableListCellAnimations {
142
+ export type Transforms = PerspectiveTransform &
143
+ RotateTransform &
144
+ RotateXTransform &
145
+ RotateYTransform &
146
+ RotateZTransform &
147
+ ScaleTransform &
148
+ ScaleXTransform &
149
+ ScaleYTransform &
150
+ TranslateXTransform &
151
+ TranslateYTransform &
152
+ SkewXTransform &
153
+ SkewYTransform &
154
+ MatrixTransform;
155
+
156
+ export type ReorderableListCellAnimatedStyles = Omit<
157
+ {
158
+ [StyleKey in keyof ViewStyle]?:
159
+ | SharedValue<ViewStyle[StyleKey]>
160
+ | ViewStyle[StyleKey];
161
+ },
162
+ // omit custom type and type with JSDoc
163
+ 'transform' | 'opacity'
164
+ >;
165
+
166
+ export interface ReorderableListCellAnimations
167
+ extends ReorderableListCellAnimatedStyles {
108
168
  /**
109
- * Shared value to animate the opacity of a dragged item. Set to false to disable default opacity animations.
169
+ * Transform animations for a dragged item.
170
+ * Disable default animation by overriding transform, e.g. `[]` or `[{ scale: customSharedValue }]`.
110
171
  */
111
- opacity?: SharedValue<number> | false;
172
+ transform?: Readonly<MaximumOneOf<SharedValueOrType<Transforms>>[]>;
112
173
  /**
113
- * Shared value to animate the scale of a dragged item. Set to false to disable default scale animations.
174
+ * Shared value to animate the opacity of a dragged item.
175
+ * Disable default animation by overriding opacity, e.g `1`.
114
176
  */
115
- scale?: SharedValue<number> | false;
177
+ opacity?: SharedValue<number> | number;
116
178
  }
117
179
 
118
180
  export interface ScrollViewContainerProps