From 249d977884b948c88e46f02412dedaa83490409d Mon Sep 17 00:00:00 2001 From: Marek Sabol Date: Sat, 12 Oct 2024 17:48:06 +0200 Subject: [PATCH] ios mute button --- apple/DemoApp/Demo/DemoNavigationView.swift | 24 +++++++++++++-- apple/DemoApp/Demo/MuteButtonView.swift | 34 +++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 apple/DemoApp/Demo/MuteButtonView.swift diff --git a/apple/DemoApp/Demo/DemoNavigationView.swift b/apple/DemoApp/Demo/DemoNavigationView.swift index 4c78e220..d396533d 100644 --- a/apple/DemoApp/Demo/DemoNavigationView.swift +++ b/apple/DemoApp/Demo/DemoNavigationView.swift @@ -13,10 +13,10 @@ private let initialLocation = CLLocation(latitude: 37.332726, longitude: -122.031790) struct DemoNavigationView: View { - private let navigationDelegate = NavigationDelegate() + private var navigationDelegate = NavigationDelegate() // NOTE: This is probably not ideal but works for demo purposes. // This causes a thread performance checker warning log. - private let spokenInstructionObserver = AVSpeechSpokenInstructionObserver(isMuted: false) + @State private var spokenInstructionObserver = AVSpeechSpokenInstructionObserver(isMuted: false) private var locationProvider: LocationProviding @ObservedObject private var ferrostarCore: FerrostarCore @@ -34,6 +34,7 @@ struct DemoNavigationView: View { @State private var camera: MapViewCamera = .center(initialLocation.coordinate, zoom: 14) @State private var snappedCamera = true + @State private var isNavigationActive = false // New state variable for navigation status init() { let simulated = SimulatedLocationProvider(location: initialLocation) @@ -121,6 +122,7 @@ struct DemoNavigationView: View { isFetchingRoutes = true try await startNavigation() isFetchingRoutes = false + isNavigationActive = true // Set to true when navigation starts } catch { isFetchingRoutes = false errorMessage = "\(error.localizedDescription)" @@ -148,6 +150,23 @@ struct DemoNavigationView: View { .task { await getRoutes() } + .overlay( + + HStack { + + Spacer() + + if isNavigationActive { + + MuteButton(isMuted: $spokenInstructionObserver.isMuted) + + } + + }, + + alignment: .topTrailing + + ) } } @@ -209,6 +228,7 @@ struct DemoNavigationView: View { ferrostarCore.stopNavigation() camera = .center(initialLocation.coordinate, zoom: 14) allowAutoLock() + isNavigationActive = false } var locationLabel: String { diff --git a/apple/DemoApp/Demo/MuteButtonView.swift b/apple/DemoApp/Demo/MuteButtonView.swift new file mode 100644 index 00000000..887758c6 --- /dev/null +++ b/apple/DemoApp/Demo/MuteButtonView.swift @@ -0,0 +1,34 @@ +// +// MuteButton.swift +// Ferrostar Demo +// +// Created by Marek Sabol on 08/10/2024. +// + +import SwiftUI + +struct MuteButton: View { + @Binding var isMuted: Bool + + var body: some View { + Button(action: { + isMuted.toggle() + }) { + Image(systemName: isMuted ? "speaker.slash.fill" : "speaker.2.fill") + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: 18, height: 18) + .padding() + .foregroundColor(.black) + .background(Color.white) + .clipShape(Circle()) + .shadow(radius: 10) + } + .padding(.trailing, 18) // Right + .padding(.top, 112) + } +} + +#Preview { + MuteButton(isMuted: .constant(false)) +}