This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
FieldGroup
一个可滚动的分组设置样式行容器。
一个可滚动的容器,用于分组的设置样式行,外观与 iOS 设置页面一致。内部可组合使用 FieldGroup.Section(用于显式分组)、FieldGroup.SectionHeader 和 FieldGroup.SectionFooter。
注意:
FieldGroup会滚动,并且本身没有高度。它会拉伸以填满其父容器,因此请为它提供一个具有确定大小的父容器,例如<Host style={{ flex: 1 }}>,或者一个具有显式高度的 host。它不会出现在类似<Host matchContents>这种按内容自适应大小的容器中,因为没有受限的高度供该组填充。
安装
- 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="推送" value={notifications} onValueChange={setNotifications} /> <Switch label="电子邮件" 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.
A modifier supplied here replaces any modifier of the same type that the
component derives from style or other props.
() => 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.
A modifier supplied here replaces any modifier of the same type that the
component derives from style or other props.
() => 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'