Last active
July 1, 2020 16:38
-
-
Save fernandatoledo/2b2813757178ecae28851457e15b1160 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, {useEffect, useRef} from 'react'; | |
import { Animated } from 'react-native'; | |
// Other style and dimension imports | |
const SequenceAnimatedBox = () => { | |
const left = useRef(new Animated.Value(0)).current; | |
const top = useRef(new Animated.Value(0)).current; | |
useEffect(() => { | |
Animated.loop( | |
Animated.sequence([ | |
Animated.timing(left, { | |
toValue: WIDTH - BOX_SIZE, | |
duration: 1000, | |
}), | |
Animated.timing(top, { | |
toValue: HEIGHT - BOX_SIZE, | |
duration: 1000, | |
}), | |
]), | |
{ iterations: -1 }, | |
).start(); | |
}, []); | |
return ( | |
<Animated.View | |
style={[ | |
styles.box, | |
{ | |
left, | |
top, | |
}, | |
]} | |
/> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment