expo-splash-screen
@amazon-devices/expo-splash-screen库用于要求启动画面保持可见状态,直至被明确要求隐藏。此功能对于将在幕后执行的任务很有用,例如进行API调用、预加载字体或为启动画面设置动画。
安装
-
在
package.json文件中添加JavaScript库依赖项。"dependencies": { ... "@amazon-devices/expo-splash-screen": "~2.0.1", "@amazon-devices/keplerscript-turbomodule-api": "~1.0.0", ... } "overrides": { "@amazon-devices/react-native-kepler": "~2.0.0" }, -
使用
npm install命令重新安装依赖项。
示例
创建顶级<项目根目录>/assets/raw目录。放置一个名为SplashScreenImages.zip的zip文件以及一个desc.txt文件(参见以下示例)和一个包含splash.png文件的_loop文件夹。
文件夹结构:
├── assets/
├──── raw/
├────── SplashScreenImages.zip
...
├── src/
...
├── manifest.toml
desc.txt文件的示例内容:
1920 1080 30
c 0 0 _loop
启动画面示例
import {hideAsync, preventAutoHideAsync} from '@amazon-devices/expo-splash-screen';
import React from 'react';
import {useEffect} from 'react';
import {StyleSheet, Text, View} from 'react-native';
preventAutoHideAsync();
export const App = () => {
useEffect(() => {
// 在调用hide async之前执行操作
setTimeout(() => {
hideAsync();
}, 2000);
}, []);
return (
<View style={styles.container}>
<Text style={styles.text}>SplashScreen演示!👋</Text>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
alignItems: 'center',
justifyContent: 'center',
},
text: {
color: 'black',
fontSize: 32,
},
});
API参考
请查看文档页面,了解有关此库和API参考的信息: 针对expo-splash-screen的官方Expo文档(仅提供英文版)。
方法
| 方法 | 描述 |
|---|---|
hideAsync |
立即隐藏原生启动画面。当您隐藏启动画面时,请确保您的应用已准备好显示内容,否则可能会短暂地看到一个空白屏幕。有关示例,请参阅示例部分。 |
preventAutoHideAsync |
在调用hideAsync之前,使原生启动画面保持可见。 |
已知问题和限制
启动画面在Vega虚拟设备上不起作用。
支持的版本
| 程序包版本 | 基于 | @amazon-devices/react-native-kepler版本 |
|---|---|---|
| 2.0.x | 0.24.0 | 2.0.x |
相关主题
Last updated: 2025年9月30日

