Reference version

This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 56).

Jetpack Compose

使用 @expo/ui 构建原生 Android 界面的 Jetpack Compose 组件。

Android
Included in Expo Go

For the complete documentation index, see llms.txt. Use this file to discover all available pages.

@expo/ui/jetpack-compose 中的 Jetpack Compose 组件允许你使用来自 React Native 的 Jetpack Compose 构建完全原生的 Android 界面。

安装

Terminal
npx expo install @expo/ui

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

使用 @expo/ui/jetpack-compose 中的组件需要将其包装在一个 Host 组件中。Host 是 Jetpack Compose 视图的容器。

import { Host, Button } from '@expo/ui/jetpack-compose'; export function SaveButton() { return ( <Host matchContents> <Button onClick={() => alert('已保存!')}>保存更改</Button> </Host> ); }