This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
Expo 启动画面
一个用于控制原生启动画面可见性行为的库。
expo-splash-screen 库中的 SplashScreen 模块提供了对原生启动画面行为的控制。默认情况下,当你的应用准备就绪时,启动画面会自动隐藏,但你也可以在高级使用场景中手动控制其可见性。
从 SDK 52 开始,由于支持最新 Android 启动画面 API 的变更,Expo Go 和开发构建无法完全复现你的 独立应用 中用户将看到的启动画面体验。Expo Go 将显示你的应用图标而不是启动画面,而开发构建中的启动画面也不会反映配置插件中设置的所有属性。强烈建议你在发布构建上测试启动画面,以确保它看起来符合预期。
另请参阅关于创建启动画面图片的指南。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
对于大多数应用来说,你不需要对启动画面做任何特殊处理。它会在应用准备就绪时自动隐藏。你也可以选择配置动画选项:
延迟隐藏启动画面
在某些情况下,可能需要延迟隐藏启动画面,直到某些资源加载完成。例如,如果你需要在显示应用内容之前加载 API 数据,你可以使用 preventAutoHideAsync() 来手动控制启动画面何时隐藏。目标应该是在尽可能早的时间隐藏启动画面。
配置
如果你在项目中使用配置插件(Continuous Native Generation (CNG)),可以使用其内置的 配置插件 来配置 expo-splash-screen。该插件允许你配置各种无法在运行时设置的属性,并且需要构建一个新的应用二进制文件才能生效。如果你的应用不使用 CNG,那么你需要手动配置该库。
如下所示,使用配置插件是配置启动画面的推荐方法。 其他方法现在被视为旧方案,未来将会移除。
Example app.json with config plugin
Configurable properties
Are you using this library in an existing React Native app?
查看 expo-splash-screen 仓库中的安装说明,了解如何配置原生项目。
启动画面动画
SplashScreen 提供了开箱即用的淡入淡出动画。可以使用 setOptions 方法进行配置。
SplashScreen.setOptions({ duration: 1000, fade: true, });
如果你更喜欢使用自定义动画,请查看 with-splash-screen 示例,了解如何为启动画面应用任意动画。你可以通过运行 npx create-expo-app --example with-splash-screen 基于此示例初始化一个新项目。
API
import * as SplashScreen from 'expo-splash-screen';
Props
Partial<AndroidSplashConfig>Properties for configuring the splash screen on Android.
string • Default: "#ffffff"Hex color for the splash screen background.
{
backgroundColor: string,
image: string
}Properties for configuring the splash screen in dark mode.
boolean • Default: falseWhether to use a full screen image as the splash screen. Legacy transition helper, will be removed.
Methods
Hides the native splash screen immediately. Be careful to ensure that your app has content ready to display when you hide the splash screen, or you may see a blank screen briefly. See the "Usage" section for an example.
voidMakes the native splash screen (configured in app.json) remain visible until hideAsync is called.
Important note: It is recommended to call this in global scope without awaiting, rather than inside React components or hooks, because otherwise this might be called too late, when the splash screen is already hidden.
Promise<boolean>Example
import * as SplashScreen from 'expo-splash-screen'; SplashScreen.preventAutoHideAsync(); export default function App() { // ... }
Configures the splashscreens default animation behavior.
void