react-native-reorderable-list 0.9.0 → 0.10.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 (41) hide show
  1. package/README.md +35 -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 +2 -0
  5. package/lib/commonjs/components/ReorderableListCore/ReorderableListCore.js.map +1 -1
  6. package/lib/commonjs/components/ReorderableListCore/useReorderableListCore.js +27 -19
  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/types/misc.js.map +1 -1
  12. package/lib/module/components/ReorderableListCell.js +13 -11
  13. package/lib/module/components/ReorderableListCell.js.map +1 -1
  14. package/lib/module/components/ReorderableListCore/ReorderableListCore.js +2 -0
  15. package/lib/module/components/ReorderableListCore/ReorderableListCore.js.map +1 -1
  16. package/lib/module/components/ReorderableListCore/useReorderableListCore.js +27 -19
  17. package/lib/module/components/ReorderableListCore/useReorderableListCore.js.map +1 -1
  18. package/lib/module/components/helpers.js +25 -0
  19. package/lib/module/components/helpers.js.map +1 -0
  20. package/lib/module/contexts/ReorderableListContext.js.map +1 -1
  21. package/lib/module/types/misc.js.map +1 -1
  22. package/lib/typescript/components/ReorderableListCell.d.ts.map +1 -1
  23. package/lib/typescript/components/ReorderableListCore/ReorderableListCore.d.ts.map +1 -1
  24. package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts +134 -3
  25. package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts.map +1 -1
  26. package/lib/typescript/components/helpers.d.ts +11 -0
  27. package/lib/typescript/components/helpers.d.ts.map +1 -0
  28. package/lib/typescript/contexts/ReorderableListContext.d.ts +2 -2
  29. package/lib/typescript/contexts/ReorderableListContext.d.ts.map +1 -1
  30. package/lib/typescript/types/misc.d.ts +9 -0
  31. package/lib/typescript/types/misc.d.ts.map +1 -1
  32. package/lib/typescript/types/props.d.ts +23 -8
  33. package/lib/typescript/types/props.d.ts.map +1 -1
  34. package/package.json +3 -1
  35. package/src/components/ReorderableListCell.tsx +18 -6
  36. package/src/components/ReorderableListCore/ReorderableListCore.tsx +2 -0
  37. package/src/components/ReorderableListCore/useReorderableListCore.ts +35 -17
  38. package/src/components/helpers.ts +36 -0
  39. package/src/contexts/ReorderableListContext.ts +3 -2
  40. package/src/types/misc.ts +10 -0
  41. package/src/types/props.ts +59 -8
@@ -1 +1 @@
1
- {"version":3,"file":"ReorderableListContext.d.ts","sourceRoot":"","sources":["../../../src/contexts/ReorderableListContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAEzD,UAAU,0BAA0B;IAClC,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAClC,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACnC,eAAe,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IACvE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,sBAAsB,uDAEvB,CAAC"}
1
+ {"version":3,"file":"ReorderableListContext.d.ts","sourceRoot":"","sources":["../../../src/contexts/ReorderableListContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAC,6BAA6B,EAAC,MAAM,UAAU,CAAC;AAEvD,UAAU,0BAA0B;IAClC,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAClC,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACnC,eAAe,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IACvE,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,6BAA6B,CAAC;CAC/C;AAED,eAAO,MAAM,sBAAsB,uDAEvB,CAAC"}
@@ -1,7 +1,16 @@
1
+ import { SharedValue } from 'react-native-reanimated';
1
2
  export declare enum ReorderableListState {
2
3
  IDLE = 0,
3
4
  DRAGGED = 1,
4
5
  RELEASED = 2,
5
6
  AUTOSCROLL = 3
6
7
  }
8
+ export type SharedValueOrType<T> = {
9
+ [TKey in keyof T]?: SharedValue<T[TKey]> | T[TKey];
10
+ };
11
+ export type MaximumOneOf<T, K extends keyof T = keyof T> = K extends keyof T ? {
12
+ [P in K]: T[K];
13
+ } & {
14
+ [P in Exclude<keyof T, K>]?: never;
15
+ } : never;
7
16
  //# sourceMappingURL=misc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../../src/types/misc.ts"],"names":[],"mappings":"AAAA,oBAAY,oBAAoB;IAC9B,IAAI,IAAI;IACR,OAAO,IAAA;IACP,QAAQ,IAAA;IACR,UAAU,IAAA;CACX"}
1
+ {"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../../src/types/misc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAEpD,oBAAY,oBAAoB;IAC9B,IAAI,IAAI;IACR,OAAO,IAAA;IACP,QAAQ,IAAA;IACR,UAAU,IAAA;CACX;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;KAChC,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;CACnD,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GACxE;KAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAC,GAAG;KAAE,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK;CAAC,GACvD,KAAK,CAAC"}
@@ -1,5 +1,6 @@
1
- import type { FlatListProps, ScrollViewProps } from 'react-native';
1
+ import type { FlatListProps, MatrixTransform, PerspectiveTransform, RotateTransform, RotateXTransform, RotateYTransform, RotateZTransform, ScaleTransform, ScaleXTransform, ScaleYTransform, ScrollViewProps, SkewXTransform, SkewYTransform, TranslateXTransform, TranslateYTransform, ViewStyle } from 'react-native';
2
2
  import { SharedValue, useAnimatedScrollHandler } from 'react-native-reanimated';
3
+ import { MaximumOneOf, SharedValueOrType } from './misc';
3
4
  export interface ReorderableListReorderEvent {
4
5
  /**
5
6
  * Index of the dragged item.
@@ -30,11 +31,19 @@ type OmittedProps = 'horizontal' | 'onScroll' | 'scrollEventThrottle' | 'removeC
30
31
  export interface ReorderableListProps<T> extends Omit<FlatListProps<T>, OmittedProps> {
31
32
  data: T[];
32
33
  /**
33
- * Threshold at the extremety of the list which triggers autoscroll when an item is dragged to it.
34
+ * Threshold at the extremety of the list which triggers autoscroll when an item is dragged to it.
34
35
  * 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
35
36
  * when an item is dragged to it. Min value: `0`. Max value: `0.4`. Default: `0.1`.
36
37
  */
37
38
  autoscrollThreshold?: number;
39
+ /**
40
+ * Amount by which the threshold is offset at the extremety of the list.
41
+ * For example, setting `{top: 50}` will make the autoscroll trigger 50 pixels earlier at the top.
42
+ */
43
+ autoscrollThresholdOffset?: {
44
+ top?: number;
45
+ bottom?: number;
46
+ };
38
47
  /**
39
48
  * Scales the autoscroll spreed at which the list scrolls when an item is dragged to the scroll areas. Default: `1`.
40
49
  */
@@ -58,7 +67,7 @@ export interface ReorderableListProps<T> extends Omit<FlatListProps<T>, OmittedP
58
67
  */
59
68
  animationDuration?: number;
60
69
  /**
61
- * Allows passing an object with shared values that can animate a cell by using the `onDragStart` and `onDragEnd` events.
70
+ * 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: []}`.
62
71
  */
63
72
  cellAnimations?: ReorderableListCellAnimations;
64
73
  /**
@@ -90,15 +99,21 @@ export interface ReorderableListProps<T> extends Omit<FlatListProps<T>, OmittedP
90
99
  */
91
100
  onDragEnd?: (event: ReorderableListDragEndEvent) => void;
92
101
  }
93
- export interface ReorderableListCellAnimations {
102
+ export type Transforms = PerspectiveTransform & RotateTransform & RotateXTransform & RotateYTransform & RotateZTransform & ScaleTransform & ScaleXTransform & ScaleYTransform & TranslateXTransform & TranslateYTransform & SkewXTransform & SkewYTransform & MatrixTransform;
103
+ export type ReorderableListCellAnimatedStyles = Omit<{
104
+ [StyleKey in keyof ViewStyle]?: SharedValue<ViewStyle[StyleKey]> | ViewStyle[StyleKey];
105
+ }, 'transform' | 'opacity'>;
106
+ export interface ReorderableListCellAnimations extends ReorderableListCellAnimatedStyles {
94
107
  /**
95
- * Shared value to animate the opacity of a dragged item. Set to false to disable default opacity animations.
108
+ * Transform animations for a dragged item.
109
+ * Disable default animation by overriding transform, e.g. `[]` or `[{ scale: customSharedValue }]`.
96
110
  */
97
- opacity?: SharedValue<number> | false;
111
+ transform?: Readonly<MaximumOneOf<SharedValueOrType<Transforms>>[]>;
98
112
  /**
99
- * Shared value to animate the scale of a dragged item. Set to false to disable default scale animations.
113
+ * Shared value to animate the opacity of a dragged item.
114
+ * Disable default animation by overriding opacity, e.g `1`.
100
115
  */
101
- scale?: SharedValue<number> | false;
116
+ opacity?: SharedValue<number> | number;
102
117
  }
103
118
  export interface ScrollViewContainerProps extends Omit<ScrollViewProps, 'onScroll'> {
104
119
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../../src/types/props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAC,WAAW,EAAE,wBAAwB,EAAC,MAAM,yBAAyB,CAAC;AAE9E,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,6BAA6B;IAC5C;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,KAAK,YAAY,GACb,YAAY,GACZ,UAAU,GACV,qBAAqB,GACrB,uBAAuB,GACvB,uBAAuB,GACvB,YAAY,CAAC;AAEjB,MAAM,WAAW,oBAAoB,CAAC,CAAC,CACrC,SAAQ,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC;IAC5C,IAAI,EAAE,CAAC,EAAE,CAAC;IACV;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;O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CAAC,CAAC,CAAE,SAAQ,oBAAoB,CAAC,CAAC,CAAC;IAC5E;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-reorderable-list",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Reorderable list for React Native applications, powered by Reanimated",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -146,6 +146,8 @@
146
146
  "import"
147
147
  ],
148
148
  "rules": {
149
+ "@typescript-eslint/no-explicit-any": "error",
150
+ "no-console": "error",
149
151
  "prettier/prettier": [
150
152
  "error",
151
153
  {
@@ -14,6 +14,7 @@ import Animated, {
14
14
 
15
15
  import {ReorderableCellContext, ReorderableListContext} from '../contexts';
16
16
  import {useContext} from '../hooks';
17
+ import {applyAnimatedStyles} from './helpers';
17
18
 
18
19
  interface ReorderableListCellProps<T>
19
20
  extends Omit<CellRendererProps<T>, 'cellKey'> {
@@ -37,7 +38,7 @@ export const ReorderableListCell = memo(
37
38
  draggedIndex,
38
39
  animationDuration,
39
40
  }: ReorderableListCellProps<T>) => {
40
- const {currentIndex, draggedHeight, scale, opacity, activeIndex} =
41
+ const {currentIndex, draggedHeight, activeIndex, cellAnimations} =
41
42
  useContext(ReorderableListContext);
42
43
  const dragHandler = useCallback(
43
44
  () => runOnUI(startDrag)(index),
@@ -103,11 +104,22 @@ export const ReorderableListCell = memo(
103
104
 
104
105
  const animatedStyle = useAnimatedStyle(() => {
105
106
  if (isActiveCell.value) {
106
- return {
107
- transform: [{translateY: itemTranslateY.value}, {scale: scale.value}],
108
- opacity: opacity.value,
109
- zIndex: 999,
110
- };
107
+ const transform = [{translateY: itemTranslateY.value}];
108
+ if (Array.isArray(cellAnimations.transform)) {
109
+ const customTransform = cellAnimations.transform.map(x =>
110
+ applyAnimatedStyles({}, x),
111
+ ) as [];
112
+ transform.push(...customTransform);
113
+ }
114
+
115
+ return applyAnimatedStyles(
116
+ {
117
+ transform,
118
+ zIndex: 999,
119
+ },
120
+ cellAnimations,
121
+ ['transform'],
122
+ );
111
123
  }
112
124
 
113
125
  return {
@@ -44,6 +44,7 @@ interface ReorderableListCoreProps<T> extends ReorderableListProps<T> {
44
44
  const ReorderableListCore = <T,>(
45
45
  {
46
46
  autoscrollThreshold = 0.1,
47
+ autoscrollThresholdOffset,
47
48
  autoscrollSpeedScale = 1,
48
49
  autoscrollDelay = AUTOSCROLL_CONFIG.delay,
49
50
  animationDuration = 200,
@@ -83,6 +84,7 @@ const ReorderableListCore = <T,>(
83
84
  } = useReorderableListCore({
84
85
  ref,
85
86
  autoscrollThreshold,
87
+ autoscrollThresholdOffset,
86
88
  autoscrollSpeedScale,
87
89
  autoscrollDelay,
88
90
  animationDuration,
@@ -43,6 +43,7 @@ const hasAutomaticBatching = version.length
43
43
  interface UseReorderableListCoreArgs<T> {
44
44
  ref: React.ForwardedRef<FlatList<T>>;
45
45
  autoscrollThreshold: number;
46
+ autoscrollThresholdOffset: {top?: number; bottom?: number} | undefined;
46
47
  autoscrollSpeedScale: number;
47
48
  autoscrollDelay: number;
48
49
  animationDuration: number;
@@ -67,6 +68,7 @@ interface UseReorderableListCoreArgs<T> {
67
68
  export const useReorderableListCore = <T>({
68
69
  ref,
69
70
  autoscrollThreshold,
71
+ autoscrollThresholdOffset,
70
72
  autoscrollSpeedScale,
71
73
  autoscrollDelay,
72
74
  animationDuration,
@@ -119,7 +121,6 @@ export const useReorderableListCore = <T>({
119
121
  const duration = useSharedValue(animationDuration);
120
122
  const scaleDefault = useSharedValue(1);
121
123
  const opacityDefault = useSharedValue(1);
122
- const {scale, opacity} = cellAnimations || {};
123
124
 
124
125
  useEffect(() => {
125
126
  duration.value = animationDuration;
@@ -132,8 +133,17 @@ export const useReorderableListCore = <T>({
132
133
  draggedIndex,
133
134
  dragEndHandlers,
134
135
  activeIndex,
135
- scale: scale || scaleDefault,
136
- opacity: opacity || opacityDefault,
136
+ cellAnimations: {
137
+ ...cellAnimations,
138
+ transform:
139
+ cellAnimations && 'transform' in cellAnimations
140
+ ? cellAnimations.transform
141
+ : [{scale: scaleDefault}],
142
+ opacity:
143
+ cellAnimations && 'opacity' in cellAnimations
144
+ ? cellAnimations.opacity
145
+ : opacityDefault,
146
+ },
137
147
  }),
138
148
  [
139
149
  draggedHeight,
@@ -141,9 +151,8 @@ export const useReorderableListCore = <T>({
141
151
  draggedIndex,
142
152
  dragEndHandlers,
143
153
  activeIndex,
144
- scale,
154
+ cellAnimations,
145
155
  scaleDefault,
146
- opacity,
147
156
  opacityDefault,
148
157
  ],
149
158
  );
@@ -359,19 +368,19 @@ export const useReorderableListCore = <T>({
359
368
  (type: 'start' | 'end') => {
360
369
  'worklet';
361
370
 
362
- // if animation is not disabled and not custom run the default
363
- if (scale !== false && !scale) {
371
+ // if no custom scale run default
372
+ if (!(cellAnimations && 'transformtra' in cellAnimations)) {
364
373
  const scaleConfig = SCALE_ANIMATION_CONFIG_DEFAULT[type];
365
374
  scaleDefault.value = withTiming(scaleConfig.toValue, scaleConfig);
366
375
  }
367
376
 
368
- // if animation is not disabled and not custom run the default
369
- if (opacity !== false && !opacity) {
377
+ // if no custom opacity run the default
378
+ if (!(cellAnimations && 'opacity' in cellAnimations)) {
370
379
  const opacityConfig = OPACITY_ANIMATION_CONFIG_DEFAULT[type];
371
380
  opacityDefault.value = withTiming(opacityConfig.toValue, opacityConfig);
372
381
  }
373
382
  },
374
- [scale, scaleDefault, opacity, opacityDefault],
383
+ [cellAnimations, scaleDefault, opacityDefault],
375
384
  );
376
385
 
377
386
  useAnimatedReaction(
@@ -467,24 +476,33 @@ export const useReorderableListCore = <T>({
467
476
  const calculateThresholdArea = useCallback(
468
477
  (hiddenArea: {top: number; bottom: number}) => {
469
478
  'worklet';
479
+ const offsetTop = Math.max(0, autoscrollThresholdOffset?.top || 0);
480
+ const offsetBottom = Math.max(0, autoscrollThresholdOffset?.bottom || 0);
470
481
  const threshold = Math.max(0, Math.min(autoscrollThreshold, 0.4));
471
482
  const visibleHeight =
472
- flatListHeightY.value - (hiddenArea.top + hiddenArea.bottom);
483
+ flatListHeightY.value -
484
+ (hiddenArea.top + hiddenArea.bottom) -
485
+ (offsetTop + offsetBottom);
473
486
 
474
- const top = visibleHeight * threshold;
475
- const bottom = flatListHeightY.value - top;
487
+ const area = visibleHeight * threshold;
488
+ const top = area + offsetTop;
489
+ const bottom = flatListHeightY.value - area - offsetBottom;
476
490
 
477
491
  return {top, bottom};
478
492
  },
479
- [autoscrollThreshold, flatListHeightY],
493
+ [autoscrollThreshold, autoscrollThresholdOffset, flatListHeightY],
480
494
  );
481
495
 
482
496
  const calculateThresholdAreaParent = useCallback(
483
497
  (hiddenArea: {top: number; bottom: number}) => {
484
498
  'worklet';
499
+ const offsetTop = Math.max(0, autoscrollThresholdOffset?.top || 0);
500
+ const offsetBottom = Math.max(0, autoscrollThresholdOffset?.bottom || 0);
485
501
  const threshold = Math.max(0, Math.min(autoscrollThreshold, 0.4));
486
- const top = flatListHeightY.value * threshold;
487
- const bottom = flatListHeightY.value - top;
502
+
503
+ const area = flatListHeightY.value * threshold;
504
+ const top = area + offsetTop;
505
+ const bottom = flatListHeightY.value - area - offsetBottom;
488
506
 
489
507
  // if the hidden area is 0 then we don't have a threshold area
490
508
  // we might have floating errors like 0.0001 which we should ignore
@@ -493,7 +511,7 @@ export const useReorderableListCore = <T>({
493
511
  bottom: hiddenArea.bottom > 0.1 ? bottom - hiddenArea.bottom : 0,
494
512
  };
495
513
  },
496
- [autoscrollThreshold, flatListHeightY],
514
+ [autoscrollThreshold, autoscrollThresholdOffset, flatListHeightY],
497
515
  );
498
516
 
499
517
  const shouldScrollParent = useCallback(
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Flattens an object containing `SharedValue`s by extracting their underlying values.
3
+ *
4
+ * @param target - An object to which the flattened shared values and every other field will be mapped to.
5
+ * @param source - The object containing, possibly among others, the shared values.
6
+ * @param excludedKeys - The keys to exclude from flattening and mapping.
7
+ *
8
+ * @returns The object to which the fields where flattened and mapped to.
9
+ */
10
+ export const applyAnimatedStyles = (
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ target: Record<string, any>,
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ source: Record<string, any>,
15
+ excludedKeys: string[] = [],
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ ): Record<string, any> => {
18
+ 'worklet';
19
+
20
+ let keys = Object.keys(source);
21
+
22
+ for (let key of keys) {
23
+ if (excludedKeys.includes(key)) {
24
+ continue;
25
+ }
26
+
27
+ let value = source[key];
28
+
29
+ target[key] =
30
+ value !== null && typeof value === 'object' && 'value' in value
31
+ ? value.value
32
+ : value;
33
+ }
34
+
35
+ return target;
36
+ };
@@ -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';
6
+
5
7
  interface ReorderableListContextData {
6
8
  currentIndex: SharedValue<number>;
7
9
  draggedHeight: SharedValue<number>;
8
10
  dragEndHandlers: SharedValue<((from: number, to: number) => void)[][]>;
9
- scale: SharedValue<number>;
10
- opacity: SharedValue<number>;
11
11
  activeIndex: number;
12
+ cellAnimations: ReorderableListCellAnimations;
12
13
  }
13
14
 
14
15
  export const ReorderableListContext = React.createContext<
package/src/types/misc.ts CHANGED
@@ -1,6 +1,16 @@
1
+ import {SharedValue} from 'react-native-reanimated';
2
+
1
3
  export enum ReorderableListState {
2
4
  IDLE = 0,
3
5
  DRAGGED,
4
6
  RELEASED,
5
7
  AUTOSCROLL,
6
8
  }
9
+
10
+ export type SharedValueOrType<T> = {
11
+ [TKey in keyof T]?: SharedValue<T[TKey]> | T[TKey];
12
+ };
13
+
14
+ export type MaximumOneOf<T, K extends keyof T = keyof T> = K extends keyof T
15
+ ? {[P in K]: T[K]} & {[P in Exclude<keyof T, K>]?: never}
16
+ : never;
@@ -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.
@@ -43,11 +62,16 @@ export interface ReorderableListProps<T>
43
62
  extends Omit<FlatListProps<T>, OmittedProps> {
44
63
  data: T[];
45
64
  /**
46
- * Threshold at the extremety of the list which triggers autoscroll when an item is dragged to it.
65
+ * Threshold at the extremety of the list which triggers autoscroll when an item is dragged to it.
47
66
  * 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
67
  * when an item is dragged to it. Min value: `0`. Max value: `0.4`. Default: `0.1`.
49
68
  */
50
69
  autoscrollThreshold?: number;
70
+ /**
71
+ * Amount by which the threshold is offset at the extremety of the list.
72
+ * For example, setting `{top: 50}` will make the autoscroll trigger 50 pixels earlier at the top.
73
+ */
74
+ autoscrollThresholdOffset?: {top?: number; bottom?: number};
51
75
  /**
52
76
  * Scales the autoscroll spreed at which the list scrolls when an item is dragged to the scroll areas. Default: `1`.
53
77
  */
@@ -71,7 +95,7 @@ export interface ReorderableListProps<T>
71
95
  */
72
96
  animationDuration?: number;
73
97
  /**
74
- * Allows passing an object with shared values that can animate a cell by using the `onDragStart` and `onDragEnd` events.
98
+ * 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
99
  */
76
100
  cellAnimations?: ReorderableListCellAnimations;
77
101
  /**
@@ -104,15 +128,42 @@ export interface ReorderableListProps<T>
104
128
  onDragEnd?: (event: ReorderableListDragEndEvent) => void;
105
129
  }
106
130
 
107
- export interface ReorderableListCellAnimations {
131
+ export type Transforms = PerspectiveTransform &
132
+ RotateTransform &
133
+ RotateXTransform &
134
+ RotateYTransform &
135
+ RotateZTransform &
136
+ ScaleTransform &
137
+ ScaleXTransform &
138
+ ScaleYTransform &
139
+ TranslateXTransform &
140
+ TranslateYTransform &
141
+ SkewXTransform &
142
+ SkewYTransform &
143
+ MatrixTransform;
144
+
145
+ export type ReorderableListCellAnimatedStyles = Omit<
146
+ {
147
+ [StyleKey in keyof ViewStyle]?:
148
+ | SharedValue<ViewStyle[StyleKey]>
149
+ | ViewStyle[StyleKey];
150
+ },
151
+ // omit custom type and type with JSDoc
152
+ 'transform' | 'opacity'
153
+ >;
154
+
155
+ export interface ReorderableListCellAnimations
156
+ extends ReorderableListCellAnimatedStyles {
108
157
  /**
109
- * Shared value to animate the opacity of a dragged item. Set to false to disable default opacity animations.
158
+ * Transform animations for a dragged item.
159
+ * Disable default animation by overriding transform, e.g. `[]` or `[{ scale: customSharedValue }]`.
110
160
  */
111
- opacity?: SharedValue<number> | false;
161
+ transform?: Readonly<MaximumOneOf<SharedValueOrType<Transforms>>[]>;
112
162
  /**
113
- * Shared value to animate the scale of a dragged item. Set to false to disable default scale animations.
163
+ * Shared value to animate the opacity of a dragged item.
164
+ * Disable default animation by overriding opacity, e.g `1`.
114
165
  */
115
- scale?: SharedValue<number> | false;
166
+ opacity?: SharedValue<number> | number;
116
167
  }
117
168
 
118
169
  export interface ScrollViewContainerProps