Created
December 24, 2020 02:08
-
-
Save aranda-adapptor/37eb2d6bde5cfdd4944b7d8813a8f368 to your computer and use it in GitHub Desktop.
Starfield in Reanimated 2 - adding animation 2
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
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