diff --git a/with-animated-splash-screen/App.js b/with-animated-splash-screen/App.js new file mode 100644 index 0000000..127063c --- /dev/null +++ b/with-animated-splash-screen/App.js @@ -0,0 +1,130 @@ +import { AppLoading, SplashScreen, Updates } from 'expo'; +import { Asset } from 'expo-asset'; +import Constants from 'expo-constants'; +import React from 'react'; +import { Animated, Button, StyleSheet, Text, View } from 'react-native'; + +// Instruct SplashScreen not to hide yet, we want to do this manually +SplashScreen.preventAutoHide(); + +export default function App() { + return ( + + + + ); +} + +function AnimatedAppLoader({ children, image }) { + const [isSplashReady, setSplashReady] = React.useState(false); + + const startAsync = React.useMemo( + // If you use a local image with require(...), use `Asset.fromModule` + () => () => Asset.fromURI(image).downloadAsync(), + [image] + ); + + const onFinish = React.useMemo(() => setSplashReady(true), []); + + if (!isSplashReady) { + return ( + + ); + } + + return ( + + {children} + + ); +} + +function AnimatedSplashScreen({ children, image }) { + const animation = React.useMemo(() => new Animated.Value(1), []); + const [isAppReady, setAppReady] = React.useState(false); + const [isSplashAnimationComplete, setAnimationComplete] = React.useState( + false + ); + + React.useEffect(() => { + if (isAppReady) { + Animated.timing(animation, { + toValue: 0, + duration: 200, + useNativeDriver: true, + }).start(() => setAnimationComplete(true)); + } + }, [isAppReady]); + + const onImageLoaded = React.useMemo(() => async () => { + SplashScreen.hide(); + try { + // Load stuff + await Promise.all([]); + } catch (e) { + // handle errors + } finally { + setAppReady(true); + } + }); + + return ( + + {isAppReady && children} + {!isSplashAnimationComplete && ( + + + + )} + + ); +} + +function MainScreen() { + return ( + + + Pretty Cool! + +