11import { EasingFunction , Easing , Animated , Platform } from 'react-native'
22
3- export function createKeyframeEasingFunction (
3+ function createKeyframeEasingFunction (
44 keyframes : number [ ] ,
55 easing : EasingFunction
66) {
@@ -22,36 +22,32 @@ export function createKeyframeEasingFunction(
2222 }
2323}
2424
25- export interface AnimationConfig {
25+ interface AnimationConfig {
2626 duration : number
2727 value : Animated . Value
2828 keyframes ?: number [ ]
2929 toValue ?: number
3030 easing ?: EasingFunction
31- infinite ?: boolean
32- delay ?: number
3331}
3432
35- export function anim ( {
33+ function loop ( {
3634 duration,
3735 value,
3836 keyframes = [ 0 , 100 ] ,
3937 easing = Easing . bezier ( 0.42 , 0.0 , 0.58 , 1.0 ) ,
4038 toValue = 100 ,
41- infinite = true ,
42- delay = 0 ,
4339} : AnimationConfig ) {
4440 const timing = Animated . timing ( value , {
4541 duration : duration ,
4642 easing : createKeyframeEasingFunction ( keyframes , easing ) ,
4743 toValue : toValue ,
4844 useNativeDriver : Platform . OS !== 'web' ,
49- delay : delay ,
5045 } )
51- return infinite ? Animated . loop ( timing ) : timing
46+
47+ return Animated . loop ( timing )
5248}
5349
54- export function stagger (
50+ function stagger (
5551 time : number ,
5652 amount : number ,
5753 animationConfig : AnimationConfig
@@ -62,8 +58,6 @@ export function stagger(
6258 keyframes = [ 0 , 100 ] ,
6359 easing = Easing . bezier ( 0.42 , 0.0 , 0.58 , 1.0 ) ,
6460 toValue = 100 ,
65- infinite = true ,
66- delay = 0 ,
6761 } = animationConfig
6862 const easingFunction = createKeyframeEasingFunction ( keyframes , easing )
6963
@@ -73,13 +67,12 @@ export function stagger(
7367 . map ( ( _ ) => new Animated . Value ( 0 ) )
7468
7569 const animations = values . map ( ( value ) =>
76- anim ( {
70+ loop ( {
7771 value,
7872 duration,
7973 easing,
8074 toValue,
8175 keyframes,
82- infinite,
8376 } )
8477 )
8578
@@ -93,9 +86,9 @@ export function stagger(
9386 easing : easingFunction ,
9487 toValue : toValue ,
9588 useNativeDriver : true ,
96- delay : delay ,
9789 } )
98- const animation = infinite ? Animated . loop ( timing ) : timing
90+
91+ const animation = Animated . loop ( timing )
9992
10093 // React Native only does 60fps
10194 // https://github.com/facebook/react-native/blob/d3980dceab90b118cc7f69696967aa7f8d4388d9/Libraries/Animated/src/animations/TimingAnimation.js#L78
@@ -125,3 +118,5 @@ export function stagger(
125118
126119 return { animation, values }
127120}
121+
122+ export { loop , stagger , AnimationConfig }
0 commit comments