SPB Git

Repository Public MIT

glass-progress.md 3.6 KB 81 lines markdown

1# GlassProgress23| | |4|---|---|5| Identifier | `glass-progress` |6| Module | `SPGlassComponents` |7| Kind | `native-wrapper` — the system `ProgressView`; the theme only sets the tint |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Feedback/GlassProgressExample.swift` |1011## Minimal usage1213```swift14GlassProgress("Uploading", value: uploadedBytes, total: totalBytes)15```1617## Variants1819| Variant | Use |20|---|---|21| Determinate | `value:` and `total:`; shows the percentage unless `showsPercent` is false. |22| Indeterminate | No value: `GlassProgress("Connecting")`. |23| `.linear` (default) | Label and percentage above a bar. |24| `.circular` | Ring (determinate) or spinner (indeterminate) before the label. |25| `onCancel:` | Adds a cancel button. |2627## Parameters2829| Parameter | Type | Default | Meaning |30|---|---|---|---|31| `label` | `LocalizedStringKey?` or `Text?` | `nil` | What is in progress. |32| `value` | `Double` | — | Completed amount, clamped to `0...total`. |33| `total` | `Double` | `1` | Amount that means "finished". |34| `fraction` | `Double?` | — | Alternative to `value`/`total`; `nil` is indeterminate. |35| `style` | `GlassProgressStyle` | `.linear` | Shape of the indicator. |36| `showsPercent` | `Bool` | `true` | Shows the percentage (determinate only). |37| `onCancel` | `(@MainActor () -> Void)?` | `nil` | Shows the cancel button. |3839`GlassProgressMath.fraction(value:total:)` returns 0 for a total that is zero, negative or not finite and for a value that is not finite; otherwise the ratio clamped to 0...1. `percentText(_:locale:)` formats with `FormatStyle` ("42%", "42 %").4041### Styles4243| Style | Appearance |44|---|---|45| `.linear` | A capsule bar under the label and the percentage. |46| `.circular` | A small ring next to the label; a turning arc when indeterminate. |47| `.ring` | A large ring with the percentage in its centre and the label underneath. |48| `.steps` | One segment per step: `GlassProgress("Shipping address", step: 2, of: 4)` shows "2 / 4". |4950The indicator stays the native `ProgressView`, drawn by a GlassKit `ProgressViewStyle` in the theme's primary colour. With Reduce Motion the indeterminate bar and arc stop moving. `GlassProgressMath.steps(_:of:)` and `completedSegments(fraction:count:)` are pure and public. VoiceOver reads a stepped indicator as a percentage.5152## States5354Determinate (0 to 100 %) or indeterminate. The component does not decide completion: the host removes it or replaces it when the work is done or cancelled.5556## Advanced example5758```swift59switch download.state {60case .preparing:61    GlassProgress("Preparing", style: .circular, onCancel: { download.cancel() })62case .running(let received, let expected):63    GlassProgress(label: Text(download.fileName), fraction: GlassProgressMath.fraction(value: received, total: expected),64                  onCancel: { download.cancel() })65case .finished:66    GlassBanner(.success, title: "Download complete")67}68```6970## Accessibility7172- The indicator and its label are one element: label (or "Loading" when none), value "42 percent" (or "Loading" when indeterminate), with the updates-frequently trait.73- The cancel button is a separate element labelled "Cancel" with the minimum hit target.74- The percentage uses monospaced digits so the label does not shift as the value changes.7576## Limits7778- The bar, ring and spinner are drawn by the system; their size follows `.controlSize(_:)`, not a GlassKit parameter.79- No estimated time remaining and no automatic completion state.80- A spinner animates for as long as it is on screen; remove indeterminate indicators when nothing is in progress.81
Files main
Menu

Theme