Skip to content

Instantly share code, notes, and snippets.

@fernandatoledo
Last active July 1, 2020 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandatoledo/2b2813757178ecae28851457e15b1160 to your computer and use it in GitHub Desktop.
Save fernandatoledo/2b2813757178ecae28851457e15b1160 to your computer and use it in GitHub Desktop.
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