@exodus/react-native-splash-screen

中文文档
6.0.2发布于 2026/01/29MITTypeScript零依赖近 30 天下载 1.1万

用于反应的喷出屏幕, 当应用程序装入时隐藏, 它工作在iOS和Android上.

中文使用文档
文档目录10 节
  1. 目录
  2. 演示
  3. 改变
  4. 安装说明
  5. 第一步(下载):
  6. 第二步 (安装):
  7. 第三步(配置):
  8. 使用说明
  9. API
  10. 贡献

react-native-splash-screen

Download PRs Welcome react-native-splash-screen release language English License MIT 原理 解析

React Native启动屏,解决iOS,Android启动白屏问题,支持Android和iOS。

目录

演示

react-native-splash-screen-Android react-native-splash-screen-iOS

改变

如果你项目的React Native>=0.47.请使用v3.+, 如果<0.47.0请使用v2.1.0。

安装说明

第一步(下载):

在项目根目录打开终端运行 npm i react-native-splash-screen --save

第二步 (安装):

大家可以通过自动或手动两种方式来安装react-native-splash-screen。

自动安装

终端运行:

react-native link react-native-splash-screen 或 rnpm link react-native-splash-screen

手动安装

Android:

1.在你的 android/settings.gradle 文件中添加下列代码:

include ':react-native-splash-screen'   
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')

2.在你的 android/app/build.gradle 文件中添加 :react-native-splash-screen:

代码如下:

...
dependencies {
    ...
    implementation project(':react-native-splash-screen')
}

3.更新你的MainApplication.java 文件,如下:

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        protected boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
            new SplashScreenReactPackage()  //添加这一句
            );
        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }
}

iOS:

  1. 在 XCode的项目导航视图中单击 Libraries ➜ Add Files to [your project's name]

  2. 将 SplashScreen.xcodeproj添加到你的项目中,node_modules ➜ react-native-splash-screen ➜ SplashScreen.xcodeproj

  3. 在XCode中打开Build Phases ➜ Link Binary With Libraries将libSplashScreen.a 添加到你的项目中。

  4. 如果在使用过过程中出现 'SplashScreen.h' file not found问题,你可以下面的代码添加到Header Search Paths中,步骤如下:

选择你的项目,TARGET → Build Settings → Search Paths → Header Search Paths 添加:

  `$(SRCROOT)/../node_modules/react-native-splash-screen/ios`

第三步(配置):

Android:

更新你的 MainActivity.java 文件如下:

public class MainActivity extends ReactActivity {
   @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this);  // 添加这一句
        super.onCreate(savedInstanceState);
    }
    // ...other code
}

iOS:

更新你的AppDelegate.m 文件如下:

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h"  // 添加这一句

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ...other code

    [RNSplashScreen show];  // 添加这一句,这一句一定要在最后
    return YES;
}

@end

使用说明

将 react-native-splash-screen 导入你的JS 文件。

import SplashScreen from 'react-native-splash-screen'

Android:

创建一个名为 launch_screen.xml 的布局文件来自定义你的启动屏幕。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/launch_screen">
</LinearLayout>

另外:

你也可以启用app主题透明选项来解决在APP启动时因主题原因导致的短暂白屏的问题,具体步骤如下:

打开 android/app/src/main/res/values/styles.xml文件,添加 <item name="android:windowIsTranslucent">true</item>,如下 :

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <!--设置透明背景-->
        + <item name="android:windowIsTranslucent">true</item>
    </style>
</resources>

更详细的介绍,可以查看 examples

iOS

iOS可以通过LaunchImage或LaunchScreen.xib来自定义你的启动屏幕。

更详细的介绍,可以查看 examples

最后,你可以在适当的时候关闭启动屏幕(如:启动初始化完成后):

import SplashScreen from 'react-native-splash-screen'

export default class WelcomePage extends Component {

    componentDidMount() {
         // do anything while splash screen keeps, use await to wait for an async task.
        SplashScreen.hide();//关闭启动屏幕
    }
}

API

方法类型可选描述
show()  functionfalse打开启动屏幕(原生方法)
hide()functionfalse关闭启动屏幕

贡献

欢迎大家提问题,如果能给问题加上一个截图,则是极好的。另外欢迎Pull requests贡献你的代码。


MIT Licensed

版本与发布记录

@exodus/react-native-splash-screen 共发布 30 个版本,首次发布于 2019/04/09;过去 12 个月发布了 3 个版本。

版本发布日期距今
6.0.2latest2026/01/299 个月前
6.0.12026/01/0710 个月前
4.0.32026/01/0710 个月前
6.1.02024/08/232 年前
6.0.02024/02/132 年前
6.0.0-rc.12024/02/132 年前

其他发布通道:old → 3.4.1。

关于 @exodus/react-native-splash-screen 的常见问题

@exodus/react-native-splash-screen 是什么?

用于反应的喷出屏幕, 当应用程序装入时隐藏, 它工作在iOS和Android上.

如何安装 @exodus/react-native-splash-screen?

在项目目录运行 npm install @exodus/react-native-splash-screen,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react-native(>=0.57.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@exodus/react-native-splash-screen 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@exodus/react-native-splash-screen 可以商用吗?

@exodus/react-native-splash-screen 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/react-native-splash-screen 的下载量有多少?

根据 npm 官方下载统计,@exodus/react-native-splash-screen 在 2026/10/14 – 2026/11/12 这 30 天内被下载 10,639 次,日均约 355 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@exodus/react-native-splash-screen 还在维护吗?

最新版本 6.0.2 发布于 2026/01/29(9 个月前);至今共发布 30 个版本,其中过去 12 个月发布了 3 个;首次发布于 2019/04/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。