Repository Public MIT
1import SwiftUI2import SPGlassKit34public struct GlassLocationButtonExample: GlassExample {5 public static let componentID = "glass-location-button"6 /// The example plays the host's role with a simulated state: no permission is requested, no position is read.7 @State private var state = GlassLocationState.idle8 @State private var message = "Sample data · simulated states, no location access"910 public init() {}1112 public var body: some View {13 VStack(spacing: 16) {14 SampleMapBackdrop()15 .overlay(alignment: .bottomTrailing) {16 GlassLocationButton(state: state, hint: hint) { advance() }17 .padding()18 }19 Picker("Simulated state", selection: $state) {20 ForEach(GlassLocationState.allCases, id: \.self) { state in21 Text(GlassLocationPresentation(state).label).tag(state)22 }23 }24 .padding(.horizontal)25 HStack(spacing: 12) {26 ForEach(GlassLocationState.allCases, id: \.self) { state in27 GlassLocationButton(state: state, size: .small) {}28 }29 }30 Text(message)31 .font(.caption)32 .foregroundStyle(.secondary)33 .padding(.horizontal)34 }35 .padding(.bottom)36 }3738 private var hint: String? {39 switch state {40 case .denied: "Location access was refused. Activating the button would open Settings in a real application."41 case .unavailable: "Location services are off on this device."42 default: nil43 }44 }4546 /// What a host might do on a tap, simulated.47 private func advance() {48 switch state {49 case .idle:50 state = .locating51 message = "The host would start location updates here."52 case .locating:53 state = .following54 message = "A position arrived: the map follows it."55 case .following:56 state = .idle57 message = "Following stopped."58 case .denied:59 message = "The host would open Settings here."60 case .unavailable:61 break62 }63 }64}6566#Preview("GlassLocationButton") { GlassLocationButtonExample().glassTheme(.emerald) }67