SP GlassKit1.1.0

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.

GlassCompass running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-compass

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-compass
ModuleSPGlassMaps
Kindcustom-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
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Maps/GlassCompassExample.swift

Minimal usage

Swift
GlassCompass(heading: mapHeading) { mapHeading = 0 }

Variants

VariantUse
heading: DoubleThe needle points north for a map rotated by that heading.
heading: nilHeading unavailable: outlined, dimmed needle; the button is disabled.
size:.small, .regular, .large.

Parameters

ParameterTypeDefaultMeaning
headingDouble?—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.
sizeGlassControlSize.regularSize 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 destructive colour (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

Swift
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 heading starts a short animation; an engine that reports the heading on every frame of a gesture should round it or throttle it.

Example

Complete example (compiled with the package)
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

Identifierglass-compass
Version1.1.0
Depends onglass-foundation, glass-icon-button, glass-maps-support
FrameworksSwiftUI
Public symbolsGlassCompass, GlassCompassSymbols
LicenceMIT
Manifestmanifest.json

Files