This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

复选框

一个表示选中或未选中状态的切换控件。

Android
iOS
Web
Included in Expo Go
Recommended version:
~57.0.3

一个受控的复选框。将 valueonValueChange 配对以从 React 管理状态。

🌐 A controlled checkbox. Pair value with onValueChange to manage state from React.

安装

🌐 Installation

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.

用法

🌐 Usage

基本复选框

🌐 Basic checkbox

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="I accept the terms" value={accepted} onValueChange={setAccepted} /> </Host> ); }

已禁用

🌐 Disabled

DisabledCheckboxExample.tsx
import { Host, Checkbox } from '@expo/ui'; export default function DisabledCheckboxExample() { return ( <Host matchContents> <Checkbox label="Locked option" value onValueChange={() => {}} disabled /> </Host> ); }

应用接口

🌐 API

import { Checkbox } from '@expo/ui';

Component

Checkbox

Type: React.Element<CheckboxProps>

A toggle control that represents a checked or unchecked state.

Props for the Checkbox component.

CheckboxProps

disabled

Optional • Type: boolean

Whether the checkbox is disabled. Disabled checkboxes do not respond to user interaction.

label

Optional • Type: string

Text label displayed alongside the checkbox.

modifiers

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.

onValueChange

Type: (value: boolean) => void

Called when the user toggles the checkbox.

testID

Optional • Type: string

Identifier used to locate the component in end-to-end tests.

value

Type: boolean

Whether the checkbox is checked.