GlassCompass
Compass driven by an injected heading, with reset to north and an unavailable state.
- Custom glass
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-compass
Draws its own Liquid Glass surface, with an opaque form when Reduce Transparency is on.
CaptureInstallation
spglass add glass-compassCopies 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-compass |
|---|---|
| Module | SPGlassMaps |
| Kind | custom-glass — a round interactive glassSurface with a drawn dial: a two-tone needle (north half in the theme's destructive colour) and four cardinal ticks |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Maps/GlassCompassExample.swift |
Minimal usage
GlassCompass(heading: mapHeading) { mapHeading = 0 }Variants
| Variant | Use |
|---|---|
heading: Double | The needle points north for a map rotated by that heading. |
heading: nil | Heading unavailable: outlined, dimmed needle; the button is disabled. |
size: | .small, .regular, .large. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
heading | Double? | — | Direction the top of the map points to, degrees clockwise from north. Any finite value; it is normalised to 0…359. NaN and infinities count as unavailable. |
size | GlassControlSize | .regular | Size of the control. |
onResetNorth | @MainActor () -> Void | — | Called on activation; the host rotates its map back to north. |
States
- Heading known: filled north arrow in the theme's
destructivecolour (the conventional red needle), rotated by the opposite of the heading. - Unavailable: outlined arrow in the secondary text colour, not rotated, button disabled.
- Pressed / focused: the interactive glass reacts to touch and pointer.
The needle rotates along the shortest arc: from 350° to 10° it turns 20°, not 340° (GlassHeading.needleRotation).
Advanced example
struct MapChrome: View {
@Bindable var engine: TileEngine // a GlassMapEngine
var body: some View {
GlassCompass(heading: engine.heading, size: .large) {
withAnimation(.smooth) { engine.resetNorth() }
}
.opacity(engine.heading == 0 ? 0.6 : 1) // de-emphasise when already north-up
}
}Accessibility
- Label "Reset to north"; value "Heading 270 degrees" or "Heading unavailable". The tooltip on macOS is the same text.
- Availability is conveyed by the shape of the symbol (filled or outlined), the disabled state and the value — not by colour alone.
- With Reduce Motion the needle is set to its new angle without a rotation animation.
- The target is at least 44 points on iOS and iPadOS.
Limits
- The compass shows an injected heading: it does not read the device compass or any sensor.
- The needle is an SF Symbol; there are no cardinal letters or degree ticks.
- Every change of
headingstarts a short animation; an engine that reports the heading on every frame of a gesture should round it or throttle it.
Example
import SwiftUI
import SPGlassKit
public struct GlassCompassExample: GlassExample {
public static let componentID = "glass-compass"
@State private var heading = 315.0
@State private var resetCount = 0
public init() {}
public var body: some View {
VStack(spacing: 16) {
SampleMapBackdrop(heading: heading)
.overlay(alignment: .topTrailing) {
VStack(spacing: 12) {
GlassCompass(heading: heading, size: .large) {
heading = 0
resetCount += 1
}
GlassCompass(heading: heading) { heading = 0 }
GlassCompass(heading: heading, size: .small) { heading = 0 }
GlassCompass(heading: nil) {}
}
.padding()
}
Slider(value: $heading, in: 0...359, step: 1) { Text("Heading") }
.padding(.horizontal)
Text("Heading \(Int(heading))° · reset to north \(resetCount) times · the last compass has no heading")
.font(.caption)
.foregroundStyle(.secondary)
.padding(.horizontal)
}
.padding(.bottom)
}
}
#Preview("GlassCompass") { GlassCompassExample().glassTheme(.crystal) }
Registry entry
| Identifier | glass-compass |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation, glass-icon-button, glass-maps-support |
| Frameworks | SwiftUI |
| Public symbols | GlassCompass, GlassCompassSymbols |
| Licence | MIT |
| Manifest | manifest.json |
Files
Maps/Maps/GlassCompass.swift7174 bytes · sha256 8e04f7d98d9f…