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

仪表

一个用于显示进度的 SwiftUI 仪表组件,带有可视化指示器。

iOS
Included in Expo Go
Recommended version:
~57.0.3

Expo UI Gauge 与官方的 SwiftUI Gauge API 相匹配,并支持通过 gaugeStyle 修饰符进行样式设置。

🌐 Expo UI Gauge matches the official SwiftUI Gauge API and supports styling via the gaugeStyle modifier.

Circular capacity Gauge showing 70%

安装

🌐 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 gauge

BasicGaugeExample.tsx
import { Host, Gauge } from '@expo/ui/swift-ui'; export default function BasicGaugeExample() { return ( <Host matchContents> <Gauge value={0.5} /> </Host> ); }

带标签

🌐 With label

你可以将自定义组件作为 children 传递,以为仪表提供标签。

🌐 You can pass custom components as children to provide a label for the gauge.

LabelExample.tsx
import { Host, Gauge, Text } from '@expo/ui/swift-ui'; export default function LabelExample() { return ( <Host matchContents> <Gauge value={0.7}> <Text>Progress</Text> </Gauge> </Host> ); }

带有数值标签

🌐 With value labels

使用 currentValueLabelminimumValueLabelmaximumValueLabel 属性显示数值信息。

🌐 Use the currentValueLabel, minimumValueLabel, and maximumValueLabel props to display value information.

ValueLabelsExample.tsx
import { Host, Gauge, Text } from '@expo/ui/swift-ui'; export default function ValueLabelsExample() { return ( <Host matchContents> <Gauge value={50} min={0} max={100} currentValueLabel={<Text>50%</Text>} minimumValueLabel={<Text>0</Text>} maximumValueLabel={<Text>100</Text>}> <Text>Usage</Text> </Gauge> </Host> ); }

仪表样式

🌐 Gauge styles

使用 gaugeStyle 修饰符来更改仪表的外观。可用的样式有:automaticcircularcircularCapacitylinearlinearCapacity

🌐 Use the gaugeStyle modifier to change the gauge's appearance. Available styles are: automatic, circular, circularCapacity, linear, and linearCapacity.

GaugeStylesExample.tsx
import { Host, Gauge, Text, VStack } from '@expo/ui/swift-ui'; import { gaugeStyle } from '@expo/ui/swift-ui/modifiers'; export default function GaugeStylesExample() { return ( <Host matchContents> <VStack spacing={16}> <Gauge value={0.5} modifiers={[gaugeStyle('circular')]}> <Text>Circular</Text> </Gauge> <Gauge value={0.5} modifiers={[gaugeStyle('circularCapacity')]}> <Text>Circular Capacity</Text> </Gauge> <Gauge value={0.5} modifiers={[gaugeStyle('linear')]}> <Text>Linear</Text> </Gauge> <Gauge value={0.5} modifiers={[gaugeStyle('linearCapacity')]}> <Text>Linear Capacity</Text> </Gauge> </VStack> </Host> ); }

有色表盘

🌐 Tinted gauge

使用 tint 修饰符来更改仪表的颜色。

🌐 Use the tint modifier to change the gauge's color.

TintedGaugeExample.tsx
import { Host, Gauge, VStack } from '@expo/ui/swift-ui'; import { gaugeStyle, tint } from '@expo/ui/swift-ui/modifiers'; export default function TintedGaugeExample() { return ( <Host matchContents> <VStack spacing={16}> <Gauge value={0.7} modifiers={[gaugeStyle('circular'), tint('green')]} /> <Gauge value={0.3} modifiers={[gaugeStyle('linear'), tint('red')]} /> </VStack> </Host> ); }

应用接口

🌐 API

import { Gauge } from '@expo/ui/swift-ui';

Component

Gauge

Type: React.Element<GaugeProps>

Renders a SwiftUI Gauge component.

GaugeProps

children

Optional • Type: ReactNode

A label describing the gauge's purpose.

currentValueLabel

Optional • Type: ReactNode

A label showing the current value. Use Text or Label to display the value.

max

Optional • Type: number • Default: 1

The maximum value of the gauge range.

maximumValueLabel

Optional • Type: ReactNode

A label showing the maximum value. Use Text or Label to display the value.

min

Optional • Type: number • Default: 0

The minimum value of the gauge range.

minimumValueLabel

Optional • Type: ReactNode

A label showing the minimum value. Use Text or Label to display the value.

value

Type: number

The current value of the gauge.