This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 56).
复选框
一种表示已选中或未选中状态的切换控件。
Android
iOS
Web
Included in Expo Go
For the complete documentation index, see llms.txt. Use this file to discover all available pages.
受控复选框。将 value 与 onValueChange 配对,以从 React 管理状态。
安装
Terminal
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
使用
基础复选框
CheckboxExample.tsx
import { useState } from 'react'; import { Host, Checkbox } from '@expo/ui'; export default function CheckboxExample() { const [accepted, setAccepted] = useState(false); return ( <Host matchContents> <Checkbox label="我接受这些条款" value={accepted} onValueChange={setAccepted} /> </Host> ); }
禁用
DisabledCheckboxExample.tsx
import { Host, Checkbox } from '@expo/ui'; export default function DisabledCheckboxExample() { return ( <Host matchContents> <Checkbox label="锁定选项" value onValueChange={() => {}} disabled /> </Host> ); }
API
import { Checkbox } from '@expo/ui';
Component
Type: React.Element<CheckboxProps>
A toggle control that represents a checked or unchecked state.
Props for the Checkbox component.
Optional • Type:
booleanWhether the checkbox is disabled. Disabled checkboxes do not respond to user interaction.
Optional • Type:
ModifierConfig[]Platform-specific modifier escape hatch. Pass an array of modifier configs
from @expo/ui/swift-ui/modifiers or @expo/ui/jetpack-compose/modifiers.
Optional • Type:
stringIdentifier used to locate the component in end-to-end tests.