FieldGroup
一个可滚动的分组设置样式行容器。
For the complete documentation index, see llms.txt. Use this file to discover all available pages.
一个可滚动的容器,用于分组的设置样式行,外观类似 iOS 设置界面。可在其中组合使用 FieldGroup.Section(用于显式分组)、FieldGroup.SectionHeader 和 FieldGroup.SectionFooter 插槽。
安装
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
分节表单
import { useState } from 'react'; import { Host, FieldGroup, Switch, Text } from '@expo/ui'; export default function FieldGroupExample() { const [notifications, setNotifications] = useState(true); const [analytics, setAnalytics] = useState(false); return ( <Host style={{ flex: 1 }}> <FieldGroup> <FieldGroup.Section title="通知"> <Switch label="Push" value={notifications} onValueChange={setNotifications} /> <Switch label="Email" value={analytics} onValueChange={setAnalytics} /> </FieldGroup.Section> <FieldGroup.Section title="关于"> <Text>版本 1.0.0</Text> </FieldGroup.Section> </FieldGroup> </Host> ); }
自定义分节头部和底部
使用 FieldGroup.SectionHeader 和 FieldGroup.SectionFooter,以完全样式化的头部/底部插槽替代默认的 title 文本。
import { useState } from 'react'; import { Host, FieldGroup, Switch, Text } from '@expo/ui'; export default function FieldGroupSlotsExample() { const [enabled, setEnabled] = useState(false); return ( <Host style={{ flex: 1 }}> <FieldGroup> <FieldGroup.Section> <FieldGroup.SectionHeader> <Text textStyle={{ fontSize: 16, fontWeight: '700' }}>隐私</Text> </FieldGroup.SectionHeader> <Switch label="共享使用情况" value={enabled} onValueChange={setEnabled} /> <FieldGroup.SectionFooter> <Text textStyle={{ fontSize: 12, color: '#8E8E93' }}> 这有助于我们改进应用。你可以随时禁用此项。 </Text> </FieldGroup.SectionFooter> </FieldGroup.Section> </FieldGroup> </Host> ); }
API
import { FieldGroup } from '@expo/ui';
Components
Type: React.Element<FieldGroupProps>
A scrollable container for grouped settings-style rows, mirroring the look
of an iOS Settings screen. Render one or more
FieldGroup.Section components inside. Direct
non-section children are automatically grouped into an implicit section,
matching SwiftUI Form behavior.
Props for the FieldGroup component, a scrollable container
of grouped settings-style rows.
ReactNodeA collection of FieldGroup.Section components that
make up the group. Non-section children are rendered inline between
sections, matching SwiftUI Form behavior.
booleanWhether the component is disabled. Disabled components do not respond to user interaction.
ModifierConfig[]Platform-specific modifier escape hatch. Pass an array of modifier configs
from @expo/ui/swift-ui/modifiers or @expo/ui/jetpack-compose/modifiers.
() => voidCalled when the component is removed from screen.
Pick<ViewStyle, 'padding' | 'paddingHorizontal' | 'paddingVertical' | 'paddingTop' | 'paddingBottom' | 'paddingLeft' | 'paddingRight' | 'backgroundColor' | 'borderRadius' | 'borderWidth' | 'borderColor' | 'opacity' | 'width' | 'height'>Platform-agnostic style properties. These are translated to SwiftUI modifiers on iOS and Jetpack Compose modifiers on Android.
Type: React.Element<FC<FieldSectionProps>>
Props for the FieldGroup.Section component, a
grouped list of rows within a FieldGroup.
ReactNodeThe rows of the section, optionally interleaved with a single
<FieldGroup.SectionHeader> and/or <FieldGroup.SectionFooter> child
to customize the header / footer slots.
booleanWhether the component is disabled. Disabled components do not respond to user interaction.
ModifierConfig[]Platform-specific modifier escape hatch. Pass an array of modifier configs
from @expo/ui/swift-ui/modifiers or @expo/ui/jetpack-compose/modifiers.
() => voidCalled when the component is removed from screen.
Pick<ViewStyle, 'padding' | 'paddingHorizontal' | 'paddingVertical' | 'paddingTop' | 'paddingBottom' | 'paddingLeft' | 'paddingRight' | 'backgroundColor' | 'borderRadius' | 'borderWidth' | 'borderColor' | 'opacity' | 'width' | 'height'>Platform-agnostic style properties. These are translated to SwiftUI modifiers on iOS and Jetpack Compose modifiers on Android.
stringIdentifier used to locate the component in end-to-end tests.
stringA plain-text section title, rendered as the default styled header above
the group. Ignored when a <FieldGroup.SectionHeader> child is
provided.
Methods
| Parameter | Type |
|---|---|
| index | number |
| total | number |
Computes the position of a row given its index within a section of
total rows.
FieldItemPositionTypes
Literal Type: string
Position of a row within a FieldGroup.Section, used
to compute grouped-list corner radii.
Acceptable values are: 'leading' | 'middle' | 'trailing' | 'only'