如何为 react-native android 设置启动画面 [英] How to set the splash screen for react-native android
问题描述
如何为 react-native android 设置启动画面,我找不到有关该主题的任何内容,我认为这很奇怪.
How does one set a splash screen for react-native android, I can't find anything on the topic and I thought it was odd.
谢谢
推荐答案
我尝试了以下 3 种方法.第一个是我目前用于 react-native 项目的 android 启动画面.
I had tried 3 of the following ways. The first one is what I am currently using for android splash screen for react-native projects.
使用他人编写的 npm 包.
Using a npm package written by other.
参考:https://github.com/remobile/react-native-splashscreen
创建一个 SplashScreen
组件,然后重定向.
Create a SplashScreen
component and redirect afterward.
参考:如何创建某种在应用加载后消失的启动画面/启动画面?(React Native)
原生在 java
代码中.
参考:https://www.bignerdranch.com/blog/splash-screens-the-right-way/
我在 initialRoute
的 componentDidMount()
中有一个 fetch
请求.
I have a fetch
request in the componentDidMount()
of initialRoute
.
使用上面列表中的第一种方式在显示启动画面的同时执行请求.
Using the first way from the list above performs the request while showing the splash screen.
而第二种方式,需要等到 SplashScreen
组件被卸载.
Whereas the second way, needs to wait until the SplashScreen
component get unmounted.
第三种方法是编写和维护的代码稍微多一些.
Third way is slightly more codes to write and maintain.
这篇关于如何为 react-native android 设置启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!