react-native-fast-animate 0.1.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.
package/src/index.tsx ADDED
@@ -0,0 +1,125 @@
1
+ import React, { useEffect, useRef, useMemo, memo } from 'react';
2
+ import { Animated } from 'react-native';
3
+ import { getAnimationConfig, getAnimationStyle } from './animations';
4
+ import type {
5
+ AnimateViewProps,
6
+ AnimateTextProps,
7
+ AnimateImageProps,
8
+ BaseAnimateProps,
9
+ } from './types';
10
+
11
+ /**
12
+ * Shared hook for animation logic
13
+ */
14
+ const useFastAnimate = (props: BaseAnimateProps) => {
15
+ const {
16
+ type = 'fadeIn',
17
+ duration = 500,
18
+ delay = 0,
19
+ infinite = false,
20
+ autoStart = true,
21
+ useNativeDriver = true,
22
+ damping = 10,
23
+ stiffness = 100,
24
+ } = props;
25
+
26
+ const animatedValue = useRef(new Animated.Value(0)).current;
27
+
28
+ const animatedStyle = useMemo(() => {
29
+ return getAnimationStyle(type, animatedValue);
30
+ }, [type, animatedValue]);
31
+
32
+ useEffect(() => {
33
+ let timeoutId: any;
34
+
35
+ if (autoStart) {
36
+ const run = () => {
37
+ animatedValue.setValue(0);
38
+ const animation = getAnimationConfig(
39
+ type,
40
+ animatedValue,
41
+ duration,
42
+ useNativeDriver,
43
+ damping,
44
+ stiffness
45
+ );
46
+
47
+ if (infinite) {
48
+ Animated.loop(animation).start();
49
+ } else {
50
+ animation.start();
51
+ }
52
+ };
53
+
54
+ if (delay > 0) {
55
+ timeoutId = setTimeout(run, delay);
56
+ } else {
57
+ run();
58
+ }
59
+ }
60
+
61
+ return () => {
62
+ if (timeoutId) clearTimeout(timeoutId);
63
+ animatedValue.stopAnimation();
64
+ };
65
+ }, [
66
+ type,
67
+ infinite,
68
+ autoStart,
69
+ delay,
70
+ duration,
71
+ useNativeDriver,
72
+ damping,
73
+ stiffness,
74
+ animatedValue,
75
+ ]);
76
+
77
+ return animatedStyle;
78
+ };
79
+
80
+ /**
81
+ * AnimateView Component
82
+ */
83
+ export const AnimateView: React.FC<AnimateViewProps> = memo((props) => {
84
+ const animatedStyle = useFastAnimate(props);
85
+ const { style, children, ...rest } = props;
86
+ return (
87
+ <Animated.View style={[style, animatedStyle]} {...rest}>
88
+ {children}
89
+ </Animated.View>
90
+ );
91
+ });
92
+
93
+ /**
94
+ * AnimateText Component
95
+ */
96
+ export const AnimateText: React.FC<AnimateTextProps> = memo((props) => {
97
+ const animatedStyle = useFastAnimate(props);
98
+ const { style, children, ...rest } = props;
99
+ return (
100
+ <Animated.Text style={[style, animatedStyle]} {...rest}>
101
+ {children}
102
+ </Animated.Text>
103
+ );
104
+ });
105
+
106
+ /**
107
+ * AnimateImage Component
108
+ */
109
+ export const AnimateImage: React.FC<AnimateImageProps> = memo((props) => {
110
+ const animatedStyle = useFastAnimate(props);
111
+ const { style, ...rest } = props;
112
+ // @ts-ignore - Animated.Image has complex style types
113
+ return <Animated.Image style={[style, animatedStyle]} {...rest} />;
114
+ });
115
+
116
+ // Default export and namespace support
117
+ const FastAnimate = Object.assign(AnimateView, {
118
+ View: AnimateView,
119
+ Text: AnimateText,
120
+ Image: AnimateImage,
121
+ });
122
+
123
+ export default FastAnimate;
124
+ export * from './types';
125
+ export * from './animations';
package/src/types.ts ADDED
@@ -0,0 +1,327 @@
1
+ import type { ViewProps, TextProps, ImageProps } from 'react-native';
2
+
3
+ export type AnimationType =
4
+ | 'fadeIn'
5
+ | 'fadeInUp'
6
+ | 'fadeInDown'
7
+ | 'fadeInLeft'
8
+ | 'fadeInRight'
9
+ | 'fadeInTopLeft'
10
+ | 'fadeInTopRight'
11
+ | 'fadeInBottomLeft'
12
+ | 'fadeInBottomRight'
13
+ | 'fadeOut'
14
+ | 'fadeOutUp'
15
+ | 'fadeOutDown'
16
+ | 'fadeOutLeft'
17
+ | 'fadeOutRight'
18
+ | 'fadeOutTopLeft'
19
+ | 'fadeOutTopRight'
20
+ | 'fadeOutBottomLeft'
21
+ | 'fadeOutBottomRight'
22
+ | 'slideInUp'
23
+ | 'slideInDown'
24
+ | 'slideInLeft'
25
+ | 'slideInRight'
26
+ | 'slideInTopLeft'
27
+ | 'slideInTopRight'
28
+ | 'slideInBottomLeft'
29
+ | 'slideInBottomRight'
30
+ | 'slideOutUp'
31
+ | 'slideOutDown'
32
+ | 'slideOutLeft'
33
+ | 'slideOutRight'
34
+ | 'slideOutTopLeft'
35
+ | 'slideOutTopRight'
36
+ | 'slideOutBottomLeft'
37
+ | 'slideOutBottomRight'
38
+ | 'zoomIn'
39
+ | 'zoomInUp'
40
+ | 'zoomInDown'
41
+ | 'zoomInLeft'
42
+ | 'zoomInRight'
43
+ | 'zoomInTopLeft'
44
+ | 'zoomInTopRight'
45
+ | 'zoomInBottomLeft'
46
+ | 'zoomInBottomRight'
47
+ | 'zoomOut'
48
+ | 'zoomOutUp'
49
+ | 'zoomOutDown'
50
+ | 'zoomOutLeft'
51
+ | 'zoomOutRight'
52
+ | 'zoomOutTopLeft'
53
+ | 'zoomOutTopRight'
54
+ | 'zoomOutBottomLeft'
55
+ | 'zoomOutBottomRight'
56
+ | 'backInUp'
57
+ | 'backInDown'
58
+ | 'backInLeft'
59
+ | 'backInRight'
60
+ | 'backOutUp'
61
+ | 'backOutDown'
62
+ | 'backOutLeft'
63
+ | 'backOutRight'
64
+ | 'bounce'
65
+ | 'bounceIn'
66
+ | 'bounceInUp'
67
+ | 'bounceInDown'
68
+ | 'bounceInLeft'
69
+ | 'bounceInRight'
70
+ | 'bounceOut'
71
+ | 'bounceOutUp'
72
+ | 'bounceOutDown'
73
+ | 'bounceOutLeft'
74
+ | 'bounceOutRight'
75
+ | 'pulse'
76
+ | 'pulseAlt'
77
+ | 'shake'
78
+ | 'shakeX'
79
+ | 'shakeY'
80
+ | 'headShake'
81
+ | 'swing'
82
+ | 'tada'
83
+ | 'wobble'
84
+ | 'jello'
85
+ | 'heartBeat'
86
+ | 'flash'
87
+ | 'rubberBand'
88
+ | 'flip'
89
+ | 'flipInX'
90
+ | 'flipInY'
91
+ | 'flipOutX'
92
+ | 'flipOutY'
93
+ | 'rotateIn'
94
+ | 'rotateInDownLeft'
95
+ | 'rotateInDownRight'
96
+ | 'rotateInUpLeft'
97
+ | 'rotateInUpRight'
98
+ | 'rotateOut'
99
+ | 'rotateOutDownLeft'
100
+ | 'rotateOutDownRight'
101
+ | 'rotateOutUpLeft'
102
+ | 'rotateOutUpRight'
103
+ | 'lightSpeedInRight'
104
+ | 'lightSpeedInLeft'
105
+ | 'lightSpeedOutRight'
106
+ | 'lightSpeedOutLeft'
107
+ | 'rollIn'
108
+ | 'rollOut'
109
+ | 'jackInTheBox'
110
+ | 'hinge'
111
+ | 'spiralIn'
112
+ | 'spiralOut'
113
+ | 'focusIn'
114
+ | 'focusOut'
115
+ | 'focusInLeft'
116
+ | 'focusInRight'
117
+ | 'focusInUp'
118
+ | 'focusInDown'
119
+ | 'cornerInTopLeft'
120
+ | 'cornerInTopRight'
121
+ | 'cornerInBottomLeft'
122
+ | 'cornerInBottomRight'
123
+ | 'cornerOutTopLeft'
124
+ | 'cornerOutTopRight'
125
+ | 'cornerOutBottomLeft'
126
+ | 'cornerOutBottomRight'
127
+ | 'perspectiveFlipX'
128
+ | 'perspectiveFlipY'
129
+ | 'doorOpenLeft'
130
+ | 'doorOpenRight'
131
+ | 'doorCloseLeft'
132
+ | 'doorCloseRight'
133
+ | 'stretch'
134
+ | 'stretchX'
135
+ | 'stretchY'
136
+ | 'skewIn'
137
+ | 'skewOut'
138
+ | 'skewInUp'
139
+ | 'skewInDown'
140
+ | 'perspectiveRotate'
141
+ | 'wave'
142
+ | 'bounceManual'
143
+ | 'blink'
144
+ | 'expandUp'
145
+ | 'expandDown'
146
+ | 'expandLeft'
147
+ | 'expandRight'
148
+ | 'squeezeX'
149
+ | 'squeezeY'
150
+ | 'wiggle'
151
+ | 'shiver'
152
+ | 'shutterIn'
153
+ | 'shutterOut'
154
+ | 'contractIn'
155
+ | 'contractOut'
156
+ | 'puffIn'
157
+ | 'puffOut'
158
+ | 'flingInLeft'
159
+ | 'flingInRight'
160
+ | 'flingInUp'
161
+ | 'flingInDown'
162
+ | 'float'
163
+ | 'beat'
164
+ | 'bounceInTopLeft'
165
+ | 'bounceInTopRight'
166
+ | 'bounceInBottomLeft'
167
+ | 'bounceInBottomRight'
168
+ | 'zoomInRotateLeft'
169
+ | 'zoomInRotateRight'
170
+ | 'swingRotate'
171
+ | 'perspectiveSlideInLeft'
172
+ | 'perspectiveSlideInRight'
173
+ | 'tiltLeft'
174
+ | 'tiltRight'
175
+ | 'squash'
176
+ | 'vibrate'
177
+ | 'sway'
178
+ | 'floatLeft'
179
+ | 'floatRight'
180
+ | 'newspaper'
181
+ | 'popIn'
182
+ | 'popOut'
183
+ | 'popInUp'
184
+ | 'popInDown'
185
+ | 'popInLeft'
186
+ | 'popInRight'
187
+ | 'popOutUp'
188
+ | 'popOutDown'
189
+ | 'popOutLeft'
190
+ | 'popOutRight'
191
+ | 'skateInLeft'
192
+ | 'skateInRight'
193
+ | 'skateOutLeft'
194
+ | 'skateOutRight'
195
+ | 'drip'
196
+ | 'dropIn'
197
+ | 'dropOut'
198
+ | 'hangIn'
199
+ | 'hangOut'
200
+ | 'revealUp'
201
+ | 'revealDown'
202
+ | 'revealLeft'
203
+ | 'revealRight'
204
+ | 'vibrateFast'
205
+ | 'vibrateSlow'
206
+ | 'jitter'
207
+ | 'glitch'
208
+ | 'glitchSlow'
209
+ | 'pulseFast'
210
+ | 'pulseSlow'
211
+ | 'heartBeatFast'
212
+ | 'heartBeatSlow'
213
+ | 'shimmer'
214
+ | 'shimmerSlow'
215
+ | 'blinkFast'
216
+ | 'blinkSlow'
217
+ | 'bounceInfinite'
218
+ | 'rotateInfinite'
219
+ | 'slideInfinite'
220
+ | 'flipInfinite'
221
+ | 'flipInfiniteX'
222
+ | 'flipInfiniteY'
223
+ | 'swingInfinite'
224
+ | 'wobbleInfinite'
225
+ | 'pulseInfinite'
226
+ | 'jelloInfinite'
227
+ | 'tiltInTop'
228
+ | 'tiltInBottom'
229
+ | 'tiltInLeft'
230
+ | 'tiltInRight'
231
+ | 'tiltOutTop'
232
+ | 'tiltOutBottom'
233
+ | 'tiltOutLeft'
234
+ | 'tiltOutRight'
235
+ | 'scaleIn'
236
+ | 'scaleOut'
237
+ | 'scaleInX'
238
+ | 'scaleInY'
239
+ | 'scaleOutX'
240
+ | 'scaleOutY'
241
+ | 'spinIn'
242
+ | 'spinOut'
243
+ | 'spinClockwise'
244
+ | 'spinCounterClockwise'
245
+ | 'zoomInRotate'
246
+ | 'zoomOutRotate'
247
+ | 'fallIn'
248
+ | 'fallOut'
249
+ | 'raiseIn'
250
+ | 'raiseOut'
251
+ | 'bounceTop'
252
+ | 'bounceBottom'
253
+ | 'bounceLeft'
254
+ | 'bounceRight'
255
+ | 'dance'
256
+ | 'jerk'
257
+ | 'panic'
258
+ | 'calm'
259
+ | 'ghost'
260
+ | 'smoke'
261
+ | 'expandUpAlt'
262
+ | 'expandDownAlt'
263
+ | 'expandLeftAlt'
264
+ | 'expandRightAlt'
265
+ | 'contractUp'
266
+ | 'contractDown'
267
+ | 'contractLeft'
268
+ | 'contractRight'
269
+ | 'floatUp'
270
+ | 'floatDown'
271
+ | 'driftLeft'
272
+ | 'driftRight'
273
+ | 'orbit'
274
+ | 'satellite'
275
+ | 'ufo'
276
+ | 'alien'
277
+ | 'asteroid'
278
+ | 'flashFast'
279
+ | 'flashSlow'
280
+ | 'rubberBandFast'
281
+ | 'rubberBandSlow'
282
+ | 'jelloFast'
283
+ | 'jelloSlow'
284
+ | 'tadaFast'
285
+ | 'tadaSlow'
286
+ | 'perspectiveSlideInUp'
287
+ | 'perspectiveSlideInDown'
288
+ | 'perspectiveSlideOutLeft'
289
+ | 'perspectiveSlideOutRight'
290
+ | 'foldIn'
291
+ | 'foldOut'
292
+ | 'unfoldIn'
293
+ | 'unfoldOut'
294
+ | 'rollInLeft'
295
+ | 'rollInRight'
296
+ | 'rollOutLeft'
297
+ | 'rollOutRight'
298
+ | 'bounceInRotate'
299
+ | 'bounceOutRotate'
300
+ | 'skewInTop'
301
+ | 'skewInBottom'
302
+ | 'skewOutTop'
303
+ | 'skewOutBottom';
304
+
305
+ export interface BaseAnimateProps {
306
+ type?: AnimationType;
307
+ duration?: number;
308
+ delay?: number;
309
+ infinite?: boolean;
310
+ autoStart?: boolean;
311
+ useNativeDriver?: boolean;
312
+ damping?: number;
313
+ stiffness?: number;
314
+ }
315
+
316
+ export interface AnimateViewProps extends ViewProps, BaseAnimateProps {
317
+ children?: React.ReactNode;
318
+ }
319
+
320
+ export interface AnimateTextProps extends TextProps, BaseAnimateProps {
321
+ children?: React.ReactNode;
322
+ }
323
+
324
+ export interface AnimateImageProps extends ImageProps, BaseAnimateProps {}
325
+
326
+ // Keep this for backward compatibility if needed
327
+ export interface FastAnimateProps extends AnimateViewProps {}