GlassLocationButton
Location action with injected state; permission is requested by the host application only.
- Custom glass
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-location-button
Draws its own Liquid Glass surface, with an opaque form when Reduce Transparency is on.
CaptureInstallation
spglass add glass-location-buttonCopies the sources and their dependencies into your project. Set up the CLI.
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")
import SPGlassKit| Identifier | glass-location-button |
|---|---|
| Module | SPGlassMaps |
| Kind | custom-glass — a round interactive glassSurface |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Maps/GlassLocationButtonExample.swift |
Minimal usage
GlassLocationButton(state: model.locationState) { model.locationButtonTapped() }Variants
| State | Symbol | Label | Enabled |
|---|---|---|---|
.idle | location | "Show my location" | yes |
.locating | location, pulsing, with an arc on the rim | "Finding your location" | yes |
.following | location.fill, primary colour | "Following your location" | yes |
.denied | location.slash with an exclamation badge | "Location access denied" | yes — the host can explain or open Settings |
.unavailable | location.slash, dimmed | "Location unavailable" | no |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
state | GlassLocationState | — | State reported by the host. |
hint | String? | nil | Explanation read as the accessibility hint and shown as the tooltip on macOS. |
size | GlassControlSize | .regular | Size of the control. |
action | @MainActor () -> Void | — | Called on activation. |
The mapping from state to symbol, label and enabled flag is GlassLocationPresentation(state), a value type usable without the view.
States
See 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.
Advanced example
@MainActor @Observable
final class LocationModel: NSObject, CLLocationManagerDelegate {
private let manager = CLLocationManager()
private(set) var state = GlassLocationState.idle
func buttonTapped() {
switch manager.authorizationStatus {
case .notDetermined: manager.requestWhenInUseAuthorization() // the host asks, never the button
case .denied: openSettings()
case .restricted: state = .unavailable
default: state = .locating; manager.startUpdatingLocation()
}
}
// delegate callbacks update `state` to .following, .denied, …
}
GlassLocationButton(
state: model.state,
hint: model.state == .denied ? "Opens Settings to allow location access" : nil
) { model.buttonTapped() }Accessibility
- The label is the state itself ("Location access denied"), so VoiceOver announces it without relying on the symbol.
- Denied and unavailable use a slashed symbol and their own label — never colour alone.
hintbecomes the accessibility hint; while locating the button has the "updates frequently" trait.- The target is at least 44 points on iOS and iPadOS.
Limits
- 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.
- 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.
Example
import SwiftUI
import SPGlassKit
public struct GlassLocationButtonExample: GlassExample {
public static let componentID = "glass-location-button"
/// The example plays the host's role with a simulated state: no permission is requested, no position is read.
@State private var state = GlassLocationState.idle
@State private var message = "Sample data · simulated states, no location access"
public init() {}
public var body: some View {
VStack(spacing: 16) {
SampleMapBackdrop()
.overlay(alignment: .bottomTrailing) {
GlassLocationButton(state: state, hint: hint) { advance() }
.padding()
}
Picker("Simulated state", selection: $state) {
ForEach(GlassLocationState.allCases, id: \.self) { state in
Text(GlassLocationPresentation(state).label).tag(state)
}
}
.padding(.horizontal)
HStack(spacing: 12) {
ForEach(GlassLocationState.allCases, id: \.self) { state in
GlassLocationButton(state: state, size: .small) {}
}
}
Text(message)
.font(.caption)
.foregroundStyle(.secondary)
.padding(.horizontal)
}
.padding(.bottom)
}
private var hint: String? {
switch state {
case .denied: "Location access was refused. Activating the button would open Settings in a real application."
case .unavailable: "Location services are off on this device."
default: nil
}
}
/// What a host might do on a tap, simulated.
private func advance() {
switch state {
case .idle:
state = .locating
message = "The host would start location updates here."
case .locating:
state = .following
message = "A position arrived: the map follows it."
case .following:
state = .idle
message = "Following stopped."
case .denied:
message = "The host would open Settings here."
case .unavailable:
break
}
}
}
#Preview("GlassLocationButton") { GlassLocationButtonExample().glassTheme(.emerald) }
Registry entry
| Identifier | glass-location-button |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation, glass-icon-button |
| Frameworks | SwiftUI |
| Public symbols | GlassLocationState, GlassLocationPresentation, GlassLocationButton |
| Licence | MIT |
| Manifest | manifest.json |
Files
Maps/Maps/GlassLocationButton.swift8017 bytes · sha256 98a116afebfa…