@souscheflabs/reanimated-flashlist 0.1.7
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.
- package/README.md +282 -0
- package/lib/AnimatedFlashList.d.ts +6 -0
- package/lib/AnimatedFlashList.d.ts.map +1 -0
- package/lib/AnimatedFlashList.js +207 -0
- package/lib/AnimatedFlashListItem.d.ts +33 -0
- package/lib/AnimatedFlashListItem.d.ts.map +1 -0
- package/lib/AnimatedFlashListItem.js +155 -0
- package/lib/__tests__/utils/test-utils.d.ts +82 -0
- package/lib/__tests__/utils/test-utils.d.ts.map +1 -0
- package/lib/__tests__/utils/test-utils.js +115 -0
- package/lib/constants/animations.d.ts +39 -0
- package/lib/constants/animations.d.ts.map +1 -0
- package/lib/constants/animations.js +100 -0
- package/lib/constants/drag.d.ts +11 -0
- package/lib/constants/drag.d.ts.map +1 -0
- package/lib/constants/drag.js +47 -0
- package/lib/constants/index.d.ts +3 -0
- package/lib/constants/index.d.ts.map +1 -0
- package/lib/constants/index.js +18 -0
- package/lib/contexts/DragStateContext.d.ts +73 -0
- package/lib/contexts/DragStateContext.d.ts.map +1 -0
- package/lib/contexts/DragStateContext.js +148 -0
- package/lib/contexts/ListAnimationContext.d.ts +104 -0
- package/lib/contexts/ListAnimationContext.d.ts.map +1 -0
- package/lib/contexts/ListAnimationContext.js +184 -0
- package/lib/contexts/index.d.ts +5 -0
- package/lib/contexts/index.d.ts.map +1 -0
- package/lib/contexts/index.js +10 -0
- package/lib/hooks/animations/index.d.ts +9 -0
- package/lib/hooks/animations/index.d.ts.map +1 -0
- package/lib/hooks/animations/index.js +13 -0
- package/lib/hooks/animations/useListEntryAnimation.d.ts +38 -0
- package/lib/hooks/animations/useListEntryAnimation.d.ts.map +1 -0
- package/lib/hooks/animations/useListEntryAnimation.js +90 -0
- package/lib/hooks/animations/useListExitAnimation.d.ts +67 -0
- package/lib/hooks/animations/useListExitAnimation.d.ts.map +1 -0
- package/lib/hooks/animations/useListExitAnimation.js +146 -0
- package/lib/hooks/drag/index.d.ts +20 -0
- package/lib/hooks/drag/index.d.ts.map +1 -0
- package/lib/hooks/drag/index.js +26 -0
- package/lib/hooks/drag/useDragAnimatedStyle.d.ts +33 -0
- package/lib/hooks/drag/useDragAnimatedStyle.d.ts.map +1 -0
- package/lib/hooks/drag/useDragAnimatedStyle.js +61 -0
- package/lib/hooks/drag/useDragGesture.d.ts +30 -0
- package/lib/hooks/drag/useDragGesture.d.ts.map +1 -0
- package/lib/hooks/drag/useDragGesture.js +189 -0
- package/lib/hooks/drag/useDragShift.d.ts +21 -0
- package/lib/hooks/drag/useDragShift.d.ts.map +1 -0
- package/lib/hooks/drag/useDragShift.js +85 -0
- package/lib/hooks/drag/useDropCompensation.d.ts +27 -0
- package/lib/hooks/drag/useDropCompensation.d.ts.map +1 -0
- package/lib/hooks/drag/useDropCompensation.js +90 -0
- package/lib/hooks/index.d.ts +8 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/index.js +18 -0
- package/lib/index.d.ts +42 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +69 -0
- package/lib/types/animations.d.ts +71 -0
- package/lib/types/animations.d.ts.map +1 -0
- package/lib/types/animations.js +2 -0
- package/lib/types/drag.d.ts +94 -0
- package/lib/types/drag.d.ts.map +1 -0
- package/lib/types/drag.js +2 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +19 -0
- package/lib/types/list.d.ts +136 -0
- package/lib/types/list.d.ts.map +1 -0
- package/lib/types/list.js +2 -0
- package/package.json +73 -0
- package/src/AnimatedFlashList.tsx +411 -0
- package/src/AnimatedFlashListItem.tsx +212 -0
- package/src/__tests__/components/AnimatedFlashList.test.tsx +365 -0
- package/src/__tests__/components/AnimatedFlashListItem.test.tsx +371 -0
- package/src/__tests__/contexts/DragStateContext.test.tsx +169 -0
- package/src/__tests__/contexts/ListAnimationContext.test.tsx +324 -0
- package/src/__tests__/hooks/useDragAnimatedStyle.test.tsx +118 -0
- package/src/__tests__/hooks/useDragGesture.test.tsx +169 -0
- package/src/__tests__/hooks/useDragShift.test.tsx +94 -0
- package/src/__tests__/hooks/useDropCompensation.test.tsx +182 -0
- package/src/__tests__/hooks/useListEntryAnimation.test.tsx +135 -0
- package/src/__tests__/hooks/useListExitAnimation.test.tsx +175 -0
- package/src/__tests__/utils/test-utils.tsx +159 -0
- package/src/constants/animations.ts +107 -0
- package/src/constants/drag.ts +51 -0
- package/src/constants/index.ts +2 -0
- package/src/contexts/DragStateContext.tsx +197 -0
- package/src/contexts/ListAnimationContext.tsx +302 -0
- package/src/contexts/index.ts +9 -0
- package/src/hooks/animations/index.ts +9 -0
- package/src/hooks/animations/useListEntryAnimation.ts +108 -0
- package/src/hooks/animations/useListExitAnimation.ts +197 -0
- package/src/hooks/drag/index.ts +20 -0
- package/src/hooks/drag/useDragAnimatedStyle.ts +80 -0
- package/src/hooks/drag/useDragGesture.ts +267 -0
- package/src/hooks/drag/useDragShift.ts +119 -0
- package/src/hooks/drag/useDropCompensation.ts +120 -0
- package/src/hooks/index.ts +16 -0
- package/src/index.ts +105 -0
- package/src/types/animations.ts +76 -0
- package/src/types/drag.ts +101 -0
- package/src/types/index.ts +3 -0
- package/src/types/list.ts +178 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { ReactElement, ComponentType, JSXElementConstructor } from 'react';
|
|
2
|
+
import type { ViewStyle } from 'react-native';
|
|
3
|
+
import type { FlashListProps } from '@shopify/flash-list';
|
|
4
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
5
|
+
import type { GestureType } from 'react-native-gesture-handler';
|
|
6
|
+
import type { DragConfig } from './drag';
|
|
7
|
+
import type {
|
|
8
|
+
AnimationDirection,
|
|
9
|
+
ExitAnimationPreset,
|
|
10
|
+
ExitAnimationConfig,
|
|
11
|
+
EntryAnimationConfig,
|
|
12
|
+
HapticFeedbackType,
|
|
13
|
+
} from './animations';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Base item interface - consumers extend this
|
|
17
|
+
*/
|
|
18
|
+
export interface AnimatedListItem {
|
|
19
|
+
id: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Props passed to drag handle wrapper
|
|
24
|
+
*/
|
|
25
|
+
export interface DragHandleProps {
|
|
26
|
+
/** The pan gesture to attach */
|
|
27
|
+
gesture: GestureType;
|
|
28
|
+
/** Whether dragging is currently active */
|
|
29
|
+
isDragging: SharedValue<boolean>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Render item info passed to renderItem callback
|
|
34
|
+
*/
|
|
35
|
+
export interface AnimatedRenderItemInfo<T extends AnimatedListItem> {
|
|
36
|
+
/** The item data */
|
|
37
|
+
item: T;
|
|
38
|
+
/** Current index in list */
|
|
39
|
+
index: number;
|
|
40
|
+
/** Total number of items */
|
|
41
|
+
totalItems: number;
|
|
42
|
+
/** Combined animated style (drag + entry/exit) - apply to outer Animated.View */
|
|
43
|
+
animatedStyle: ViewStyle;
|
|
44
|
+
/** Drag handle props - spread onto GestureDetector wrapping your drag handle */
|
|
45
|
+
dragHandleProps: DragHandleProps | null;
|
|
46
|
+
/** Whether this item is currently being dragged */
|
|
47
|
+
isDragging: boolean;
|
|
48
|
+
/** Whether drag is enabled for this item */
|
|
49
|
+
isDragEnabled: boolean;
|
|
50
|
+
/** Trigger exit animation programmatically */
|
|
51
|
+
triggerExitAnimation: (
|
|
52
|
+
direction: AnimationDirection,
|
|
53
|
+
onComplete: () => void,
|
|
54
|
+
preset?: ExitAnimationPreset,
|
|
55
|
+
) => void;
|
|
56
|
+
/** Reset exit animation state */
|
|
57
|
+
resetExitAnimation: () => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Configuration for the AnimatedFlashList
|
|
62
|
+
*/
|
|
63
|
+
export interface AnimatedFlashListConfig {
|
|
64
|
+
/** Drag behavior configuration */
|
|
65
|
+
drag?: Partial<DragConfig>;
|
|
66
|
+
/** Exit animation configuration */
|
|
67
|
+
exitAnimation?: Partial<ExitAnimationConfig>;
|
|
68
|
+
/** Entry animation configuration */
|
|
69
|
+
entryAnimation?: Partial<EntryAnimationConfig>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Props for AnimatedFlashList component
|
|
74
|
+
*/
|
|
75
|
+
export interface AnimatedFlashListProps<T extends AnimatedListItem>
|
|
76
|
+
extends Omit<
|
|
77
|
+
FlashListProps<T>,
|
|
78
|
+
'data' | 'renderItem' | 'keyExtractor' | 'ref'
|
|
79
|
+
> {
|
|
80
|
+
/** List data */
|
|
81
|
+
data: T[];
|
|
82
|
+
|
|
83
|
+
/** Key extractor function */
|
|
84
|
+
keyExtractor: (item: T, index: number) => string;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Render function for each item
|
|
88
|
+
* Receives item data and animation utilities
|
|
89
|
+
*/
|
|
90
|
+
renderItem: (info: AnimatedRenderItemInfo<T>) => ReactElement;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Whether drag-to-reorder is enabled
|
|
94
|
+
* @default false
|
|
95
|
+
*/
|
|
96
|
+
dragEnabled?: boolean;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Callback when an item is reordered
|
|
100
|
+
* @param itemId - ID of the moved item
|
|
101
|
+
* @param fromIndex - Original index
|
|
102
|
+
* @param toIndex - New index
|
|
103
|
+
*/
|
|
104
|
+
onReorder?: (itemId: string, fromIndex: number, toIndex: number) => void;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Callback with neighbor-based reorder info (for fractional indexing)
|
|
108
|
+
* @param itemId - ID of the moved item
|
|
109
|
+
* @param afterItemId - ID of item that should come before (null if moving to start)
|
|
110
|
+
* @param beforeItemId - ID of item that should come after (null if moving to end)
|
|
111
|
+
*/
|
|
112
|
+
onReorderByNeighbors?: (
|
|
113
|
+
itemId: string,
|
|
114
|
+
afterItemId: string | null,
|
|
115
|
+
beforeItemId: string | null,
|
|
116
|
+
) => void;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Function to determine if an item can be dragged
|
|
120
|
+
* @default () => true when dragEnabled is true
|
|
121
|
+
*/
|
|
122
|
+
canDrag?: (item: T, index: number) => boolean;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Optional haptic feedback callback
|
|
126
|
+
* Called during drag operations
|
|
127
|
+
*/
|
|
128
|
+
onHapticFeedback?: (type: HapticFeedbackType) => void;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Configuration overrides
|
|
132
|
+
*/
|
|
133
|
+
config?: AnimatedFlashListConfig;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Called when FlashList needs to prepare for layout animation
|
|
137
|
+
* (before items are added/removed)
|
|
138
|
+
*/
|
|
139
|
+
onPrepareLayoutAnimation?: () => void;
|
|
140
|
+
|
|
141
|
+
/** Footer component */
|
|
142
|
+
ListFooterComponent?:
|
|
143
|
+
| ReactElement<unknown, string | JSXElementConstructor<unknown>>
|
|
144
|
+
| ComponentType<unknown>
|
|
145
|
+
| null;
|
|
146
|
+
|
|
147
|
+
/** Refresh callback */
|
|
148
|
+
onRefresh?: () => void | Promise<void>;
|
|
149
|
+
|
|
150
|
+
/** Whether currently refreshing */
|
|
151
|
+
refreshing?: boolean;
|
|
152
|
+
|
|
153
|
+
/** Pagination callback */
|
|
154
|
+
onEndReached?: () => void;
|
|
155
|
+
|
|
156
|
+
/** Pagination threshold */
|
|
157
|
+
onEndReachedThreshold?: number;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Ref handle for AnimatedFlashList
|
|
162
|
+
*/
|
|
163
|
+
export interface AnimatedFlashListRef {
|
|
164
|
+
/**
|
|
165
|
+
* Prepare FlashList for layout animation before items are removed/added
|
|
166
|
+
*/
|
|
167
|
+
prepareForLayoutAnimation: () => void;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Scroll to a specific offset
|
|
171
|
+
*/
|
|
172
|
+
scrollToOffset: (offset: number, animated?: boolean) => void;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Scroll to a specific index
|
|
176
|
+
*/
|
|
177
|
+
scrollToIndex: (index: number, animated?: boolean) => void;
|
|
178
|
+
}
|