@hua-labs/motion-core 2.3.0 → 2.4.1
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/LICENSE +21 -0
- package/README.md +128 -39
- package/dist/chunk-47QAGQLN.mjs +1057 -0
- package/dist/chunk-47QAGQLN.mjs.map +1 -0
- package/dist/chunk-LSIP7MB5.cjs +1090 -0
- package/dist/chunk-LSIP7MB5.cjs.map +1 -0
- package/dist/index.cjs +7591 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +637 -685
- package/dist/index.d.ts +1579 -0
- package/dist/index.mjs +2788 -1175
- package/dist/index.mjs.map +1 -1
- package/dist/native.cjs +692 -0
- package/dist/native.cjs.map +1 -0
- package/dist/native.d.mts +177 -0
- package/dist/native.d.ts +177 -0
- package/dist/native.mjs +555 -0
- package/dist/native.mjs.map +1 -0
- package/dist/springPhysics-BZVRi9PQ.d.mts +740 -0
- package/dist/springPhysics-BZVRi9PQ.d.ts +740 -0
- package/package.json +29 -9
package/dist/native.cjs
ADDED
|
@@ -0,0 +1,692 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLSIP7MB5_cjs = require('./chunk-LSIP7MB5.cjs');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var reactNative = require('react-native');
|
|
6
|
+
|
|
7
|
+
function useFadeIn(options = {}) {
|
|
8
|
+
const profile = chunkLSIP7MB5_cjs.useMotionProfile();
|
|
9
|
+
const {
|
|
10
|
+
duration = profile.base.duration,
|
|
11
|
+
delay = 0,
|
|
12
|
+
easing = chunkLSIP7MB5_cjs.getEasing(profile.base.easing) || chunkLSIP7MB5_cjs.easeOut,
|
|
13
|
+
autoStart = true,
|
|
14
|
+
useNativeDriver = true,
|
|
15
|
+
initialOpacity = profile.entrance.fade.initialOpacity,
|
|
16
|
+
targetOpacity = 1,
|
|
17
|
+
onComplete,
|
|
18
|
+
onStart
|
|
19
|
+
} = options;
|
|
20
|
+
const opacity = react.useRef(new reactNative.Animated.Value(initialOpacity)).current;
|
|
21
|
+
const [isAnimating, setIsAnimating] = react.useState(false);
|
|
22
|
+
const [isVisible, setIsVisible] = react.useState(false);
|
|
23
|
+
const [progress, setProgress] = react.useState(0);
|
|
24
|
+
const animRef = react.useRef(null);
|
|
25
|
+
const start = react.useCallback(() => {
|
|
26
|
+
if (isAnimating) return;
|
|
27
|
+
setIsAnimating(true);
|
|
28
|
+
onStart?.();
|
|
29
|
+
animRef.current = reactNative.Animated.timing(opacity, {
|
|
30
|
+
toValue: targetOpacity,
|
|
31
|
+
duration,
|
|
32
|
+
delay,
|
|
33
|
+
easing,
|
|
34
|
+
useNativeDriver
|
|
35
|
+
});
|
|
36
|
+
animRef.current.start(({ finished }) => {
|
|
37
|
+
if (finished) {
|
|
38
|
+
setIsVisible(true);
|
|
39
|
+
setIsAnimating(false);
|
|
40
|
+
setProgress(1);
|
|
41
|
+
onComplete?.();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}, [opacity, duration, delay, easing, useNativeDriver, targetOpacity, isAnimating, onStart, onComplete]);
|
|
45
|
+
const stop = react.useCallback(() => {
|
|
46
|
+
animRef.current?.stop();
|
|
47
|
+
setIsAnimating(false);
|
|
48
|
+
}, []);
|
|
49
|
+
const reset = react.useCallback(() => {
|
|
50
|
+
animRef.current?.stop();
|
|
51
|
+
opacity.setValue(initialOpacity);
|
|
52
|
+
setIsAnimating(false);
|
|
53
|
+
setIsVisible(false);
|
|
54
|
+
setProgress(0);
|
|
55
|
+
}, [opacity, initialOpacity]);
|
|
56
|
+
react.useEffect(() => {
|
|
57
|
+
if (autoStart) start();
|
|
58
|
+
}, []);
|
|
59
|
+
react.useEffect(() => {
|
|
60
|
+
return () => {
|
|
61
|
+
animRef.current?.stop();
|
|
62
|
+
};
|
|
63
|
+
}, []);
|
|
64
|
+
return {
|
|
65
|
+
style: { opacity },
|
|
66
|
+
isVisible,
|
|
67
|
+
isAnimating,
|
|
68
|
+
progress,
|
|
69
|
+
start,
|
|
70
|
+
stop,
|
|
71
|
+
reset
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function useSlideBase(direction, options = {}) {
|
|
75
|
+
const profile = chunkLSIP7MB5_cjs.useMotionProfile();
|
|
76
|
+
const {
|
|
77
|
+
duration = profile.base.duration,
|
|
78
|
+
delay = 0,
|
|
79
|
+
easing = chunkLSIP7MB5_cjs.getEasing(profile.entrance.slide.easing) || chunkLSIP7MB5_cjs.easeOut,
|
|
80
|
+
distance = profile.entrance.slide.distance,
|
|
81
|
+
autoStart = true,
|
|
82
|
+
useNativeDriver = true,
|
|
83
|
+
onComplete,
|
|
84
|
+
onStart
|
|
85
|
+
} = options;
|
|
86
|
+
const isVertical = direction === "up" || direction === "down";
|
|
87
|
+
const sign = direction === "up" || direction === "left" ? 1 : -1;
|
|
88
|
+
const initialValue = sign * distance;
|
|
89
|
+
const translate = react.useRef(new reactNative.Animated.Value(initialValue)).current;
|
|
90
|
+
const opacity = react.useRef(new reactNative.Animated.Value(0)).current;
|
|
91
|
+
const [isAnimating, setIsAnimating] = react.useState(false);
|
|
92
|
+
const [isVisible, setIsVisible] = react.useState(false);
|
|
93
|
+
const [progress, setProgress] = react.useState(0);
|
|
94
|
+
const animRef = react.useRef(null);
|
|
95
|
+
const start = react.useCallback(() => {
|
|
96
|
+
if (isAnimating) return;
|
|
97
|
+
setIsAnimating(true);
|
|
98
|
+
onStart?.();
|
|
99
|
+
animRef.current = reactNative.Animated.parallel([
|
|
100
|
+
reactNative.Animated.timing(translate, {
|
|
101
|
+
toValue: 0,
|
|
102
|
+
duration,
|
|
103
|
+
delay,
|
|
104
|
+
easing,
|
|
105
|
+
useNativeDriver
|
|
106
|
+
}),
|
|
107
|
+
reactNative.Animated.timing(opacity, {
|
|
108
|
+
toValue: 1,
|
|
109
|
+
duration,
|
|
110
|
+
delay,
|
|
111
|
+
easing,
|
|
112
|
+
useNativeDriver
|
|
113
|
+
})
|
|
114
|
+
]);
|
|
115
|
+
animRef.current.start(({ finished }) => {
|
|
116
|
+
if (finished) {
|
|
117
|
+
setIsVisible(true);
|
|
118
|
+
setIsAnimating(false);
|
|
119
|
+
setProgress(1);
|
|
120
|
+
onComplete?.();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}, [translate, opacity, duration, delay, easing, useNativeDriver, isAnimating, onStart, onComplete]);
|
|
124
|
+
const stop = react.useCallback(() => {
|
|
125
|
+
animRef.current?.stop();
|
|
126
|
+
setIsAnimating(false);
|
|
127
|
+
}, []);
|
|
128
|
+
const reset = react.useCallback(() => {
|
|
129
|
+
animRef.current?.stop();
|
|
130
|
+
translate.setValue(initialValue);
|
|
131
|
+
opacity.setValue(0);
|
|
132
|
+
setIsAnimating(false);
|
|
133
|
+
setIsVisible(false);
|
|
134
|
+
setProgress(0);
|
|
135
|
+
}, [translate, opacity, initialValue]);
|
|
136
|
+
react.useEffect(() => {
|
|
137
|
+
if (autoStart) start();
|
|
138
|
+
}, []);
|
|
139
|
+
react.useEffect(() => {
|
|
140
|
+
return () => {
|
|
141
|
+
animRef.current?.stop();
|
|
142
|
+
};
|
|
143
|
+
}, []);
|
|
144
|
+
const style = isVertical ? { opacity, transform: [{ translateY: translate }] } : { opacity, transform: [{ translateX: translate }] };
|
|
145
|
+
return {
|
|
146
|
+
style,
|
|
147
|
+
isVisible,
|
|
148
|
+
isAnimating,
|
|
149
|
+
progress,
|
|
150
|
+
start,
|
|
151
|
+
stop,
|
|
152
|
+
reset
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function useSlideUp(options = {}) {
|
|
156
|
+
return useSlideBase("up", options);
|
|
157
|
+
}
|
|
158
|
+
function useSlideDown(options = {}) {
|
|
159
|
+
return useSlideBase("down", options);
|
|
160
|
+
}
|
|
161
|
+
function useSlideLeft(options = {}) {
|
|
162
|
+
return useSlideBase("left", options);
|
|
163
|
+
}
|
|
164
|
+
function useSlideRight(options = {}) {
|
|
165
|
+
return useSlideBase("right", options);
|
|
166
|
+
}
|
|
167
|
+
function useScaleIn(options = {}) {
|
|
168
|
+
const profile = chunkLSIP7MB5_cjs.useMotionProfile();
|
|
169
|
+
const {
|
|
170
|
+
duration = profile.base.duration,
|
|
171
|
+
delay = 0,
|
|
172
|
+
easing = chunkLSIP7MB5_cjs.getEasing(profile.base.easing) || chunkLSIP7MB5_cjs.easeOut,
|
|
173
|
+
autoStart = true,
|
|
174
|
+
useNativeDriver = true,
|
|
175
|
+
initialScale = profile.entrance.scale.from,
|
|
176
|
+
targetScale = 1,
|
|
177
|
+
onComplete,
|
|
178
|
+
onStart
|
|
179
|
+
} = options;
|
|
180
|
+
const scale = react.useRef(new reactNative.Animated.Value(initialScale)).current;
|
|
181
|
+
const opacity = react.useRef(new reactNative.Animated.Value(0)).current;
|
|
182
|
+
const [isAnimating, setIsAnimating] = react.useState(false);
|
|
183
|
+
const [isVisible, setIsVisible] = react.useState(false);
|
|
184
|
+
const [progress, setProgress] = react.useState(0);
|
|
185
|
+
const animRef = react.useRef(null);
|
|
186
|
+
const start = react.useCallback(() => {
|
|
187
|
+
if (isAnimating) return;
|
|
188
|
+
setIsAnimating(true);
|
|
189
|
+
onStart?.();
|
|
190
|
+
animRef.current = reactNative.Animated.parallel([
|
|
191
|
+
reactNative.Animated.timing(scale, {
|
|
192
|
+
toValue: targetScale,
|
|
193
|
+
duration,
|
|
194
|
+
delay,
|
|
195
|
+
easing,
|
|
196
|
+
useNativeDriver
|
|
197
|
+
}),
|
|
198
|
+
reactNative.Animated.timing(opacity, {
|
|
199
|
+
toValue: 1,
|
|
200
|
+
duration,
|
|
201
|
+
delay,
|
|
202
|
+
easing,
|
|
203
|
+
useNativeDriver
|
|
204
|
+
})
|
|
205
|
+
]);
|
|
206
|
+
animRef.current.start(({ finished }) => {
|
|
207
|
+
if (finished) {
|
|
208
|
+
setIsVisible(true);
|
|
209
|
+
setIsAnimating(false);
|
|
210
|
+
setProgress(1);
|
|
211
|
+
onComplete?.();
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}, [scale, opacity, duration, delay, easing, useNativeDriver, targetScale, isAnimating, onStart, onComplete]);
|
|
215
|
+
const stop = react.useCallback(() => {
|
|
216
|
+
animRef.current?.stop();
|
|
217
|
+
setIsAnimating(false);
|
|
218
|
+
}, []);
|
|
219
|
+
const reset = react.useCallback(() => {
|
|
220
|
+
animRef.current?.stop();
|
|
221
|
+
scale.setValue(initialScale);
|
|
222
|
+
opacity.setValue(0);
|
|
223
|
+
setIsAnimating(false);
|
|
224
|
+
setIsVisible(false);
|
|
225
|
+
setProgress(0);
|
|
226
|
+
}, [scale, opacity, initialScale]);
|
|
227
|
+
react.useEffect(() => {
|
|
228
|
+
if (autoStart) start();
|
|
229
|
+
}, []);
|
|
230
|
+
react.useEffect(() => {
|
|
231
|
+
return () => {
|
|
232
|
+
animRef.current?.stop();
|
|
233
|
+
};
|
|
234
|
+
}, []);
|
|
235
|
+
return {
|
|
236
|
+
style: {
|
|
237
|
+
opacity,
|
|
238
|
+
transform: [{ scale }]
|
|
239
|
+
},
|
|
240
|
+
isVisible,
|
|
241
|
+
isAnimating,
|
|
242
|
+
progress,
|
|
243
|
+
start,
|
|
244
|
+
stop,
|
|
245
|
+
reset
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function useBounceIn(options = {}) {
|
|
249
|
+
chunkLSIP7MB5_cjs.useMotionProfile();
|
|
250
|
+
const {
|
|
251
|
+
delay = 0,
|
|
252
|
+
autoStart = true,
|
|
253
|
+
useNativeDriver = true,
|
|
254
|
+
initialScale = 0.3,
|
|
255
|
+
friction = 4,
|
|
256
|
+
tension = 80,
|
|
257
|
+
onComplete,
|
|
258
|
+
onStart
|
|
259
|
+
} = options;
|
|
260
|
+
const scale = react.useRef(new reactNative.Animated.Value(initialScale)).current;
|
|
261
|
+
const opacity = react.useRef(new reactNative.Animated.Value(0)).current;
|
|
262
|
+
const [isAnimating, setIsAnimating] = react.useState(false);
|
|
263
|
+
const [isVisible, setIsVisible] = react.useState(false);
|
|
264
|
+
const [progress, setProgress] = react.useState(0);
|
|
265
|
+
const animRef = react.useRef(null);
|
|
266
|
+
const start = react.useCallback(() => {
|
|
267
|
+
if (isAnimating) return;
|
|
268
|
+
setIsAnimating(true);
|
|
269
|
+
onStart?.();
|
|
270
|
+
animRef.current = reactNative.Animated.parallel([
|
|
271
|
+
reactNative.Animated.spring(scale, {
|
|
272
|
+
toValue: 1,
|
|
273
|
+
friction,
|
|
274
|
+
tension,
|
|
275
|
+
useNativeDriver,
|
|
276
|
+
delay
|
|
277
|
+
}),
|
|
278
|
+
reactNative.Animated.timing(opacity, {
|
|
279
|
+
toValue: 1,
|
|
280
|
+
duration: 200,
|
|
281
|
+
delay,
|
|
282
|
+
useNativeDriver
|
|
283
|
+
})
|
|
284
|
+
]);
|
|
285
|
+
animRef.current.start(({ finished }) => {
|
|
286
|
+
if (finished) {
|
|
287
|
+
setIsVisible(true);
|
|
288
|
+
setIsAnimating(false);
|
|
289
|
+
setProgress(1);
|
|
290
|
+
onComplete?.();
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}, [scale, opacity, friction, tension, delay, useNativeDriver, isAnimating, onStart, onComplete]);
|
|
294
|
+
const stop = react.useCallback(() => {
|
|
295
|
+
animRef.current?.stop();
|
|
296
|
+
setIsAnimating(false);
|
|
297
|
+
}, []);
|
|
298
|
+
const reset = react.useCallback(() => {
|
|
299
|
+
animRef.current?.stop();
|
|
300
|
+
scale.setValue(initialScale);
|
|
301
|
+
opacity.setValue(0);
|
|
302
|
+
setIsAnimating(false);
|
|
303
|
+
setIsVisible(false);
|
|
304
|
+
setProgress(0);
|
|
305
|
+
}, [scale, opacity, initialScale]);
|
|
306
|
+
react.useEffect(() => {
|
|
307
|
+
if (autoStart) start();
|
|
308
|
+
}, []);
|
|
309
|
+
react.useEffect(() => {
|
|
310
|
+
return () => {
|
|
311
|
+
animRef.current?.stop();
|
|
312
|
+
};
|
|
313
|
+
}, []);
|
|
314
|
+
return {
|
|
315
|
+
style: {
|
|
316
|
+
opacity,
|
|
317
|
+
transform: [{ scale }]
|
|
318
|
+
},
|
|
319
|
+
isVisible,
|
|
320
|
+
isAnimating,
|
|
321
|
+
progress,
|
|
322
|
+
start,
|
|
323
|
+
stop,
|
|
324
|
+
reset
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function useSpringMotion(options) {
|
|
328
|
+
const profile = chunkLSIP7MB5_cjs.useMotionProfile();
|
|
329
|
+
const {
|
|
330
|
+
from,
|
|
331
|
+
to,
|
|
332
|
+
friction = Math.sqrt(4 * profile.spring.mass * profile.spring.stiffness) / (2 * profile.spring.damping) * 10 || 26,
|
|
333
|
+
tension = profile.spring.stiffness / 2 || 170,
|
|
334
|
+
autoStart = true,
|
|
335
|
+
useNativeDriver = true,
|
|
336
|
+
enabled = true,
|
|
337
|
+
onComplete,
|
|
338
|
+
onStart
|
|
339
|
+
} = options;
|
|
340
|
+
const value = react.useRef(new reactNative.Animated.Value(from)).current;
|
|
341
|
+
const [isAnimating, setIsAnimating] = react.useState(false);
|
|
342
|
+
const animRef = react.useRef(null);
|
|
343
|
+
const animateTo = react.useCallback((toValue) => {
|
|
344
|
+
if (!enabled) return;
|
|
345
|
+
setIsAnimating(true);
|
|
346
|
+
onStart?.();
|
|
347
|
+
animRef.current?.stop();
|
|
348
|
+
animRef.current = reactNative.Animated.spring(value, {
|
|
349
|
+
toValue,
|
|
350
|
+
friction,
|
|
351
|
+
tension,
|
|
352
|
+
useNativeDriver
|
|
353
|
+
});
|
|
354
|
+
animRef.current.start(({ finished }) => {
|
|
355
|
+
if (finished) {
|
|
356
|
+
setIsAnimating(false);
|
|
357
|
+
onComplete?.();
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}, [value, friction, tension, useNativeDriver, enabled, onStart, onComplete]);
|
|
361
|
+
const start = react.useCallback(() => {
|
|
362
|
+
animateTo(to);
|
|
363
|
+
}, [animateTo, to]);
|
|
364
|
+
const stop = react.useCallback(() => {
|
|
365
|
+
animRef.current?.stop();
|
|
366
|
+
setIsAnimating(false);
|
|
367
|
+
}, []);
|
|
368
|
+
const reset = react.useCallback(() => {
|
|
369
|
+
animRef.current?.stop();
|
|
370
|
+
value.setValue(from);
|
|
371
|
+
setIsAnimating(false);
|
|
372
|
+
}, [value, from]);
|
|
373
|
+
react.useEffect(() => {
|
|
374
|
+
if (autoStart && enabled) start();
|
|
375
|
+
}, []);
|
|
376
|
+
react.useEffect(() => {
|
|
377
|
+
return () => {
|
|
378
|
+
animRef.current?.stop();
|
|
379
|
+
};
|
|
380
|
+
}, []);
|
|
381
|
+
return { value, isAnimating, start, stop, reset, animateTo };
|
|
382
|
+
}
|
|
383
|
+
function usePulse(options = {}) {
|
|
384
|
+
const {
|
|
385
|
+
duration = 1500,
|
|
386
|
+
autoStart = true,
|
|
387
|
+
useNativeDriver = true,
|
|
388
|
+
easing = chunkLSIP7MB5_cjs.getEasing("easeInOut") || chunkLSIP7MB5_cjs.easeInOut,
|
|
389
|
+
minOpacity = 0.3,
|
|
390
|
+
iterations = -1,
|
|
391
|
+
onStart
|
|
392
|
+
} = options;
|
|
393
|
+
const opacity = react.useRef(new reactNative.Animated.Value(1)).current;
|
|
394
|
+
const [isAnimating, setIsAnimating] = react.useState(false);
|
|
395
|
+
const animRef = react.useRef(null);
|
|
396
|
+
const start = react.useCallback(() => {
|
|
397
|
+
if (isAnimating) return;
|
|
398
|
+
setIsAnimating(true);
|
|
399
|
+
onStart?.();
|
|
400
|
+
const pulse = reactNative.Animated.sequence([
|
|
401
|
+
reactNative.Animated.timing(opacity, {
|
|
402
|
+
toValue: minOpacity,
|
|
403
|
+
duration: duration / 2,
|
|
404
|
+
easing,
|
|
405
|
+
useNativeDriver
|
|
406
|
+
}),
|
|
407
|
+
reactNative.Animated.timing(opacity, {
|
|
408
|
+
toValue: 1,
|
|
409
|
+
duration: duration / 2,
|
|
410
|
+
easing,
|
|
411
|
+
useNativeDriver
|
|
412
|
+
})
|
|
413
|
+
]);
|
|
414
|
+
animRef.current = iterations === -1 || iterations === Infinity ? reactNative.Animated.loop(pulse) : reactNative.Animated.loop(pulse, { iterations });
|
|
415
|
+
animRef.current.start(({ finished }) => {
|
|
416
|
+
if (finished) setIsAnimating(false);
|
|
417
|
+
});
|
|
418
|
+
}, [opacity, duration, easing, useNativeDriver, minOpacity, iterations, isAnimating, onStart]);
|
|
419
|
+
const stop = react.useCallback(() => {
|
|
420
|
+
animRef.current?.stop();
|
|
421
|
+
setIsAnimating(false);
|
|
422
|
+
}, []);
|
|
423
|
+
const reset = react.useCallback(() => {
|
|
424
|
+
animRef.current?.stop();
|
|
425
|
+
opacity.setValue(1);
|
|
426
|
+
setIsAnimating(false);
|
|
427
|
+
}, [opacity]);
|
|
428
|
+
react.useEffect(() => {
|
|
429
|
+
if (autoStart) start();
|
|
430
|
+
}, []);
|
|
431
|
+
react.useEffect(() => {
|
|
432
|
+
return () => {
|
|
433
|
+
animRef.current?.stop();
|
|
434
|
+
};
|
|
435
|
+
}, []);
|
|
436
|
+
return {
|
|
437
|
+
style: { opacity },
|
|
438
|
+
isVisible: true,
|
|
439
|
+
isAnimating,
|
|
440
|
+
progress: 0,
|
|
441
|
+
start,
|
|
442
|
+
stop,
|
|
443
|
+
reset
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function useStagger(options) {
|
|
447
|
+
const profile = chunkLSIP7MB5_cjs.useMotionProfile();
|
|
448
|
+
const {
|
|
449
|
+
count,
|
|
450
|
+
staggerDelay = profile.stagger.perItem,
|
|
451
|
+
duration = profile.base.duration,
|
|
452
|
+
easing = chunkLSIP7MB5_cjs.getEasing(profile.base.easing) || chunkLSIP7MB5_cjs.easeOut,
|
|
453
|
+
autoStart = true,
|
|
454
|
+
useNativeDriver = true,
|
|
455
|
+
motionType = "fadeIn",
|
|
456
|
+
distance = profile.entrance.slide.distance,
|
|
457
|
+
onComplete,
|
|
458
|
+
onStart
|
|
459
|
+
} = options;
|
|
460
|
+
const [isVisible, setIsVisible] = react.useState(false);
|
|
461
|
+
const animRef = react.useRef(null);
|
|
462
|
+
const animatedValues = react.useRef(
|
|
463
|
+
Array.from({ length: count }, () => ({
|
|
464
|
+
opacity: new reactNative.Animated.Value(0),
|
|
465
|
+
translateY: new reactNative.Animated.Value(distance),
|
|
466
|
+
scale: new reactNative.Animated.Value(0.8)
|
|
467
|
+
}))
|
|
468
|
+
).current;
|
|
469
|
+
react.useEffect(() => {
|
|
470
|
+
while (animatedValues.length < count) {
|
|
471
|
+
animatedValues.push({
|
|
472
|
+
opacity: new reactNative.Animated.Value(0),
|
|
473
|
+
translateY: new reactNative.Animated.Value(distance),
|
|
474
|
+
scale: new reactNative.Animated.Value(0.8)
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}, [count, animatedValues, distance]);
|
|
478
|
+
const start = react.useCallback(() => {
|
|
479
|
+
setIsVisible(false);
|
|
480
|
+
onStart?.();
|
|
481
|
+
const animations = animatedValues.slice(0, count).map((v) => {
|
|
482
|
+
const itemAnims = [
|
|
483
|
+
reactNative.Animated.timing(v.opacity, {
|
|
484
|
+
toValue: 1,
|
|
485
|
+
duration,
|
|
486
|
+
easing,
|
|
487
|
+
useNativeDriver
|
|
488
|
+
})
|
|
489
|
+
];
|
|
490
|
+
if (motionType === "slideUp") {
|
|
491
|
+
itemAnims.push(
|
|
492
|
+
reactNative.Animated.timing(v.translateY, {
|
|
493
|
+
toValue: 0,
|
|
494
|
+
duration,
|
|
495
|
+
easing,
|
|
496
|
+
useNativeDriver
|
|
497
|
+
})
|
|
498
|
+
);
|
|
499
|
+
} else if (motionType === "scaleIn") {
|
|
500
|
+
itemAnims.push(
|
|
501
|
+
reactNative.Animated.timing(v.scale, {
|
|
502
|
+
toValue: 1,
|
|
503
|
+
duration,
|
|
504
|
+
easing,
|
|
505
|
+
useNativeDriver
|
|
506
|
+
})
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
return reactNative.Animated.parallel(itemAnims);
|
|
510
|
+
});
|
|
511
|
+
animRef.current = reactNative.Animated.stagger(staggerDelay, animations);
|
|
512
|
+
animRef.current.start(({ finished }) => {
|
|
513
|
+
if (finished) {
|
|
514
|
+
setIsVisible(true);
|
|
515
|
+
onComplete?.();
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
}, [animatedValues, count, staggerDelay, duration, easing, useNativeDriver, motionType, onStart, onComplete]);
|
|
519
|
+
const stop = react.useCallback(() => {
|
|
520
|
+
animRef.current?.stop();
|
|
521
|
+
}, []);
|
|
522
|
+
const reset = react.useCallback(() => {
|
|
523
|
+
animRef.current?.stop();
|
|
524
|
+
animatedValues.forEach((v) => {
|
|
525
|
+
v.opacity.setValue(0);
|
|
526
|
+
v.translateY.setValue(distance);
|
|
527
|
+
v.scale.setValue(0.8);
|
|
528
|
+
});
|
|
529
|
+
setIsVisible(false);
|
|
530
|
+
}, [animatedValues, distance]);
|
|
531
|
+
react.useEffect(() => {
|
|
532
|
+
if (autoStart) start();
|
|
533
|
+
}, []);
|
|
534
|
+
react.useEffect(() => {
|
|
535
|
+
return () => {
|
|
536
|
+
animRef.current?.stop();
|
|
537
|
+
};
|
|
538
|
+
}, []);
|
|
539
|
+
const items = react.useMemo(() => {
|
|
540
|
+
return animatedValues.slice(0, count).map((v) => {
|
|
541
|
+
if (motionType === "slideUp") {
|
|
542
|
+
return { style: { opacity: v.opacity, transform: [{ translateY: v.translateY }] } };
|
|
543
|
+
}
|
|
544
|
+
if (motionType === "scaleIn") {
|
|
545
|
+
return { style: { opacity: v.opacity, transform: [{ scale: v.scale }] } };
|
|
546
|
+
}
|
|
547
|
+
return { style: { opacity: v.opacity } };
|
|
548
|
+
});
|
|
549
|
+
}, [animatedValues, count, motionType]);
|
|
550
|
+
return { items, isVisible, start, stop, reset };
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
Object.defineProperty(exports, "MOTION_PRESETS", {
|
|
554
|
+
enumerable: true,
|
|
555
|
+
get: function () { return chunkLSIP7MB5_cjs.MOTION_PRESETS; }
|
|
556
|
+
});
|
|
557
|
+
Object.defineProperty(exports, "MotionEngine", {
|
|
558
|
+
enumerable: true,
|
|
559
|
+
get: function () { return chunkLSIP7MB5_cjs.MotionEngine; }
|
|
560
|
+
});
|
|
561
|
+
Object.defineProperty(exports, "MotionProfileProvider", {
|
|
562
|
+
enumerable: true,
|
|
563
|
+
get: function () { return chunkLSIP7MB5_cjs.MotionProfileProvider; }
|
|
564
|
+
});
|
|
565
|
+
Object.defineProperty(exports, "MotionStateManager", {
|
|
566
|
+
enumerable: true,
|
|
567
|
+
get: function () { return chunkLSIP7MB5_cjs.MotionStateManager; }
|
|
568
|
+
});
|
|
569
|
+
Object.defineProperty(exports, "PAGE_MOTIONS", {
|
|
570
|
+
enumerable: true,
|
|
571
|
+
get: function () { return chunkLSIP7MB5_cjs.PAGE_MOTIONS; }
|
|
572
|
+
});
|
|
573
|
+
Object.defineProperty(exports, "TransitionEffects", {
|
|
574
|
+
enumerable: true,
|
|
575
|
+
get: function () { return chunkLSIP7MB5_cjs.TransitionEffects; }
|
|
576
|
+
});
|
|
577
|
+
Object.defineProperty(exports, "applyEasing", {
|
|
578
|
+
enumerable: true,
|
|
579
|
+
get: function () { return chunkLSIP7MB5_cjs.applyEasing; }
|
|
580
|
+
});
|
|
581
|
+
Object.defineProperty(exports, "calculateSpring", {
|
|
582
|
+
enumerable: true,
|
|
583
|
+
get: function () { return chunkLSIP7MB5_cjs.calculateSpring; }
|
|
584
|
+
});
|
|
585
|
+
Object.defineProperty(exports, "easeIn", {
|
|
586
|
+
enumerable: true,
|
|
587
|
+
get: function () { return chunkLSIP7MB5_cjs.easeIn; }
|
|
588
|
+
});
|
|
589
|
+
Object.defineProperty(exports, "easeInOut", {
|
|
590
|
+
enumerable: true,
|
|
591
|
+
get: function () { return chunkLSIP7MB5_cjs.easeInOut; }
|
|
592
|
+
});
|
|
593
|
+
Object.defineProperty(exports, "easeInOutQuad", {
|
|
594
|
+
enumerable: true,
|
|
595
|
+
get: function () { return chunkLSIP7MB5_cjs.easeInOutQuad; }
|
|
596
|
+
});
|
|
597
|
+
Object.defineProperty(exports, "easeInQuad", {
|
|
598
|
+
enumerable: true,
|
|
599
|
+
get: function () { return chunkLSIP7MB5_cjs.easeInQuad; }
|
|
600
|
+
});
|
|
601
|
+
Object.defineProperty(exports, "easeOut", {
|
|
602
|
+
enumerable: true,
|
|
603
|
+
get: function () { return chunkLSIP7MB5_cjs.easeOut; }
|
|
604
|
+
});
|
|
605
|
+
Object.defineProperty(exports, "easeOutQuad", {
|
|
606
|
+
enumerable: true,
|
|
607
|
+
get: function () { return chunkLSIP7MB5_cjs.easeOutQuad; }
|
|
608
|
+
});
|
|
609
|
+
Object.defineProperty(exports, "easingPresets", {
|
|
610
|
+
enumerable: true,
|
|
611
|
+
get: function () { return chunkLSIP7MB5_cjs.easingPresets; }
|
|
612
|
+
});
|
|
613
|
+
Object.defineProperty(exports, "getAvailableEasings", {
|
|
614
|
+
enumerable: true,
|
|
615
|
+
get: function () { return chunkLSIP7MB5_cjs.getAvailableEasings; }
|
|
616
|
+
});
|
|
617
|
+
Object.defineProperty(exports, "getEasing", {
|
|
618
|
+
enumerable: true,
|
|
619
|
+
get: function () { return chunkLSIP7MB5_cjs.getEasing; }
|
|
620
|
+
});
|
|
621
|
+
Object.defineProperty(exports, "getMotionPreset", {
|
|
622
|
+
enumerable: true,
|
|
623
|
+
get: function () { return chunkLSIP7MB5_cjs.getMotionPreset; }
|
|
624
|
+
});
|
|
625
|
+
Object.defineProperty(exports, "getPagePreset", {
|
|
626
|
+
enumerable: true,
|
|
627
|
+
get: function () { return chunkLSIP7MB5_cjs.getPagePreset; }
|
|
628
|
+
});
|
|
629
|
+
Object.defineProperty(exports, "getPresetEasing", {
|
|
630
|
+
enumerable: true,
|
|
631
|
+
get: function () { return chunkLSIP7MB5_cjs.getPresetEasing; }
|
|
632
|
+
});
|
|
633
|
+
Object.defineProperty(exports, "hua", {
|
|
634
|
+
enumerable: true,
|
|
635
|
+
get: function () { return chunkLSIP7MB5_cjs.hua; }
|
|
636
|
+
});
|
|
637
|
+
Object.defineProperty(exports, "isEasingFunction", {
|
|
638
|
+
enumerable: true,
|
|
639
|
+
get: function () { return chunkLSIP7MB5_cjs.isEasingFunction; }
|
|
640
|
+
});
|
|
641
|
+
Object.defineProperty(exports, "isValidEasing", {
|
|
642
|
+
enumerable: true,
|
|
643
|
+
get: function () { return chunkLSIP7MB5_cjs.isValidEasing; }
|
|
644
|
+
});
|
|
645
|
+
Object.defineProperty(exports, "linear", {
|
|
646
|
+
enumerable: true,
|
|
647
|
+
get: function () { return chunkLSIP7MB5_cjs.linear; }
|
|
648
|
+
});
|
|
649
|
+
Object.defineProperty(exports, "mergeProfileOverrides", {
|
|
650
|
+
enumerable: true,
|
|
651
|
+
get: function () { return chunkLSIP7MB5_cjs.mergeProfileOverrides; }
|
|
652
|
+
});
|
|
653
|
+
Object.defineProperty(exports, "mergeWithPreset", {
|
|
654
|
+
enumerable: true,
|
|
655
|
+
get: function () { return chunkLSIP7MB5_cjs.mergeWithPreset; }
|
|
656
|
+
});
|
|
657
|
+
Object.defineProperty(exports, "motionEngine", {
|
|
658
|
+
enumerable: true,
|
|
659
|
+
get: function () { return chunkLSIP7MB5_cjs.motionEngine; }
|
|
660
|
+
});
|
|
661
|
+
Object.defineProperty(exports, "neutral", {
|
|
662
|
+
enumerable: true,
|
|
663
|
+
get: function () { return chunkLSIP7MB5_cjs.neutral; }
|
|
664
|
+
});
|
|
665
|
+
Object.defineProperty(exports, "resolveProfile", {
|
|
666
|
+
enumerable: true,
|
|
667
|
+
get: function () { return chunkLSIP7MB5_cjs.resolveProfile; }
|
|
668
|
+
});
|
|
669
|
+
Object.defineProperty(exports, "safeApplyEasing", {
|
|
670
|
+
enumerable: true,
|
|
671
|
+
get: function () { return chunkLSIP7MB5_cjs.safeApplyEasing; }
|
|
672
|
+
});
|
|
673
|
+
Object.defineProperty(exports, "transitionEffects", {
|
|
674
|
+
enumerable: true,
|
|
675
|
+
get: function () { return chunkLSIP7MB5_cjs.transitionEffects; }
|
|
676
|
+
});
|
|
677
|
+
Object.defineProperty(exports, "useMotionProfile", {
|
|
678
|
+
enumerable: true,
|
|
679
|
+
get: function () { return chunkLSIP7MB5_cjs.useMotionProfile; }
|
|
680
|
+
});
|
|
681
|
+
exports.useBounceIn = useBounceIn;
|
|
682
|
+
exports.useFadeIn = useFadeIn;
|
|
683
|
+
exports.usePulse = usePulse;
|
|
684
|
+
exports.useScaleIn = useScaleIn;
|
|
685
|
+
exports.useSlideDown = useSlideDown;
|
|
686
|
+
exports.useSlideLeft = useSlideLeft;
|
|
687
|
+
exports.useSlideRight = useSlideRight;
|
|
688
|
+
exports.useSlideUp = useSlideUp;
|
|
689
|
+
exports.useSpringMotion = useSpringMotion;
|
|
690
|
+
exports.useStagger = useStagger;
|
|
691
|
+
//# sourceMappingURL=native.cjs.map
|
|
692
|
+
//# sourceMappingURL=native.cjs.map
|