diff --git a/README.md b/README.md index eb96864d..8491fc7f 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,10 @@ Boolean that controls route simulation. Set this as `true` to auto navigate whic Boolean that controls showing the end of route feedback UI when the route controller arrives at the final destination. Defaults to `false`. +#### `mute` + +Boolean that toggles voice instructions. Defaults to `false`. + #### `hideStatusView` Boolean that controls showing the `StatusView` (iOS only). This is the transparent black bar with the "Simulating Navigation" text shown in the above screenshot. Defaults to `false`. diff --git a/android/src/main/java/com/homee/mapboxnavigation/MapboxNavigationManager.kt b/android/src/main/java/com/homee/mapboxnavigation/MapboxNavigationManager.kt index 8aac0ed9..a6ab16af 100644 --- a/android/src/main/java/com/homee/mapboxnavigation/MapboxNavigationManager.kt +++ b/android/src/main/java/com/homee/mapboxnavigation/MapboxNavigationManager.kt @@ -75,4 +75,13 @@ class MapboxNavigationManager(var mCallerContext: ReactApplicationContext) : Sim fun setShowsEndOfRouteFeedback(view: MapboxNavigationView, showsEndOfRouteFeedback: Boolean) { view.setShowsEndOfRouteFeedback(showsEndOfRouteFeedback) } -} \ No newline at end of file + + @ReactProp(name = "mute") + fun setMute(view: MapboxNavigationView, mute: Boolean) { + val isMuted = view.isVoiceGuidanceMuted() + if (mute != isMuted) { + view.toggleMute() + } + view.setMute(mute) + } +} diff --git a/android/src/main/java/com/homee/mapboxnavigation/MapboxNavigationView.kt b/android/src/main/java/com/homee/mapboxnavigation/MapboxNavigationView.kt index d897037b..1db08f68 100644 --- a/android/src/main/java/com/homee/mapboxnavigation/MapboxNavigationView.kt +++ b/android/src/main/java/com/homee/mapboxnavigation/MapboxNavigationView.kt @@ -29,6 +29,7 @@ class MapboxNavigationView(private val context: ThemedReactContext) : Navigation private var destination: Point? = null private var shouldSimulateRoute = false private var showsEndOfRouteFeedback = false + private var mute = false private lateinit var navigationMapboxMap: NavigationMapboxMap private lateinit var mapboxNavigation: MapboxNavigation @@ -97,7 +98,7 @@ class MapboxNavigationView(private val context: ThemedReactContext) : Navigation .coordinates(mutableListOf(origin, destination)) .profile(RouteUrl.PROFILE_DRIVING) .steps(true) - .voiceInstructions(true) + .voiceInstructions(!this.mute) .build(), routesReqCallback) } catch (ex: Exception) { sendErrorToReact(ex.toString()) @@ -218,7 +219,11 @@ class MapboxNavigationView(private val context: ThemedReactContext) : Navigation this.showsEndOfRouteFeedback = showsEndOfRouteFeedback } + fun setMute(mute: Boolean) { + this.mute = mute + } + fun onDropViewInstance() { this.onDestroy() } -} \ No newline at end of file +} diff --git a/dist/typings.d.ts b/dist/typings.d.ts index 311684b6..fd3c038b 100644 --- a/dist/typings.d.ts +++ b/dist/typings.d.ts @@ -32,5 +32,6 @@ export interface IMapboxNavigationProps { onArrive?: () => void; showsEndOfRouteFeedback?: boolean; hideStatusView?: boolean; + mute?: boolean; } export {}; diff --git a/ios/MapboxNavigationManager.m b/ios/MapboxNavigationManager.m index 5b1d368f..7e4c8f1f 100644 --- a/ios/MapboxNavigationManager.m +++ b/ios/MapboxNavigationManager.m @@ -12,5 +12,6 @@ @interface RCT_EXTERN_MODULE(MapboxNavigationManager, RCTViewManager) RCT_EXPORT_VIEW_PROPERTY(shouldSimulateRoute, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsEndOfRouteFeedback, BOOL) RCT_EXPORT_VIEW_PROPERTY(hideStatusView, BOOL) +RCT_EXPORT_VIEW_PROPERTY(mute, BOOL) @end diff --git a/ios/MapboxNavigationView.swift b/ios/MapboxNavigationView.swift index 4e7cbbb0..2a5f4c5e 100644 --- a/ios/MapboxNavigationView.swift +++ b/ios/MapboxNavigationView.swift @@ -32,6 +32,7 @@ class MapboxNavigationView: UIView, NavigationViewControllerDelegate { @objc var shouldSimulateRoute: Bool = false @objc var showsEndOfRouteFeedback: Bool = false @objc var hideStatusView: Bool = false + @objc var mute: Bool = false @objc var onLocationChange: RCTDirectEventBlock? @objc var onRouteProgressChange: RCTDirectEventBlock? @@ -95,6 +96,8 @@ class MapboxNavigationView: UIView, NavigationViewControllerDelegate { vc.showsEndOfRouteFeedback = strongSelf.showsEndOfRouteFeedback StatusView.appearance().isHidden = strongSelf.hideStatusView + + NavigationSettings.shared.voiceMuted = strongSelf.mute; vc.delegate = strongSelf diff --git a/src/typings.ts b/src/typings.ts index 5d08394d..91c5cd0b 100644 --- a/src/typings.ts +++ b/src/typings.ts @@ -36,4 +36,5 @@ export interface IMapboxNavigationProps { onArrive?: () => void; showsEndOfRouteFeedback?: boolean; hideStatusView?: boolean; + mute?: boolean; }