Skip to content

Commit

Permalink
Add option to toggle voice instructions. (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoachimAmoah committed Sep 27, 2021
1 parent 2909bc4 commit 3c0088f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@ class MapboxNavigationManager(var mCallerContext: ReactApplicationContext) : Sim
fun setShowsEndOfRouteFeedback(view: MapboxNavigationView, showsEndOfRouteFeedback: Boolean) {
view.setShowsEndOfRouteFeedback(showsEndOfRouteFeedback)
}
}

@ReactProp(name = "mute")
fun setMute(view: MapboxNavigationView, mute: Boolean) {
val isMuted = view.isVoiceGuidanceMuted()
if (mute != isMuted) {
view.toggleMute()
}
view.setMute(mute)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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()
}
}
}
1 change: 1 addition & 0 deletions dist/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ export interface IMapboxNavigationProps {
onArrive?: () => void;
showsEndOfRouteFeedback?: boolean;
hideStatusView?: boolean;
mute?: boolean;
}
export {};
1 change: 1 addition & 0 deletions ios/MapboxNavigationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions ios/MapboxNavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ export interface IMapboxNavigationProps {
onArrive?: () => void;
showsEndOfRouteFeedback?: boolean;
hideStatusView?: boolean;
mute?: boolean;
}

0 comments on commit 3c0088f

Please sign in to comment.