Last active
July 1, 2020 16:37
-
-
Save fernandatoledo/8b136ef05d67ac73836a8615130f68ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Animated } from 'react-native'; | |
import { | |
useAnimate, | |
useAnimateParallel, | |
} from '@rootstrap/react-native-use-animate'; | |
// Other style and dimension imports | |
const ParallelAnimatedBox = () => { | |
// Be aware: animate should be false for nested animations | |
const config = { bounce: true, duration: 1000, animate: false }; | |
const left = useAnimate({ fromValue: 0, toValue: WIDTH - BOX_SIZE, ...config }); | |
const top = useAnimate({ fromValue: 0, toValue: HEIGHT - BOX_SIZE, ...config }); | |
const animatedRotation = useAnimate(config); | |
useAnimateParallel({ | |
animations: [left, top, animatedRotation], | |
iterations: -1, | |
}); | |
return ( | |
<Animated.View | |
style={[ | |
styles.box, | |
{ | |
left: left.animatedValue, | |
top: top.animatedValue, | |
transform: [ | |
{ | |
rotate: animatedRotation.interpolate({ | |
outputRange: ['0deg', '360deg'], | |
}), | |
}, | |
], | |
}, | |
]} | |
/> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment