Skip to content

Instantly share code, notes, and snippets.

@fernandatoledo
Last active July 1, 2020 16:37
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/8b136ef05d67ac73836a8615130f68ca to your computer and use it in GitHub Desktop.
Save fernandatoledo/8b136ef05d67ac73836a8615130f68ca to your computer and use it in GitHub Desktop.
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