Show splash screen before show main screen in react native without using 3rd party library

前端 未结 5 1381
忘掉有多难
忘掉有多难 2021-01-31 10:47

I am beginner in react native so may be my question seems silly to all experts.

but I am struggling with a basic feature that i want to implement that i want to start my

5条回答
  •  你的背包
    2021-01-31 11:46

    That's how I do it:

    1. Create a component for your splash screen and place it at the bottom of your App.js, something like:

      return (
         <>
            
               
               
            
      
            
         
      )
      
    2. Your can be something like:

      import React, { useEffect, useState } from 'react'
      import { Image, StatusBar, Text, Animated } from 'react-native'
      
      const SplashScreen = ({ }) => {
         const [done, setdone] = useState(false)
         const animationOpacity = React.useRef(new Animated.Value(1)).current
         const animationScale = React.useRef(new Animated.Value(1)).current
      
         if (done) return null
      
         function hideAnimation() {
              Animated.parallel([
                  Animated.timing(animationOpacity, {
                     toValue: 0,
                     delay: 1000,
                     duration: 400,
                     useNativeDriver: true
                 }),
                 Animated.timing(animationScale, {
                     toValue: 10,
                     delay: 1000,
                     duration: 400,
                     useNativeDriver: true
                 })
              ]).start(() => setdone(true))
          }
      
          hideAnimation()
      
          return (
              
      
                  
      
                  
                       // some image or icon
                      Some text
                  
      
              
          )
      }
      
      export default SplashScreen
      
    3. Adjust the Animation params, backgroundColor, Image, Text according to your needs.

提交回复
热议问题