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 +1 @@
1
- {"version":3,"file":"useReorderableListCore.d.ts","sourceRoot":"","sources":["../../../../src/components/ReorderableListCore/useReorderableListCore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,UAAU,EAEX,MAAM,cAAc,CAAC;AAGtB,OAAiB,EAGf,WAAW,EAUZ,MAAM,yBAAyB,CAAC;AAOjC,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,6BAA6B,EAE9B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAC,2BAA2B,EAAC,MAAM,aAAa,CAAC;AAO7D,UAAU,0BAA0B,CAAC,CAAC;IACpC,GAAG,EAAE,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,IAAI,CAAC;IACxD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,6BAA6B,KAAK,IAAI,CAAC;IAC7D,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,IAAI,CAAC;IACzD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC9C,sBAAsB,EAAE,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC;IAChE,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACnD,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACzD,uBAAuB,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAC1D,oBAAoB,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1C,8BAA8B,EAAE,OAAO,GAAG,SAAS,CAAC;IACpD,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,cAAc,EAAE,6BAA6B,GAAG,SAAS,CAAC;IAC1D,sBAAsB,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5C,UAAU,EAAE,OAAO,CAAC;IACpB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/C;AAED,eAAO,MAAM,sBAAsB;;;;;uBAolBvB,MAAM;;;;;6CAniBN,MAAM,MAAM,MAAM,KAAK,IAAI;;;;;;;;;;CAsnBtC,CAAC"}
1
+ {"version":3,"file":"useReorderableListCore.d.ts","sourceRoot":"","sources":["../../../../src/components/ReorderableListCore/useReorderableListCore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,UAAU,EAEX,MAAM,cAAc,CAAC;AAGtB,OAAiB,EAGf,WAAW,EAUZ,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B,EAAE,OAAO,GAAG,SAAS,CAAC;IACpD,gBAAgB,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,cAAc,EAAE,6BAA6B,GAAG,SAAS,CAAC;IAC1D,sBAAsB,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5C,UAAU,EAAE,OAAO,CAAC;IACpB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/C;AAED,eAAO,MAAM,sBAAsB;;;;;uBAymBvB,MAAM;;;;;6CAtjBN,MAAM,MAAM,MAAM,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyoBtC,CAAC"}
@@ -0,0 +1,11 @@
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 declare const applyAnimatedStyles: (target: Record<string, any>, source: Record<string, any>, excludedKeys?: string[]) => Record<string, any>;
11
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/components/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,WAEtB,OAAO,MAAM,EAAE,GAAG,CAAC,UAEnB,OAAO,MAAM,EAAE,GAAG,CAAC,iBACb,MAAM,EAAE,KAErB,OAAO,MAAM,EAAE,GAAG,CAmBpB,CAAC"}
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
  import type { SharedValue } from 'react-native-reanimated';
3
+ import { ReorderableListCellAnimations } from '../types';
3
4
  interface ReorderableListContextData {
4
5
  currentIndex: SharedValue<number>;
5
6
  draggedHeight: SharedValue<number>;
6
7
  dragEndHandlers: SharedValue<((from: number, to: number) => void)[][]>;
7
- scale: SharedValue<number>;
8
- opacity: SharedValue<number>;
9
8
  activeIndex: number;
9
+ cellAnimations: ReorderableListCellAnimations;
10
10
  }
11
11
  export declare const ReorderableListContext: React.Context<ReorderableListContextData | undefined>;
12
12
  export {};
@@ -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,7 @@
1
1
  import { NestedReorderableList, ReorderableList, ScrollViewContainer } from './components';
2
2
  import { useIsActive, useReorderableDrag, useReorderableDragEnd, useReorderableDragStart } from './hooks';
3
- import type { ReorderableListCellAnimations, ReorderableListDragEndEvent, ReorderableListDragStartEvent, ReorderableListProps, ReorderableListReorderEvent, ScrollViewContainerProps } from './types';
3
+ import type { ReorderableListCellAnimations, ReorderableListDragEndEvent, ReorderableListDragStartEvent, ReorderableListIndexChangeEvent, ReorderableListProps, ReorderableListReorderEvent, ScrollViewContainerProps } from './types';
4
4
  import { reorderItems } from './utils';
5
- export { useIsActive, useReorderableDrag, useReorderableDragStart, useReorderableDragEnd, ReorderableListProps, ReorderableListReorderEvent, ReorderableListCellAnimations, ReorderableListDragStartEvent, ReorderableListDragEndEvent, ScrollViewContainer, ScrollViewContainerProps, NestedReorderableList, reorderItems, };
5
+ export { useIsActive, useReorderableDrag, useReorderableDragStart, useReorderableDragEnd, ReorderableListProps, ReorderableListReorderEvent, ReorderableListCellAnimations, ReorderableListDragStartEvent, ReorderableListDragEndEvent, ReorderableListIndexChangeEvent, ScrollViewContainer, ScrollViewContainerProps, NestedReorderableList, reorderItems, };
6
6
  export default ReorderableList;
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,wBAAwB,EACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AAErC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,6BAA6B,EAC7B,2BAA2B,EAC3B,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,YAAY,GACb,CAAC;AACF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,6BAA6B,EAC7B,+BAA+B,EAC/B,oBAAoB,EACpB,2BAA2B,EAC3B,wBAAwB,EACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AAErC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,6BAA6B,EAC7B,2BAA2B,EAC3B,+BAA+B,EAC/B,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EACrB,YAAY,GACb,CAAC;AACF,eAAe,eAAe,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.
@@ -16,6 +17,12 @@ export interface ReorderableListDragStartEvent {
16
17
  */
17
18
  index: number;
18
19
  }
20
+ export interface ReorderableListIndexChangeEvent {
21
+ /**
22
+ * Index of the dragged item.
23
+ */
24
+ index: number;
25
+ }
19
26
  export interface ReorderableListDragEndEvent {
20
27
  /**
21
28
  * Index of the dragged item.
@@ -30,11 +37,19 @@ type OmittedProps = 'horizontal' | 'onScroll' | 'scrollEventThrottle' | 'removeC
30
37
  export interface ReorderableListProps<T> extends Omit<FlatListProps<T>, OmittedProps> {
31
38
  data: T[];
32
39
  /**
33
- * Threshold at the extremety of the list which triggers autoscroll when an item is dragged to it.
40
+ * Threshold at the extremety of the list which triggers autoscroll when an item is dragged to it.
34
41
  * 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
42
  * when an item is dragged to it. Min value: `0`. Max value: `0.4`. Default: `0.1`.
36
43
  */
37
44
  autoscrollThreshold?: number;
45
+ /**
46
+ * Amount by which the threshold is offset at the extremety of the list.
47
+ * For example, setting `{top: 50}` will make the autoscroll trigger 50 pixels earlier at the top.
48
+ */
49
+ autoscrollThresholdOffset?: {
50
+ top?: number;
51
+ bottom?: number;
52
+ };
38
53
  /**
39
54
  * Scales the autoscroll spreed at which the list scrolls when an item is dragged to the scroll areas. Default: `1`.
40
55
  */
@@ -58,7 +73,7 @@ export interface ReorderableListProps<T> extends Omit<FlatListProps<T>, OmittedP
58
73
  */
59
74
  animationDuration?: number;
60
75
  /**
61
- * Allows passing an object with shared values that can animate a cell by using the `onDragStart` and `onDragEnd` events.
76
+ * 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
77
  */
63
78
  cellAnimations?: ReorderableListCellAnimations;
64
79
  /**
@@ -70,7 +85,7 @@ export interface ReorderableListProps<T> extends Omit<FlatListProps<T>, OmittedP
70
85
  */
71
86
  panEnabled?: boolean;
72
87
  /**
73
- * Duration in milliseconds of a long press on the list before pan gestures, necessary for dragging, are allowed to activate.
88
+ * Duration in milliseconds of the long press on the list before the pan gesture for dragging is allowed to activate.
74
89
  */
75
90
  panActivateAfterLongPress?: number;
76
91
  /**
@@ -89,16 +104,26 @@ export interface ReorderableListProps<T> extends Omit<FlatListProps<T>, OmittedP
89
104
  * 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.
90
105
  */
91
106
  onDragEnd?: (event: ReorderableListDragEndEvent) => void;
107
+ /**
108
+ * 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.
109
+ */
110
+ onIndexChange?: (event: ReorderableListIndexChangeEvent) => void;
92
111
  }
93
- export interface ReorderableListCellAnimations {
112
+ export type Transforms = PerspectiveTransform & RotateTransform & RotateXTransform & RotateYTransform & RotateZTransform & ScaleTransform & ScaleXTransform & ScaleYTransform & TranslateXTransform & TranslateYTransform & SkewXTransform & SkewYTransform & MatrixTransform;
113
+ export type ReorderableListCellAnimatedStyles = Omit<{
114
+ [StyleKey in keyof ViewStyle]?: SharedValue<ViewStyle[StyleKey]> | ViewStyle[StyleKey];
115
+ }, 'transform' | 'opacity'>;
116
+ export interface ReorderableListCellAnimations extends ReorderableListCellAnimatedStyles {
94
117
  /**
95
- * Shared value to animate the opacity of a dragged item. Set to false to disable default opacity animations.
118
+ * Transform animations for a dragged item.
119
+ * Disable default animation by overriding transform, e.g. `[]` or `[{ scale: customSharedValue }]`.
96
120
  */
97
- opacity?: SharedValue<number> | false;
121
+ transform?: Readonly<MaximumOneOf<SharedValueOrType<Transforms>>[]>;
98
122
  /**
99
- * Shared value to animate the scale of a dragged item. Set to false to disable default scale animations.
123
+ * Shared value to animate the opacity of a dragged item.
124
+ * Disable default animation by overriding opacity, e.g `1`.
100
125
  */
101
- scale?: SharedValue<number> | false;
126
+ opacity?: SharedValue<number> | number;
102
127
  }
103
128
  export interface ScrollViewContainerProps extends Omit<ScrollViewProps, 'onScroll'> {
104
129
  /**
@@ -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;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YAAY,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;IACpE;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CACxC;AAED,MAAM,WAAW,wBACf,SAAQ,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC;IACzC;;OAEG;IACH,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC;CACxD;AAED,MAAM,WAAW,0BAA0B,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.11.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,
@@ -53,6 +54,7 @@ const ReorderableListCore = <T,>(
53
54
  onScroll,
54
55
  onDragStart,
55
56
  onDragEnd,
57
+ onIndexChange,
56
58
  scrollViewContainerRef,
57
59
  scrollViewHeightY,
58
60
  scrollViewScrollOffsetY,
@@ -83,6 +85,7 @@ const ReorderableListCore = <T,>(
83
85
  } = useReorderableListCore({
84
86
  ref,
85
87
  autoscrollThreshold,
88
+ autoscrollThresholdOffset,
86
89
  autoscrollSpeedScale,
87
90
  autoscrollDelay,
88
91
  animationDuration,
@@ -91,6 +94,7 @@ const ReorderableListCore = <T,>(
91
94
  onReorder,
92
95
  onDragStart,
93
96
  onDragEnd,
97
+ onIndexChange,
94
98
  scrollViewContainerRef,
95
99
  scrollViewHeightY,
96
100
  scrollViewScrollOffsetY,
@@ -31,6 +31,7 @@ import {
31
31
  ReorderableListCellAnimations,
32
32
  ReorderableListDragEndEvent,
33
33
  ReorderableListDragStartEvent,
34
+ ReorderableListIndexChangeEvent,
34
35
  ReorderableListState,
35
36
  } from '../../types';
36
37
  import type {ReorderableListReorderEvent} from '../../types';
@@ -43,6 +44,7 @@ const hasAutomaticBatching = version.length
43
44
  interface UseReorderableListCoreArgs<T> {
44
45
  ref: React.ForwardedRef<FlatList<T>>;
45
46
  autoscrollThreshold: number;
47
+ autoscrollThresholdOffset: {top?: number; bottom?: number} | undefined;
46
48
  autoscrollSpeedScale: number;
47
49
  autoscrollDelay: number;
48
50
  animationDuration: number;
@@ -50,6 +52,7 @@ interface UseReorderableListCoreArgs<T> {
50
52
  onReorder: (event: ReorderableListReorderEvent) => void;
51
53
  onDragStart?: (event: ReorderableListDragStartEvent) => void;
52
54
  onDragEnd?: (event: ReorderableListDragEndEvent) => void;
55
+ onIndexChange?: (event: ReorderableListIndexChangeEvent) => void;
53
56
  onLayout?: (event: LayoutChangeEvent) => void;
54
57
  scrollViewContainerRef: React.RefObject<ScrollView> | undefined;
55
58
  scrollViewHeightY: SharedValue<number> | undefined;
@@ -67,6 +70,7 @@ interface UseReorderableListCoreArgs<T> {
67
70
  export const useReorderableListCore = <T>({
68
71
  ref,
69
72
  autoscrollThreshold,
73
+ autoscrollThresholdOffset,
70
74
  autoscrollSpeedScale,
71
75
  autoscrollDelay,
72
76
  animationDuration,
@@ -75,6 +79,7 @@ export const useReorderableListCore = <T>({
75
79
  onDragStart,
76
80
  onDragEnd,
77
81
  onLayout,
82
+ onIndexChange,
78
83
  scrollViewContainerRef,
79
84
  scrollViewHeightY,
80
85
  scrollViewScrollOffsetY,
@@ -119,7 +124,6 @@ export const useReorderableListCore = <T>({
119
124
  const duration = useSharedValue(animationDuration);
120
125
  const scaleDefault = useSharedValue(1);
121
126
  const opacityDefault = useSharedValue(1);
122
- const {scale, opacity} = cellAnimations || {};
123
127
 
124
128
  useEffect(() => {
125
129
  duration.value = animationDuration;
@@ -132,8 +136,17 @@ export const useReorderableListCore = <T>({
132
136
  draggedIndex,
133
137
  dragEndHandlers,
134
138
  activeIndex,
135
- scale: scale || scaleDefault,
136
- opacity: opacity || opacityDefault,
139
+ cellAnimations: {
140
+ ...cellAnimations,
141
+ transform:
142
+ cellAnimations && 'transform' in cellAnimations
143
+ ? cellAnimations.transform
144
+ : [{scale: scaleDefault}],
145
+ opacity:
146
+ cellAnimations && 'opacity' in cellAnimations
147
+ ? cellAnimations.opacity
148
+ : opacityDefault,
149
+ },
137
150
  }),
138
151
  [
139
152
  draggedHeight,
@@ -141,9 +154,8 @@ export const useReorderableListCore = <T>({
141
154
  draggedIndex,
142
155
  dragEndHandlers,
143
156
  activeIndex,
144
- scale,
157
+ cellAnimations,
145
158
  scaleDefault,
146
- opacity,
147
159
  opacityDefault,
148
160
  ],
149
161
  );
@@ -342,6 +354,8 @@ export const useReorderableListCore = <T>({
342
354
  previousDirection.value = newDirection;
343
355
  previousIndex.value = currentIndex.value;
344
356
  currentIndex.value = newIndex;
357
+
358
+ onIndexChange?.({index: newIndex});
345
359
  }
346
360
  },
347
361
  [
@@ -352,6 +366,7 @@ export const useReorderableListCore = <T>({
352
366
  itemOffset,
353
367
  itemHeight,
354
368
  getIndexFromY,
369
+ onIndexChange,
355
370
  ],
356
371
  );
357
372
 
@@ -359,19 +374,19 @@ export const useReorderableListCore = <T>({
359
374
  (type: 'start' | 'end') => {
360
375
  'worklet';
361
376
 
362
- // if animation is not disabled and not custom run the default
363
- if (scale !== false && !scale) {
377
+ // if no custom scale run default
378
+ if (!(cellAnimations && 'transformtra' in cellAnimations)) {
364
379
  const scaleConfig = SCALE_ANIMATION_CONFIG_DEFAULT[type];
365
380
  scaleDefault.value = withTiming(scaleConfig.toValue, scaleConfig);
366
381
  }
367
382
 
368
- // if animation is not disabled and not custom run the default
369
- if (opacity !== false && !opacity) {
383
+ // if no custom opacity run the default
384
+ if (!(cellAnimations && 'opacity' in cellAnimations)) {
370
385
  const opacityConfig = OPACITY_ANIMATION_CONFIG_DEFAULT[type];
371
386
  opacityDefault.value = withTiming(opacityConfig.toValue, opacityConfig);
372
387
  }
373
388
  },
374
- [scale, scaleDefault, opacity, opacityDefault],
389
+ [cellAnimations, scaleDefault, opacityDefault],
375
390
  );
376
391
 
377
392
  useAnimatedReaction(
@@ -467,24 +482,33 @@ export const useReorderableListCore = <T>({
467
482
  const calculateThresholdArea = useCallback(
468
483
  (hiddenArea: {top: number; bottom: number}) => {
469
484
  'worklet';
485
+ const offsetTop = Math.max(0, autoscrollThresholdOffset?.top || 0);
486
+ const offsetBottom = Math.max(0, autoscrollThresholdOffset?.bottom || 0);
470
487
  const threshold = Math.max(0, Math.min(autoscrollThreshold, 0.4));
471
488
  const visibleHeight =
472
- flatListHeightY.value - (hiddenArea.top + hiddenArea.bottom);
489
+ flatListHeightY.value -
490
+ (hiddenArea.top + hiddenArea.bottom) -
491
+ (offsetTop + offsetBottom);
473
492
 
474
- const top = visibleHeight * threshold;
475
- const bottom = flatListHeightY.value - top;
493
+ const area = visibleHeight * threshold;
494
+ const top = area + offsetTop;
495
+ const bottom = flatListHeightY.value - area - offsetBottom;
476
496
 
477
497
  return {top, bottom};
478
498
  },
479
- [autoscrollThreshold, flatListHeightY],
499
+ [autoscrollThreshold, autoscrollThresholdOffset, flatListHeightY],
480
500
  );
481
501
 
482
502
  const calculateThresholdAreaParent = useCallback(
483
503
  (hiddenArea: {top: number; bottom: number}) => {
484
504
  'worklet';
505
+ const offsetTop = Math.max(0, autoscrollThresholdOffset?.top || 0);
506
+ const offsetBottom = Math.max(0, autoscrollThresholdOffset?.bottom || 0);
485
507
  const threshold = Math.max(0, Math.min(autoscrollThreshold, 0.4));
486
- const top = flatListHeightY.value * threshold;
487
- const bottom = flatListHeightY.value - top;
508
+
509
+ const area = flatListHeightY.value * threshold;
510
+ const top = area + offsetTop;
511
+ const bottom = flatListHeightY.value - area - offsetBottom;
488
512
 
489
513
  // if the hidden area is 0 then we don't have a threshold area
490
514
  // we might have floating errors like 0.0001 which we should ignore
@@ -493,7 +517,7 @@ export const useReorderableListCore = <T>({
493
517
  bottom: hiddenArea.bottom > 0.1 ? bottom - hiddenArea.bottom : 0,
494
518
  };
495
519
  },
496
- [autoscrollThreshold, flatListHeightY],
520
+ [autoscrollThreshold, autoscrollThresholdOffset, flatListHeightY],
497
521
  );
498
522
 
499
523
  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/index.ts CHANGED
@@ -13,6 +13,7 @@ import type {
13
13
  ReorderableListCellAnimations,
14
14
  ReorderableListDragEndEvent,
15
15
  ReorderableListDragStartEvent,
16
+ ReorderableListIndexChangeEvent,
16
17
  ReorderableListProps,
17
18
  ReorderableListReorderEvent,
18
19
  ScrollViewContainerProps,
@@ -29,6 +30,7 @@ export {
29
30
  ReorderableListCellAnimations,
30
31
  ReorderableListDragStartEvent,
31
32
  ReorderableListDragEndEvent,
33
+ ReorderableListIndexChangeEvent,
32
34
  ScrollViewContainer,
33
35
  ScrollViewContainerProps,
34
36
  NestedReorderableList,
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;