Reference version

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

链接

一个用于显示可点击链接的 SwiftUI Link 组件。

iOS
tvOS

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

Expo UI Link 与官方的 SwiftUI Link API 一致。

安装

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.

使用

基本链接

BasicLinkExample.tsx
import { Host, Link } from '@expo/ui/swift-ui'; export default function BasicLinkExample() { return ( <Host style={{ flex: 1 }}> <Link label="访问 Expo" destination="https://expo.dev" /> </Host> ); }

自定义标签内容

你可以将自定义组件作为 children 传入,以实现更复杂的链接标签内容。

CustomContentExample.tsx
import { Host, Link, VStack, Image, Text } from '@expo/ui/swift-ui'; export default function CustomContentExample() { return ( <Host matchContents> <Link destination="https://expo.dev"> <VStack spacing={4}> <Image systemName="link" /> <Text>Expo</Text> </VStack> </Link> </Host> ); }

API

import { Link } from '@expo/ui/swift-ui';

Component

iOS
tvOS

Type: React.Element<LinkProps>

Displays a native link component.

Example

import { Link } from '@expo/ui/swift-ui'; import { foregroundStyle, font } from '@expo/ui/swift-ui/modifiers'; <Link label="Open" destination="https://expo.dev" modifiers={[ foregroundStyle('red'), font({ size: 24, weight: 'bold' }) ]} />

LinkProps

children

iOS
tvOS
Optional • Literal type: union

Custom content for the link label. Use this for custom label views. Only nested elements are supported, not plain strings.

Acceptable values are: React.ReactElement | React.ReactElement

destination

iOS
tvOS
Optional • Type: string

The URL for the link.

label

iOS
tvOS
Optional • Type: string

The text label for the Link. Use this for simple text links.