Javascript 如何在不使用任何其他库和插件的情况下在react navigation中创建闪屏

Javascript 如何在不使用任何其他库和插件的情况下在react navigation中创建闪屏,javascript,react-native,react-redux,react-native-android,Javascript,React Native,React Redux,React Native Android,我正在构建react原生应用程序,没有使用expo和其他任何框架。我试图在react导航中创建闪屏,而不使用任何npm包和其他库,所以我的问题是:如何实现这一点 const StackNavigation = (props) => { return ( <Stack.Navigator initialRouteName="Splash" > <Stack.Screen name="Home" component={HomeScreen} o

我正在构建react原生应用程序,没有使用expo和其他任何框架。我试图在react导航中创建闪屏,而不使用任何npm包和其他库,所以我的问题是:如何实现这一点

const StackNavigation = (props) => {
   return (
    <Stack.Navigator initialRouteName="Splash"  >
        <Stack.Screen name="Home" component={HomeScreen} options={({ navigation, route }) => 
    ({
            headerLeft: props => (
                <Icon
                    name='rowing'
                    color='#00aced'
                    onPress={() => navigation.openDrawer()}
                />

            )
        })} />
        <Stack.Screen name="Post" component={PostScreen} />
        <Stack.Screen name="Splash" component={SplashScreen} options={{headerShown: false}}/>
    </Stack.Navigator>
);
}
const StackNavigation=(道具)=>{
返回(
({
标题左侧:道具=>(
navigation.openDrawer()}
/>
)
})} />
);
}

通过仅使用React本机端添加初始屏幕的一个问题是,每次启动应用程序时,您都会发现一个难看的白色屏幕,这个白色屏幕可以持续5-20秒。这是因为当你的应用程序启动时,它需要加载React native来运行你的代码,在此期间,你的代码甚至还没有开始运行,因此出现了白色屏幕

但是,如果您不关心白色屏幕,这里是我的解决方案,它也不需要反应导航,只需在componentDidMount()或useEffect()中显示初始屏幕,并在setTimeout()中显示所需的延迟时间

import React,{useState,useffect}来自“React”;
从“react native”导入{文本、视图、样式表、图像};
导出默认函数App(){
const[splash,setSplash]=使用状态(true);
useffect(()=>{
设置超时(()=>{
setSplash(假);
}, 1000);
}, []);
返回飞溅?
(
) : (
主屏幕
);
}
这是小吃

如果您需要避免在Android Studio中使用白色屏幕,谢天谢地,有几个npm库可以帮助您避免这种情况

import React, {useState, useEffect} from 'react';
import { Text, View, StyleSheet, Image } from 'react-native';

export default function App() {

  const [splash, setSplash] = useState(true);
  useEffect(() => {
    setTimeout(() => {
      setSplash(false);
    }, 1000);
  }, []);

  return splash ? 
  (<View style={styles.container}>
  <Image style={styles.logo} source={require('./assets/snack-icon.png')} />
  </View>) : (
    <View style={styles.container}>
      <Text style={styles.paragraph}>
        Home Screen
      </Text>
    </View>
  );
}