Reference version

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

SwiftUI

使用 @expo/ui 构建原生 iOS 界面的 SwiftUI 组件。

iOS
tvOS

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

重要 此库目前处于 beta 阶段,且可能发生破坏性变更。 它在 Expo Go 应用中不可用 — 请使用 development builds 进行尝试。

@expo/ui/swift-ui 中的 SwiftUI 组件允许你在 React Native 中使用 SwiftUI 构建完全原生的 iOS 界面。

安装

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/swift-ui 中的组件时,需要将其包装在 Host 组件中。Host 是 SwiftUI 视图的容器。

import { Host, Button } from '@expo/ui/swift-ui'; export function SaveButton() { return ( <Host style={{ flex: 1 }}> <Button label="保存更改" /> </Host> ); }

更多信息请参阅以下资源:

Expo UI Swift UI 指南

了解 @expo/ui/swift-ui 的基础知识

使用 SwiftUI 扩展

创建可与 Expo UI 集成的自定义 SwiftUI 组件和修饰器。

Expo UI iOS Liquid Glass 教程
Expo UI iOS Liquid Glass 教程

了解如何在你的 React Native 应用中使用新的 Expo UI 构建真正的 SwiftUI 视图。