Skip to content

Instantly share code, notes, and snippets.

@aranda-adapptor
Created December 24, 2020 02:08
Show Gist options
  • Save aranda-adapptor/37eb2d6bde5cfdd4944b7d8813a8f368 to your computer and use it in GitHub Desktop.
Save aranda-adapptor/37eb2d6bde5cfdd4944b7d8813a8f368 to your computer and use it in GitHub Desktop.
Starfield in Reanimated 2 - adding animation 2
const Starfield: React.FC<{}> = () => {
// Create a shared time value
const timeVal = useSharedValue(0);
// Start a repeating animation that goes from 0 to 3600 in an hour
const duration = 3600;
useEffect(
() => {
timeVal.value = 0;
timeVal.value = withRepeat(
withTiming(duration, {
duration: 1000 * duration,
easing: Easing.linear,
}),
0,
false
);
},
// Tells useEffect to only trigger on mount instead of every render
[]
);
return (
<View
style={{
flex: 1,
backgroundColor: "black",
}}
>
{/* Pass in the time value */}
<Star x={100} y={100} time={timeVal} />
</View>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment