@@ -151,7 +151,11 @@ public Map<String, Object> getConstants() {
151151 }
152152
153153 @ ReactMethod
154- private void cleanup () {
154+ public void cleanup (final Promise promise ) {
155+ if (!ensureNavigatorAvailable (promise )) {
156+ return ;
157+ }
158+
155159 stopUpdatingLocation ();
156160 removeNavigationListeners ();
157161 mWaypoints .clear ();
@@ -160,10 +164,12 @@ private void cleanup() {
160164 listener .onReady (false );
161165 }
162166
167+ final Navigator navigator = mNavigator ;
163168 UiThreadUtil .runOnUiThread (
164169 () -> {
165- mNavigator .clearDestinations ();
166- mNavigator .cleanup ();
170+ navigator .clearDestinations ();
171+ navigator .cleanup ();
172+ promise .resolve (true );
167173 });
168174 }
169175
@@ -282,6 +288,10 @@ public void onError(@NavigationApi.ErrorCode int errorCode) {
282288 public void setTurnByTurnLoggingEnabled (boolean isEnabled ) {
283289 final Activity currentActivity = getReactApplicationContext ().getCurrentActivity ();
284290 if (currentActivity == null ) return ;
291+ if (mNavigator == null ) {
292+ logDebugInfo (JsErrors .NO_NAVIGATOR_ERROR_MESSAGE );
293+ return ;
294+ }
285295
286296 if (isEnabled ) {
287297 NavForwardingManager .startNavForwarding (mNavigator , currentActivity , this );
@@ -295,6 +305,9 @@ public void setTurnByTurnLoggingEnabled(boolean isEnabled) {
295305 * navigation events occur (e.g. the driver's route changes or the destination is reached).
296306 */
297307 private void registerNavigationListeners () {
308+ if (mNavigator == null ) {
309+ return ;
310+ }
298311 removeNavigationListeners ();
299312
300313 mArrivalListener =
@@ -353,6 +366,9 @@ public void onRemainingTimeOrDistanceChanged() {
353366 }
354367
355368 private void removeNavigationListeners () {
369+ if (mNavigator == null ) {
370+ return ;
371+ }
356372 if (mArrivalListener != null ) {
357373 mNavigator .removeArrivalListener (mArrivalListener );
358374 }
@@ -417,19 +433,20 @@ private void createWaypoint(Map map) {
417433 public void setDestination (
418434 ReadableMap waypoint ,
419435 @ Nullable ReadableMap routingOptions ,
420- @ Nullable ReadableMap displayOptions ) {
436+ @ Nullable ReadableMap displayOptions ,
437+ final Promise promise ) {
421438 WritableArray array = new WritableNativeArray ();
422439 array .pushMap (waypoint );
423- setDestinations (array , routingOptions , displayOptions );
440+ setDestinations (array , routingOptions , displayOptions , promise );
424441 }
425442
426443 @ ReactMethod
427444 public void setDestinations (
428445 ReadableArray waypoints ,
429446 @ Nullable ReadableMap routingOptions ,
430- @ Nullable ReadableMap displayOptions ) {
431- if ( mNavigator == null ) {
432- // TODO: HANDLE THIS
447+ @ Nullable ReadableMap displayOptions ,
448+ final Promise promise ) {
449+ if (! ensureNavigatorAvailable ( promise )) {
433450 return ;
434451 }
435452
@@ -462,42 +479,63 @@ public void setDestinations(
462479 if (pendingRoute != null ) {
463480 // Set an action to perform when a route is determined to the destination
464481 pendingRoute .setOnResultListener (
465- code -> sendCommandToReactNative ("onRouteStatusResult" , code .toString ()));
482+ code -> {
483+ sendCommandToReactNative ("onRouteStatusResult" , code .toString ());
484+ promise .resolve (true );
485+ });
486+ } else {
487+ promise .resolve (true );
466488 }
467489 }
468490
469491 @ ReactMethod
470- public void clearDestinations () {
471- if (mNavigator != null ) {
472- mWaypoints .clear (); // reset waypoints
473- mNavigator .clearDestinations ();
492+ public void clearDestinations (final Promise promise ) {
493+ if (!ensureNavigatorAvailable (promise )) {
494+ return ;
474495 }
496+ mWaypoints .clear (); // reset waypoints
497+ mNavigator .clearDestinations ();
498+ promise .resolve (true );
475499 }
476500
477501 @ ReactMethod
478- public void continueToNextDestination () {
479- if (mNavigator != null ) {
480- mNavigator . continueToNextDestination () ;
502+ public void continueToNextDestination (final Promise promise ) {
503+ if (! ensureNavigatorAvailable ( promise ) ) {
504+ return ;
481505 }
506+ mNavigator .continueToNextDestination ();
507+ promise .resolve (true );
482508 }
483509
484510 @ ReactMethod
485- public void startGuidance () {
511+ public void startGuidance (final Promise promise ) {
512+ if (!ensureNavigatorAvailable (promise )) {
513+ return ;
514+ }
486515 if (mWaypoints .isEmpty ()) {
516+ promise .reject (JsErrors .NO_DESTINATIONS_ERROR_CODE , JsErrors .NO_DESTINATIONS_ERROR_MESSAGE );
487517 return ;
488518 }
489519
490520 mNavigator .startGuidance ();
491521 sendCommandToReactNative ("onStartGuidance" , null );
522+ promise .resolve (true );
492523 }
493524
494525 @ ReactMethod
495- public void stopGuidance () {
526+ public void stopGuidance (final Promise promise ) {
527+ if (!ensureNavigatorAvailable (promise )) {
528+ return ;
529+ }
496530 mNavigator .stopGuidance ();
531+ promise .resolve (true );
497532 }
498533
499534 @ ReactMethod
500535 public void simulateLocationsAlongExistingRoute (float speedMultiplier ) {
536+ if (mNavigator == null ) {
537+ return ;
538+ }
501539 if (mWaypoints .isEmpty ()) {
502540 return ;
503541 }
@@ -510,16 +548,25 @@ public void simulateLocationsAlongExistingRoute(float speedMultiplier) {
510548
511549 @ ReactMethod
512550 public void stopLocationSimulation () {
551+ if (mNavigator == null ) {
552+ return ;
553+ }
513554 mNavigator .getSimulator ().unsetUserLocation ();
514555 }
515556
516557 @ ReactMethod
517558 public void pauseLocationSimulation () {
559+ if (mNavigator == null ) {
560+ return ;
561+ }
518562 mNavigator .getSimulator ().pause ();
519563 }
520564
521565 @ ReactMethod
522566 public void resumeLocationSimulation () {
567+ if (mNavigator == null ) {
568+ return ;
569+ }
523570 mNavigator .getSimulator ().resume ();
524571 }
525572
@@ -530,6 +577,9 @@ public void setAbnormalTerminatingReportingEnabled(boolean isOn) {
530577
531578 @ ReactMethod
532579 public void setSpeedAlertOptions (@ Nullable ReadableMap options ) {
580+ if (mNavigator == null ) {
581+ return ;
582+ }
533583 if (options == null ) {
534584 mNavigator .setSpeedAlertOptions (null );
535585 return ;
@@ -650,6 +700,14 @@ private void sendCommandToReactNative(String functionName, @Nullable Object para
650700 }
651701 }
652702
703+ private boolean ensureNavigatorAvailable (final Promise promise ) {
704+ if (mNavigator == null ) {
705+ promise .reject (JsErrors .NO_NAVIGATOR_ERROR_CODE , JsErrors .NO_NAVIGATOR_ERROR_MESSAGE );
706+ return false ;
707+ }
708+ return true ;
709+ }
710+
653711 @ ReactMethod
654712 public void simulateLocation (ReadableMap location ) {
655713 if (mNavigator != null ) {
0 commit comments