SPB Git

Repository Public MIT

glass-location-button.md 2.9 KB 78 lines markdown

1# GlassLocationButton23| | |4|---|---|5| Identifier | `glass-location-button` |6| Module | `SPGlassMaps` |7| Kind | `custom-glass` — a round interactive `glassSurface` |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Maps/GlassLocationButtonExample.swift` |1011## Minimal usage1213```swift14GlassLocationButton(state: model.locationState) { model.locationButtonTapped() }15```1617## Variants1819| State | Symbol | Label | Enabled |20|---|---|---|---|21| `.idle` | `location` | "Show my location" | yes |22| `.locating` | `location`, pulsing | "Finding your location" | yes |23| `.following` | `location.fill`, primary colour | "Following your location" | yes |24| `.denied` | `location.slash` | "Location access denied" | yes — the host can explain or open Settings |25| `.unavailable` | `location.slash` | "Location unavailable" | no |2627## Parameters2829| Parameter | Type | Default | Meaning |30|---|---|---|---|31| `state` | `GlassLocationState` | — | State reported by the host. |32| `hint` | `String?` | `nil` | Explanation read as the accessibility hint and shown as the tooltip on macOS. |33| `size` | `GlassControlSize` | `.regular` | Size of the control. |34| `action` | `@MainActor () -> Void` | — | Called on activation. |3536The mapping from state to symbol, label and enabled flag is `GlassLocationPresentation(state)`, a value type usable without the view.3738## States3940See the table above. The pulse of `.locating` is a symbol effect that stops with Reduce Motion; the state is then conveyed by the label alone.4142## Advanced example4344```swift45@MainActor @Observable46final class LocationModel: NSObject, CLLocationManagerDelegate {47    private let manager = CLLocationManager()48    private(set) var state = GlassLocationState.idle4950    func buttonTapped() {51        switch manager.authorizationStatus {52        case .notDetermined: manager.requestWhenInUseAuthorization()   // the host asks, never the button53        case .denied: openSettings()54        case .restricted: state = .unavailable55        default: state = .locating; manager.startUpdatingLocation()56        }57    }58    // delegate callbacks update `state` to .following, .denied, …59}6061GlassLocationButton(62    state: model.state,63    hint: model.state == .denied ? "Opens Settings to allow location access" : nil64) { model.buttonTapped() }65```6667## Accessibility6869- The label is the state itself ("Location access denied"), so VoiceOver announces it without relying on the symbol.70- Denied and unavailable use a slashed symbol and their own label — never colour alone.71- `hint` becomes the accessibility hint; while locating the button has the "updates frequently" trait.72- The target is at least 44 points on iOS and iPadOS.7374## Limits7576- The button never requests the location permission, never reads a position and does not import Core Location: all of that is the host's code.77- There is no visible text next to the symbol; put a banner or an alert in the host if the denied state needs a visible explanation.78
Files main
Menu

Theme