react-native-reorderable-list 0.7.1 → 0.8.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 (85) hide show
  1. package/README.md +53 -47
  2. package/lib/commonjs/components/ReorderableList.js +11 -13
  3. package/lib/commonjs/components/ReorderableList.js.map +1 -1
  4. package/lib/commonjs/components/ReorderableListCell.js +39 -29
  5. package/lib/commonjs/components/ReorderableListCell.js.map +1 -1
  6. package/lib/commonjs/components/ReorderableListCore/ReorderableListCore.js +10 -7
  7. package/lib/commonjs/components/ReorderableListCore/ReorderableListCore.js.map +1 -1
  8. package/lib/commonjs/components/ReorderableListCore/animationDefaults.js +34 -0
  9. package/lib/commonjs/components/ReorderableListCore/animationDefaults.js.map +1 -0
  10. package/lib/commonjs/components/ReorderableListCore/{constants.js → autoscrollConfig.js} +1 -1
  11. package/lib/commonjs/components/ReorderableListCore/autoscrollConfig.js.map +1 -0
  12. package/lib/commonjs/components/ReorderableListCore/useReorderableListCore.js +61 -32
  13. package/lib/commonjs/components/ReorderableListCore/useReorderableListCore.js.map +1 -1
  14. package/lib/commonjs/components/ScrollViewContainer.js +2 -2
  15. package/lib/commonjs/components/ScrollViewContainer.js.map +1 -1
  16. package/lib/commonjs/components/index.js +0 -11
  17. package/lib/commonjs/components/index.js.map +1 -1
  18. package/lib/commonjs/contexts/ReorderableListContext.js.map +1 -1
  19. package/lib/commonjs/index.js +0 -6
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/types/misc.js +3 -3
  22. package/lib/module/components/ReorderableList.js +11 -13
  23. package/lib/module/components/ReorderableList.js.map +1 -1
  24. package/lib/module/components/ReorderableListCell.js +40 -30
  25. package/lib/module/components/ReorderableListCell.js.map +1 -1
  26. package/lib/module/components/ReorderableListCore/ReorderableListCore.js +9 -5
  27. package/lib/module/components/ReorderableListCore/ReorderableListCore.js.map +1 -1
  28. package/lib/module/components/ReorderableListCore/animationDefaults.js +28 -0
  29. package/lib/module/components/ReorderableListCore/animationDefaults.js.map +1 -0
  30. package/lib/module/components/ReorderableListCore/{constants.js → autoscrollConfig.js} +1 -1
  31. package/lib/module/components/ReorderableListCore/autoscrollConfig.js.map +1 -0
  32. package/lib/module/components/ReorderableListCore/useReorderableListCore.js +60 -31
  33. package/lib/module/components/ReorderableListCore/useReorderableListCore.js.map +1 -1
  34. package/lib/module/components/ScrollViewContainer.js +3 -3
  35. package/lib/module/components/ScrollViewContainer.js.map +1 -1
  36. package/lib/module/components/index.js +0 -1
  37. package/lib/module/components/index.js.map +1 -1
  38. package/lib/module/contexts/ReorderableListContext.js.map +1 -1
  39. package/lib/module/index.js +2 -2
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/module/types/misc.js +3 -3
  42. package/lib/typescript/components/ReorderableList.d.ts.map +1 -1
  43. package/lib/typescript/components/ReorderableListCell.d.ts +1 -1
  44. package/lib/typescript/components/ReorderableListCell.d.ts.map +1 -1
  45. package/lib/typescript/components/ReorderableListCore/ReorderableListCore.d.ts.map +1 -1
  46. package/lib/typescript/components/ReorderableListCore/animationDefaults.d.ts +13 -0
  47. package/lib/typescript/components/ReorderableListCore/animationDefaults.d.ts.map +1 -0
  48. package/lib/typescript/components/ReorderableListCore/{constants.d.ts → autoscrollConfig.d.ts} +1 -1
  49. package/lib/typescript/components/ReorderableListCore/autoscrollConfig.d.ts.map +1 -0
  50. package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts +7 -4
  51. package/lib/typescript/components/ReorderableListCore/useReorderableListCore.d.ts.map +1 -1
  52. package/lib/typescript/components/ScrollViewContainer.d.ts.map +1 -1
  53. package/lib/typescript/components/index.d.ts +0 -1
  54. package/lib/typescript/components/index.d.ts.map +1 -1
  55. package/lib/typescript/contexts/ReorderableListContext.d.ts +2 -0
  56. package/lib/typescript/contexts/ReorderableListContext.d.ts.map +1 -1
  57. package/lib/typescript/index.d.ts +3 -3
  58. package/lib/typescript/index.d.ts.map +1 -1
  59. package/lib/typescript/types/misc.d.ts +3 -3
  60. package/lib/typescript/types/misc.d.ts.map +1 -1
  61. package/lib/typescript/types/props.d.ts +25 -37
  62. package/lib/typescript/types/props.d.ts.map +1 -1
  63. package/package.json +5 -5
  64. package/src/components/ReorderableList.tsx +14 -16
  65. package/src/components/ReorderableListCell.tsx +36 -32
  66. package/src/components/ReorderableListCore/ReorderableListCore.tsx +15 -4
  67. package/src/components/ReorderableListCore/animationDefaults.ts +35 -0
  68. package/src/components/ReorderableListCore/useReorderableListCore.ts +84 -37
  69. package/src/components/ScrollViewContainer.tsx +7 -3
  70. package/src/components/index.ts +0 -1
  71. package/src/contexts/ReorderableListContext.ts +2 -0
  72. package/src/index.ts +4 -6
  73. package/src/types/misc.ts +3 -3
  74. package/src/types/props.ts +26 -43
  75. package/lib/commonjs/components/ReorderableListCore/constants.js.map +0 -1
  76. package/lib/commonjs/components/ReorderableListItem.js +0 -87
  77. package/lib/commonjs/components/ReorderableListItem.js.map +0 -1
  78. package/lib/module/components/ReorderableListCore/constants.js.map +0 -1
  79. package/lib/module/components/ReorderableListItem.js +0 -78
  80. package/lib/module/components/ReorderableListItem.js.map +0 -1
  81. package/lib/typescript/components/ReorderableListCore/constants.d.ts.map +0 -1
  82. package/lib/typescript/components/ReorderableListItem.d.ts +0 -4
  83. package/lib/typescript/components/ReorderableListItem.d.ts.map +0 -1
  84. package/src/components/ReorderableListItem.tsx +0 -108
  85. /package/src/components/ReorderableListCore/{constants.ts → autoscrollConfig.ts} +0 -0
@@ -2,7 +2,6 @@ import React, {useCallback, useEffect, useMemo} from 'react';
2
2
  import {
3
3
  FlatList,
4
4
  LayoutChangeEvent,
5
- NativeScrollEvent,
6
5
  ScrollView,
7
6
  unstable_batchedUpdates,
8
7
  } from 'react-native';
@@ -23,8 +22,17 @@ import Animated, {
23
22
  withTiming,
24
23
  } from 'react-native-reanimated';
25
24
 
26
- import {AUTOSCROLL_CONFIG} from './constants';
27
- import {ReorderableListDragEndEvent, ReorderableListState} from '../../types';
25
+ import {
26
+ OPACITY_ANIMATION_CONFIG_DEFAULT,
27
+ SCALE_ANIMATION_CONFIG_DEFAULT,
28
+ } from './animationDefaults';
29
+ import {AUTOSCROLL_CONFIG} from './autoscrollConfig';
30
+ import {
31
+ ReorderableListCellAnimations,
32
+ ReorderableListDragEndEvent,
33
+ ReorderableListDragStartEvent,
34
+ ReorderableListState,
35
+ } from '../../types';
28
36
  import type {ReorderableListReorderEvent} from '../../types';
29
37
 
30
38
  const version = React.version.split('.');
@@ -40,8 +48,8 @@ interface UseReorderableListCoreArgs<T> {
40
48
  animationDuration: number;
41
49
  dragReorderThreshold: number;
42
50
  onReorder: (event: ReorderableListReorderEvent) => void;
51
+ onDragStart?: (event: ReorderableListDragStartEvent) => void;
43
52
  onDragEnd?: (event: ReorderableListDragEndEvent) => void;
44
- onScroll?: (event: NativeScrollEvent) => void;
45
53
  onLayout?: (event: LayoutChangeEvent) => void;
46
54
  scrollViewContainerRef: React.RefObject<ScrollView> | undefined;
47
55
  scrollViewHeightY: SharedValue<number> | undefined;
@@ -50,6 +58,7 @@ interface UseReorderableListCoreArgs<T> {
50
58
  initialScrollEnabled: boolean | undefined;
51
59
  initialScrollViewScrollEnabled: boolean | undefined;
52
60
  nestedScrollable: boolean | undefined;
61
+ cellAnimations: ReorderableListCellAnimations | undefined;
53
62
  }
54
63
 
55
64
  export const useReorderableListCore = <T>({
@@ -60,8 +69,8 @@ export const useReorderableListCore = <T>({
60
69
  animationDuration,
61
70
  dragReorderThreshold,
62
71
  onReorder,
72
+ onDragStart,
63
73
  onDragEnd,
64
- onScroll,
65
74
  onLayout,
66
75
  scrollViewContainerRef,
67
76
  scrollViewHeightY,
@@ -70,6 +79,7 @@ export const useReorderableListCore = <T>({
70
79
  initialScrollEnabled,
71
80
  initialScrollViewScrollEnabled,
72
81
  nestedScrollable,
82
+ cellAnimations,
73
83
  }: UseReorderableListCoreArgs<T>) => {
74
84
  const flatListRef = useAnimatedRef<FlatList>();
75
85
  const scrollEnabled = useSharedValue(initialScrollEnabled);
@@ -100,6 +110,9 @@ export const useReorderableListCore = <T>({
100
110
  >([]);
101
111
  const startY = useSharedValue(0);
102
112
  const duration = useSharedValue(animationDuration);
113
+ const scaleDefault = useSharedValue(1);
114
+ const opacityDefault = useSharedValue(1);
115
+ const {scale, opacity} = cellAnimations || {};
103
116
 
104
117
  useEffect(() => {
105
118
  duration.value = animationDuration;
@@ -111,8 +124,19 @@ export const useReorderableListCore = <T>({
111
124
  currentIndex,
112
125
  draggedIndex,
113
126
  dragEndHandlers,
127
+ scale: scale || scaleDefault,
128
+ opacity: opacity || opacityDefault,
114
129
  }),
115
- [draggedHeight, currentIndex, draggedIndex, dragEndHandlers],
130
+ [
131
+ draggedHeight,
132
+ currentIndex,
133
+ draggedIndex,
134
+ dragEndHandlers,
135
+ scale,
136
+ scaleDefault,
137
+ opacity,
138
+ opacityDefault,
139
+ ],
116
140
  );
117
141
 
118
142
  const panGestureHandler = useMemo(
@@ -124,22 +148,18 @@ export const useReorderableListCore = <T>({
124
148
  startY.value = e.y;
125
149
  currentY.value = e.y;
126
150
  currentTranslationY.value = e.translationY;
127
- if (draggedIndex.value >= 0) {
128
- dragY.value = e.translationY;
129
- }
151
+ dragY.value = e.translationY;
130
152
  gestureState.value = e.state;
131
153
  }
132
154
  })
133
155
  .onUpdate(e => {
134
- if (state.value !== ReorderableListState.RELEASING) {
156
+ if (state.value !== ReorderableListState.RELEASED) {
135
157
  currentY.value = startY.value + e.translationY;
136
158
  currentTranslationY.value = e.translationY;
137
- if (draggedIndex.value >= 0) {
138
- dragY.value =
139
- e.translationY +
140
- dragScrollTranslationY.value +
141
- scrollViewDragScrollTranslationY.value;
142
- }
159
+ dragY.value =
160
+ e.translationY +
161
+ dragScrollTranslationY.value +
162
+ scrollViewDragScrollTranslationY.value;
143
163
  gestureState.value = e.state;
144
164
  }
145
165
  })
@@ -150,7 +170,6 @@ export const useReorderableListCore = <T>({
150
170
  currentY,
151
171
  dragScrollTranslationY,
152
172
  scrollViewDragScrollTranslationY,
153
- draggedIndex,
154
173
  gestureState,
155
174
  dragY,
156
175
  startY,
@@ -195,21 +214,23 @@ export const useReorderableListCore = <T>({
195
214
  const resetSharedValues = useCallback(() => {
196
215
  'worklet';
197
216
 
198
- // current index is reset on item render for the on end event
199
- draggedIndex.value = -1;
200
- // released flag is reset after release is triggered in the item
201
217
  state.value = ReorderableListState.IDLE;
218
+ draggedIndex.value = -1;
202
219
  dragY.value = 0;
203
220
  dragScrollTranslationY.value = 0;
204
221
  scrollViewDragScrollTranslationY.value = 0;
205
222
  }, [
223
+ draggedIndex,
206
224
  dragY,
207
225
  dragScrollTranslationY,
208
226
  scrollViewDragScrollTranslationY,
209
- draggedIndex,
210
227
  state,
211
228
  ]);
212
229
 
230
+ const resetSharedValuesAfterAnimations = useCallback(() => {
231
+ setTimeout(runOnUI(resetSharedValues), duration.value);
232
+ }, [resetSharedValues, duration]);
233
+
213
234
  const reorder = (fromIndex: number, toIndex: number) => {
214
235
  runOnUI(resetSharedValues)();
215
236
 
@@ -313,19 +334,39 @@ export const useReorderableListCore = <T>({
313
334
  ],
314
335
  );
315
336
 
337
+ const runDefaultDragAnimations = useCallback(
338
+ (type: 'start' | 'end') => {
339
+ 'worklet';
340
+
341
+ // if animation is not disabled and not custom run the default
342
+ if (scale !== false && !scale) {
343
+ const scaleConfig = SCALE_ANIMATION_CONFIG_DEFAULT[type];
344
+ scaleDefault.value = withTiming(scaleConfig.toValue, scaleConfig);
345
+ }
346
+
347
+ // if animation is not disabled and not custom run the default
348
+ if (opacity !== false && !opacity) {
349
+ const opacityConfig = OPACITY_ANIMATION_CONFIG_DEFAULT[type];
350
+ opacityDefault.value = withTiming(opacityConfig.toValue, opacityConfig);
351
+ }
352
+ },
353
+ [scale, scaleDefault, opacity, opacityDefault],
354
+ );
355
+
316
356
  useAnimatedReaction(
317
357
  () => gestureState.value,
318
358
  () => {
319
359
  if (
320
360
  gestureState.value !== State.ACTIVE &&
321
361
  gestureState.value !== State.BEGAN &&
322
- (state.value === ReorderableListState.DRAGGING ||
323
- state.value === ReorderableListState.AUTO_SCROLL)
362
+ (state.value === ReorderableListState.DRAGGED ||
363
+ state.value === ReorderableListState.AUTOSCROLL)
324
364
  ) {
325
- state.value = ReorderableListState.RELEASING;
365
+ state.value = ReorderableListState.RELEASED;
326
366
 
327
367
  // enable back scroll on releasing
328
368
  runOnJS(setScrollEnabled)(true);
369
+
329
370
  // trigger onDragEnd event
330
371
  let e = {from: draggedIndex.value, to: currentIndex.value};
331
372
  onDragEnd?.(e);
@@ -348,6 +389,8 @@ export const useReorderableListCore = <T>({
348
389
  currentItemOffset +
349
390
  (draggedItemHeight - currentItemHeight);
350
391
 
392
+ runDefaultDragAnimations('end');
393
+
351
394
  if (dragY.value !== newTopPosition) {
352
395
  // animate dragged item to its new position on release
353
396
  dragY.value = withTiming(
@@ -364,7 +407,7 @@ export const useReorderableListCore = <T>({
364
407
  // user might drag and release the item without moving it so,
365
408
  // since the animation end callback is not executed in that case
366
409
  // we need to reset values as the reorder function would do
367
- resetSharedValues();
410
+ runOnJS(resetSharedValuesAfterAnimations)();
368
411
  }
369
412
  }
370
413
  },
@@ -485,20 +528,20 @@ export const useReorderableListCore = <T>({
485
528
  () => currentY.value + scrollViewDragScrollTranslationY.value,
486
529
  y => {
487
530
  if (
488
- state.value === ReorderableListState.DRAGGING ||
489
- state.value === ReorderableListState.AUTO_SCROLL
531
+ state.value === ReorderableListState.DRAGGED ||
532
+ state.value === ReorderableListState.AUTOSCROLL
490
533
  ) {
491
534
  setCurrentIndex(y);
492
535
 
493
536
  if (scrollDirection(y) !== 0) {
494
- if (state.value !== ReorderableListState.AUTO_SCROLL) {
537
+ if (state.value !== ReorderableListState.AUTOSCROLL) {
495
538
  // trigger autoscroll
496
539
  lastAutoscrollTrigger.value = autoscrollTrigger.value;
497
540
  autoscrollTrigger.value *= -1;
498
- state.value = ReorderableListState.AUTO_SCROLL;
541
+ state.value = ReorderableListState.AUTOSCROLL;
499
542
  }
500
- } else if (state.value === ReorderableListState.AUTO_SCROLL) {
501
- state.value = ReorderableListState.DRAGGING;
543
+ } else if (state.value === ReorderableListState.AUTOSCROLL) {
544
+ state.value = ReorderableListState.DRAGGED;
502
545
  }
503
546
  }
504
547
  },
@@ -509,7 +552,7 @@ export const useReorderableListCore = <T>({
509
552
  () => {
510
553
  if (
511
554
  autoscrollTrigger.value !== lastAutoscrollTrigger.value &&
512
- state.value === ReorderableListState.AUTO_SCROLL
555
+ state.value === ReorderableListState.AUTOSCROLL
513
556
  ) {
514
557
  let y = currentY.value + scrollViewDragScrollTranslationY.value;
515
558
  const autoscrollIncrement =
@@ -550,7 +593,7 @@ export const useReorderableListCore = <T>({
550
593
  flatListScrollOffsetY.value - dragInitialScrollOffsetY.value;
551
594
  }
552
595
 
553
- if (state.value === ReorderableListState.AUTO_SCROLL) {
596
+ if (state.value === ReorderableListState.AUTOSCROLL) {
554
597
  dragY.value =
555
598
  currentTranslationY.value +
556
599
  dragScrollTranslationY.value +
@@ -562,8 +605,6 @@ export const useReorderableListCore = <T>({
562
605
  withTiming(autoscrollTrigger.value * -1, {duration: 0}),
563
606
  );
564
607
  }
565
-
566
- onScroll?.(e);
567
608
  });
568
609
 
569
610
  // parent scroll handler
@@ -579,7 +620,7 @@ export const useReorderableListCore = <T>({
579
620
  value - scrollViewDragInitialScrollOffsetY.value;
580
621
  }
581
622
 
582
- if (state.value === ReorderableListState.AUTO_SCROLL) {
623
+ if (state.value === ReorderableListState.AUTOSCROLL) {
583
624
  dragY.value =
584
625
  currentTranslationY.value + scrollViewDragScrollTranslationY.value;
585
626
 
@@ -612,9 +653,13 @@ export const useReorderableListCore = <T>({
612
653
  draggedIndex.value = index;
613
654
  previousIndex.value = -1;
614
655
  currentIndex.value = index;
615
- state.value = ReorderableListState.DRAGGING;
656
+ state.value = ReorderableListState.DRAGGED;
616
657
 
617
658
  runOnJS(setScrollEnabled)(false);
659
+
660
+ // run animation before onDragStart to avoid potentially waiting for it
661
+ runDefaultDragAnimations('start');
662
+ onDragStart?.({index});
618
663
  }
619
664
  },
620
665
  [
@@ -630,6 +675,8 @@ export const useReorderableListCore = <T>({
630
675
  state,
631
676
  flatListScrollOffsetY,
632
677
  itemHeight,
678
+ onDragStart,
679
+ runDefaultDragAnimations,
633
680
  ],
634
681
  );
635
682
 
@@ -5,6 +5,7 @@ import {Gesture, GestureDetector} from 'react-native-gesture-handler';
5
5
  import Animated, {
6
6
  useAnimatedRef,
7
7
  useAnimatedScrollHandler,
8
+ useComposedEventHandler,
8
9
  useSharedValue,
9
10
  } from 'react-native-reanimated';
10
11
 
@@ -27,12 +28,15 @@ export const ScrollViewContainer: React.FC<ScrollViewContainerProps> = ({
27
28
  const handleScroll = useAnimatedScrollHandler(
28
29
  e => {
29
30
  scrollViewScrollOffsetY.value = e.contentOffset.y;
30
-
31
- onScroll?.(e);
32
31
  },
33
32
  [scrollViewScrollOffsetY],
34
33
  );
35
34
 
35
+ const composedScrollHandler = useComposedEventHandler([
36
+ handleScroll,
37
+ onScroll || null,
38
+ ]);
39
+
36
40
  const contextValue = useMemo(
37
41
  () => ({
38
42
  scrollViewContainerRef,
@@ -64,7 +68,7 @@ export const ScrollViewContainer: React.FC<ScrollViewContainerProps> = ({
64
68
  <Animated.ScrollView
65
69
  {...rest}
66
70
  ref={scrollViewContainerRef}
67
- onScroll={handleScroll}
71
+ onScroll={composedScrollHandler}
68
72
  onLayout={handleLayout}
69
73
  scrollEnabled={scrollEnabled}
70
74
  />
@@ -1,5 +1,4 @@
1
1
  export * from './ReorderableList';
2
2
  export * from './NestedReorderableList';
3
3
  export * from './ReorderableListCell';
4
- export * from './ReorderableListItem';
5
4
  export * from './ScrollViewContainer';
@@ -6,6 +6,8 @@ interface ReorderableListContextData {
6
6
  currentIndex: SharedValue<number>;
7
7
  draggedHeight: SharedValue<number>;
8
8
  dragEndHandlers: SharedValue<((from: number, to: number) => void)[][]>;
9
+ scale: SharedValue<number>;
10
+ opacity: SharedValue<number>;
9
11
  }
10
12
 
11
13
  export const ReorderableListContext = React.createContext<
package/src/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  NestedReorderableList,
3
3
  ReorderableList,
4
- ReorderableListItem,
5
4
  ScrollViewContainer,
6
5
  } from './components';
7
6
  import {
@@ -10,9 +9,9 @@ import {
10
9
  useReorderableDragStart,
11
10
  } from './hooks';
12
11
  import type {
12
+ ReorderableListCellAnimations,
13
13
  ReorderableListDragEndEvent,
14
- ReorderableListItemConfig,
15
- ReorderableListItemProps,
14
+ ReorderableListDragStartEvent,
16
15
  ReorderableListProps,
17
16
  ReorderableListReorderEvent,
18
17
  ScrollViewContainerProps,
@@ -25,10 +24,9 @@ export {
25
24
  useReorderableDragEnd,
26
25
  ReorderableListProps,
27
26
  ReorderableListReorderEvent,
27
+ ReorderableListCellAnimations,
28
+ ReorderableListDragStartEvent,
28
29
  ReorderableListDragEndEvent,
29
- ReorderableListItem,
30
- ReorderableListItemConfig,
31
- ReorderableListItemProps,
32
30
  ScrollViewContainer,
33
31
  ScrollViewContainerProps,
34
32
  NestedReorderableList,
package/src/types/misc.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export enum ReorderableListState {
2
2
  IDLE = 0,
3
- DRAGGING,
4
- RELEASING,
5
- AUTO_SCROLL,
3
+ DRAGGED,
4
+ RELEASED,
5
+ AUTOSCROLL,
6
6
  }
@@ -1,11 +1,6 @@
1
- import type {
2
- FlatListProps,
3
- NativeScrollEvent,
4
- ScrollViewProps,
5
- ViewProps,
6
- } from 'react-native';
1
+ import type {FlatListProps, ScrollViewProps} from 'react-native';
7
2
 
8
- import {EasingFunction} from 'react-native-reanimated';
3
+ import {SharedValue, useAnimatedScrollHandler} from 'react-native-reanimated';
9
4
 
10
5
  export interface ReorderableListReorderEvent {
11
6
  /**
@@ -18,6 +13,13 @@ export interface ReorderableListReorderEvent {
18
13
  to: number;
19
14
  }
20
15
 
16
+ export interface ReorderableListDragStartEvent {
17
+ /**
18
+ * Index of the dragged item.
19
+ */
20
+ index: number;
21
+ }
22
+
21
23
  export interface ReorderableListDragEndEvent {
22
24
  /**
23
25
  * Index of the dragged item.
@@ -69,63 +71,44 @@ export interface ReorderableListProps<T>
69
71
  */
70
72
  animationDuration?: number;
71
73
  /**
72
- * Event fired after an item is released and the list is reordered.
73
- */
74
- onReorder: (event: ReorderableListReorderEvent) => void;
75
- /**
76
- * Event fired at most once per frame during scrolling. Needs to be a `worklet`. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info.
74
+ * Allows passing an object with shared values that can animate a cell by using the `onDragStart` and `onDragEnd` events.
77
75
  */
78
- onScroll?: (event: NativeScrollEvent) => void;
76
+ cellAnimations?: ReorderableListCellAnimations;
79
77
  /**
80
- * 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.
81
- */
82
- onDragEnd?: (event: ReorderableListDragEndEvent) => void;
83
- }
84
-
85
- export interface ReorderableListItemConfig {
86
- /**
87
- * Value of the animated style on drag end.
88
- */
89
- enabled?: boolean;
90
- /**
91
- * Value of the animated style on drag end.
92
- */
93
- valueEnd?: number;
94
- /**
95
- * Value of the animated style on drag start.
78
+ * Event fired after an item is released and the list is reordered.
96
79
  */
97
- valueStart?: number;
80
+ onReorder: (event: ReorderableListReorderEvent) => void;
98
81
  /**
99
- * Easing function for the animation to the end value. Default: `Easing.in(Easing.ease)`.
82
+ * An animated scroll handler created with useAnimatedScrollHandler. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info.
100
83
  */
101
- easingEnd?: EasingFunction;
84
+ onScroll?: ReturnType<typeof useAnimatedScrollHandler>;
102
85
  /**
103
- * Easing function for the animation to the start value. Default: `Easing.out(Easing.ease)`.
86
+ * Event fired when an item is dragged. Needs to be a `worklet`. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info.
104
87
  */
105
- easingStart?: EasingFunction;
88
+ onDragStart?: (event: ReorderableListDragStartEvent) => void;
106
89
  /**
107
- * Duration of the animations in milliseconds. Default: `200`.
90
+ * 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.
108
91
  */
109
- duration?: number;
92
+ onDragEnd?: (event: ReorderableListDragEndEvent) => void;
110
93
  }
111
94
 
112
- export interface ReorderableListItemProps extends ViewProps {
95
+ export interface ReorderableListCellAnimations {
113
96
  /**
114
- * Config for the `opacity` animation. Enabled by default with custom default options.
97
+ * Shared value to animate the opacity of a dragged item. Set to false to disable default opacity animations.
115
98
  */
116
- opacityAnimationConfig?: ReorderableListItemConfig;
99
+ opacity?: SharedValue<number> | false;
117
100
  /**
118
- * Config for the `scale` animation. Enabled by default with custom default options.
101
+ * Shared value to animate the scale of a dragged item. Set to false to disable default scale animations.
119
102
  */
120
- scaleAnimationConfig?: ReorderableListItemConfig;
103
+ scale?: SharedValue<number> | false;
121
104
  }
122
105
 
123
106
  export interface ScrollViewContainerProps
124
107
  extends Omit<ScrollViewProps, 'onScroll'> {
125
108
  /**
126
- * Event fired at most once per frame during scrolling. Needs to be a `worklet`. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info.
109
+ * An animated scroll handler created with useAnimatedScrollHandler. See [Reanimated docs](https://docs.swmansion.com/react-native-reanimated) for further info.
127
110
  */
128
- onScroll?: (event: NativeScrollEvent) => void;
111
+ onScroll?: ReturnType<typeof useAnimatedScrollHandler>;
129
112
  }
130
113
 
131
114
  export interface NestedReorderableListProps<T> extends ReorderableListProps<T> {
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNative","require","IOS_CONFIG","delay","increment","ANDROID_FABRIC_CONFIG","ANDROID_PAPER_CONFIG","IS_FABRIC","exports","global","AUTOSCROLL_CONFIG","Platform","select","android","ios","web","macos","windows","native"],"sourceRoot":"../../../../src","sources":["components/ReorderableListCore/constants.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,UAAU,GAAG;EACjBC,KAAK,EAAE,EAAE;EACTC,SAAS,EAAE;AACb,CAAC;AAED,MAAMC,qBAAqB,GAAG;EAC5BF,KAAK,EAAE,EAAE;EACTC,SAAS,EAAE;AACb,CAAC;AAED,MAAME,oBAAoB,GAAG;EAC3BH,KAAK,EAAE,EAAE;EACTC,SAAS,EAAE;AACb,CAAC;AAEM,MAAMG,SAAS,GAAAC,OAAA,CAAAD,SAAA,GACpBE,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAI,uBAAuB,IAAIA,MAAM;AAEpE,MAAMC,iBAAiB,GAAAF,OAAA,CAAAE,iBAAA,GAAGC,qBAAQ,CAACC,MAAM,CAAC;EAC/C;EACAC,OAAO,EAAEN,SAAS,GAAGF,qBAAqB,GAAGC,oBAAoB;EACjEQ,GAAG,EAAEZ,UAAU;EAEf;EACAa,GAAG,EAAEb,UAAU;EACfc,KAAK,EAAEd,UAAU;EACjBe,OAAO,EAAEf,UAAU;EACnBgB,MAAM,EAAEhB;AACV,CAAC,CAAC","ignoreList":[]}
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ReorderableListItem = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
9
- var _hooks = require("../hooks");
10
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
13
- const scaleDefaultConfig = {
14
- enabled: true,
15
- valueEnd: 1,
16
- valueStart: 1.025,
17
- easingStart: _reactNativeReanimated.Easing.in(_reactNativeReanimated.Easing.ease),
18
- easingEnd: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.ease),
19
- duration: 200
20
- };
21
- const opacityDefaultConfig = {
22
- enabled: true,
23
- valueEnd: 1,
24
- valueStart: 0.75,
25
- easingStart: _reactNativeReanimated.Easing.in(_reactNativeReanimated.Easing.ease),
26
- easingEnd: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.ease),
27
- duration: 200
28
- };
29
- const ReorderableListItem = ({
30
- scaleAnimationConfig = scaleDefaultConfig,
31
- opacityAnimationConfig = opacityDefaultConfig,
32
- ...rest
33
- }) => {
34
- const scaleConfigWithDefaults = (0, _react.useMemo)(() => ({
35
- ...scaleDefaultConfig,
36
- ...scaleAnimationConfig
37
- }), [scaleAnimationConfig]);
38
- const opacityConfigWithDefaults = (0, _react.useMemo)(() => ({
39
- ...opacityDefaultConfig,
40
- ...opacityAnimationConfig
41
- }), [opacityAnimationConfig]);
42
- const scale = (0, _reactNativeReanimated.useSharedValue)(scaleConfigWithDefaults.enabled ? scaleConfigWithDefaults.valueEnd : 1);
43
- const opacity = (0, _reactNativeReanimated.useSharedValue)(opacityConfigWithDefaults.enabled ? opacityConfigWithDefaults.valueEnd : 1);
44
- (0, _hooks.useReorderableDragStart)((0, _react.useCallback)(() => {
45
- 'worklet';
46
-
47
- if (scaleConfigWithDefaults.enabled) {
48
- scale.value = (0, _reactNativeReanimated.withTiming)(scaleConfigWithDefaults.valueStart, {
49
- easing: scaleConfigWithDefaults.easingStart,
50
- duration: scaleConfigWithDefaults.duration
51
- });
52
- }
53
- if (opacityConfigWithDefaults.enabled) {
54
- opacity.value = (0, _reactNativeReanimated.withTiming)(opacityConfigWithDefaults.valueStart, {
55
- easing: opacityConfigWithDefaults.easingStart,
56
- duration: opacityConfigWithDefaults.duration
57
- });
58
- }
59
- }, [opacity, scale, opacityConfigWithDefaults, scaleConfigWithDefaults]));
60
- (0, _hooks.useReorderableDragEnd)((0, _react.useCallback)(() => {
61
- 'worklet';
62
-
63
- if (scaleConfigWithDefaults.enabled) {
64
- scale.value = (0, _reactNativeReanimated.withTiming)(scaleConfigWithDefaults.valueEnd, {
65
- easing: scaleConfigWithDefaults.easingEnd,
66
- duration: scaleConfigWithDefaults.duration
67
- });
68
- }
69
- if (opacityConfigWithDefaults.enabled) {
70
- opacity.value = (0, _reactNativeReanimated.withTiming)(opacityConfigWithDefaults.valueEnd, {
71
- easing: opacityConfigWithDefaults.easingEnd,
72
- duration: opacityConfigWithDefaults.duration
73
- });
74
- }
75
- }, [opacity, scale, opacityConfigWithDefaults, scaleConfigWithDefaults]));
76
- const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
77
- transform: [{
78
- scale: scale.value
79
- }],
80
- opacity: opacity.value
81
- }), [scale, opacity]);
82
- return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, _extends({}, rest, {
83
- style: [animatedStyle, rest.style]
84
- }));
85
- };
86
- exports.ReorderableListItem = ReorderableListItem;
87
- //# sourceMappingURL=ReorderableListItem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNativeReanimated","_hooks","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_extends","assign","bind","arguments","length","apply","scaleDefaultConfig","enabled","valueEnd","valueStart","easingStart","Easing","in","ease","easingEnd","out","duration","opacityDefaultConfig","ReorderableListItem","scaleAnimationConfig","opacityAnimationConfig","rest","scaleConfigWithDefaults","useMemo","opacityConfigWithDefaults","scale","useSharedValue","opacity","useReorderableDragStart","useCallback","value","withTiming","easing","useReorderableDragEnd","animatedStyle","useAnimatedStyle","transform","createElement","View","style","exports"],"sourceRoot":"../../../src","sources":["components/ReorderableListItem.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,sBAAA,GAAAF,uBAAA,CAAAC,OAAA;AAOA,IAAAE,MAAA,GAAAF,OAAA;AAAwE,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CA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OAAO,EAAE;MACnCkB,KAAK,CAACK,KAAK,GAAG,IAAAC,iCAAU,EAACT,uBAAuB,CAACd,QAAQ,EAAE;QACzDwB,MAAM,EAAEV,uBAAuB,CAACR,SAAS;QACzCE,QAAQ,EAAEM,uBAAuB,CAACN;MACpC,CAAC,CAAC;IACJ;IAEA,IAAIQ,yBAAyB,CAACjB,OAAO,EAAE;MACrCoB,OAAO,CAACG,KAAK,GAAG,IAAAC,iCAAU,EAACP,yBAAyB,CAAChB,QAAQ,EAAE;QAC7DwB,MAAM,EAAER,yBAAyB,CAACV,SAAS;QAC3CE,QAAQ,EAAEQ,yBAAyB,CAACR;MACtC,CAAC,CAAC;IACJ;EACF,CAAC,EAAE,CAACW,OAAO,EAAEF,KAAK,EAAED,yBAAyB,EAAEF,uBAAuB,CAAC,CACzE,CAAC;EAED,MAAMY,aAAa,GAAG,IAAAC,uCAAgB,EACpC,OAAO;IACLC,SAAS,EAAE,CACT;MACEX,KAAK,EAAEA,KAAK,CAACK;IACf,CAAC,CACF;IACDH,OAAO,EAAEA,OAAO,CAACG;EACnB,CAAC,CAAC,EACF,CAACL,KAAK,EAAEE,OAAO,CACjB,CAAC;EAED,oBAAOpD,MAAA,CAAAW,OAAA,CAAAmD,aAAA,CAAC3D,sBAAA,CAAAQ,OAAQ,CAACoD,IAAI,EAAAtC,QAAA,KAAKqB,IAAI;IAAEkB,KAAK,EAAE,CAACL,aAAa,EAAEb,IAAI,CAACkB,KAAK;EAAE,EAAE,CAAC;AACxE,CAAC;AAACC,OAAA,CAAAtB,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["Platform","IOS_CONFIG","delay","increment","ANDROID_FABRIC_CONFIG","ANDROID_PAPER_CONFIG","IS_FABRIC","global","AUTOSCROLL_CONFIG","select","android","ios","web","macos","windows","native"],"sourceRoot":"../../../../src","sources":["components/ReorderableListCore/constants.ts"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,cAAc;AAErC,MAAMC,UAAU,GAAG;EACjBC,KAAK,EAAE,EAAE;EACTC,SAAS,EAAE;AACb,CAAC;AAED,MAAMC,qBAAqB,GAAG;EAC5BF,KAAK,EAAE,EAAE;EACTC,SAAS,EAAE;AACb,CAAC;AAED,MAAME,oBAAoB,GAAG;EAC3BH,KAAK,EAAE,EAAE;EACTC,SAAS,EAAE;AACb,CAAC;AAED,OAAO,MAAMG,SAAS,GACpBC,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAI,uBAAuB,IAAIA,MAAM;AAE3E,OAAO,MAAMC,iBAAiB,GAAGR,QAAQ,CAACS,MAAM,CAAC;EAC/C;EACAC,OAAO,EAAEJ,SAAS,GAAGF,qBAAqB,GAAGC,oBAAoB;EACjEM,GAAG,EAAEV,UAAU;EAEf;EACAW,GAAG,EAAEX,UAAU;EACfY,KAAK,EAAEZ,UAAU;EACjBa,OAAO,EAAEb,UAAU;EACnBc,MAAM,EAAEd;AACV,CAAC,CAAC","ignoreList":[]}