DisclosureGroup
一个用于显示可展开内容的 SwiftUI DisclosureGroup 组件。
iOS
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
Expo UI DisclosureGroup 与官方的 SwiftUI DisclosureGroup API 一致,并会显示一个展开指示器,用于显示或隐藏内容。
安装
Terminal
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
使用
基本的 disclosure group
BasicDisclosureGroupExample.tsx
import { Host, DisclosureGroup, Text } from '@expo/ui/swift-ui'; export default function BasicDisclosureGroupExample() { return ( <Host matchContents> <DisclosureGroup label="更多信息"> <Text>当 disclosure group 展开时,会显示此内容。</Text> </DisclosureGroup> </Host> ); }
初始展开
将 isExpanded 初始设置为 true,即可默认显示内容。
InitiallyExpandedExample.tsx
import { useState } from 'react'; import { Host, DisclosureGroup, Text } from '@expo/ui/swift-ui'; export default function InitiallyExpandedExample() { const [isExpanded, setIsExpanded] = useState(true); return ( <Host matchContents> <DisclosureGroup label="详情" isExpanded={isExpanded} onIsExpandedChange={setIsExpanded}> <Text>此内容默认可见。</Text> </DisclosureGroup> </Host> ); }
API
import { DisclosureGroup } from '@expo/ui/swift-ui';
Component
Type: React.Element<DisclosureGroupProps>
Type:
ReactNodeOptional • Type:
(isExpanded: boolean) => voidA callback that is called when the expansion state changes.