Reference version

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

Jetpack Compose

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

Android

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

重要 此库目前处于 alpha 阶段,并且将经常发生破坏性变更。 它在 Expo Go 应用中不可用 — 请使用开发构建来试用。

@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> ); }