且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何为 react-native android 设置启动画面

更新时间:2021-08-16 22:08:39

我尝试了以下 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.

  1. 使用他人编写的 npm 包.

  1. 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/

我在 initialRoutecomponentDidMount() 中有一个 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.