ProgressView
A bar when there is a value, a spinner when there isn't. Flat, as on iOS: no glass.
import { ProgressView } from "@adamexu/glass";Bar
With a value it is a bar, filled to value / total: the label (children) goes over it, currentValueLabel under it. A bar's value changes in a step, never animated, as SwiftUI's does even under withAnimation. progressViewStyle="linear" without a value is an empty, still track.
const [progress, setProgress] = useState(0.4);
<ProgressView value={progress} currentValueLabel={`${Math.round(progress * 100)}%`}>
Downloading
</ProgressView>
<ProgressView value={7} total={10} tint="#34C759" aria-label="Storage" />
<ProgressView progressViewStyle="linear" aria-label="Waiting" />
<Button buttonStyle="plain" onClick={() => setProgress((p) => (p > 0.5 ? 0.2 : 0.8))}>
Change the bar
</Button>Spinner
Without a value it spins. Spinners are 14 px (mini, small), 20 (regular) or 37 (large, extraLarge), with the label centered under them. The spinner is 16 frames stepped on the compositor, so it keeps time while the main thread is busy.
<ProgressView controlSize="small" />
<ProgressView />
<ProgressView controlSize="large" />
<ProgressView tint="#FF2D55">Loading</ProgressView>In a List
Each one is its own row. While a presentation (an alert, a sheet, a pop-up) is up, a bar's fill goes gray, as UIKit dims its tints.
const [progress, setProgress] = useState(0.4);
<NavigationStack
root={
<NavigationPage title="Downloads">
<List>
<Section header="Progress">
<ProgressView />
<ProgressView>Loading</ProgressView>
<ProgressView value={progress} />
<ProgressView value={progress} currentValueLabel={`${Math.round(progress * 100)}%`}>
<Text>Downloading</Text>
</ProgressView>
<Button buttonStyle="plain" onClick={() => setProgress((p) => (p > 0.5 ? 0.2 : 0.8))}>
Change the bar
</Button>
</Section>
</List>
</NavigationPage>
}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | null | - | null or left out: indeterminate. |
| total | number | 1 | The value that fills the bar. |
| progressViewStyle | "automatic" | "circular" | "linear" | "automatic" | automatic: a bar with a value, a spinner without. circular always spins; linear without a value is an empty, still track. |
| controlSize | "mini" | "small" | "regular" | "large" | "extraLarge" | "regular" | Spinners only: 14 px (mini, small), 20, 37 (large, extraLarge). |
| tint | string | - | A bar's fill, a spinner's blades. |
| children | ReactNode | - | The label: under a spinner (centered, secondary), over a bar. |
| currentValueLabel | ReactNode | - | Under a bar. |
| disabled | boolean | false | Accepted and ignored: .disabled doesn't change a ProgressView. |
| aria-label | string | - | On the role="progressbar" element; a string label names it otherwise. |
| className, style | string, CSSProperties | - | On the same element. |
Accessibility
It is a role="progressbar". A bar has aria-valuenow, aria-valuemin 0 and aria-valuemax total; a spinner is aria-busy and named "Loading" unless labelled.
SwiftUI
| SwiftUI | @adamexu/glass |
|---|---|
| ProgressView() | <ProgressView /> |
| ProgressView(value:, total:) { label } currentValueLabel: { } | <ProgressView value total currentValueLabel>label</ProgressView> |
| .progressViewStyle(.circular / .linear) | progressViewStyle="circular" / "linear" |
| .controlSize(.small / .large) | controlSize="small" / "large" |
| .tint(c) | tint={c} |