homeeondemand / react-native-mapbox-navigation

A navigation UI ready to drop into your React Native application
MIT License
160 stars 122 forks source link

Can we stop the navigation manually before reaching to final destination? #34

Open MaganAnkur opened 3 years ago

rossmartin commented 3 years ago

There is not a way to stop navigation imperatively via a ref on the MapboxNavigation component. You can accomplish this currently by removing the MapboxNavigation component and mounting a new one.

thomaskbird commented 3 years ago

@rossmartin So you don't think there would be a way to utilize these methods mapbox provides? Screen Shot 2021-04-22 at 4 20 34 PM

MaganAnkur commented 3 years ago

There is not a way to stop navigation imperatively via a ref on the MapboxNavigation component. You can accomplish this currently by removing the MapboxNavigation component and mounting a new one.

Thanks @rossmartin i also noticed one thing that onCancelNavigation does not stop the navigation, can we also add this as well in enhancement please.

engelzero commented 3 years ago

To stop navigation add the following to the navigationViewControllerDidDismiss function

    navigationViewController.navigationService.stop()
    navigationViewController.dismiss(animated: true, completion: nil)
  func navigationViewControllerDidDismiss(_ navigationViewController: NavigationViewController, byCanceling canceled: Bool) {
    if (!canceled) {
      return;
    }

    // add
    navigationViewController.navigationService.stop()
    navigationViewController.dismiss(animated: true, completion: nil)

    onCancelNavigation?(["message": ""]);
  }

@MaganAnkur @rossmartin

Reference: https://github.com/mapbox/mapbox-navigation-ios/issues/2201#issuecomment-693539539

younusmahmood commented 2 years ago

Has anyone figured this out? I can't seem to get around it. Find it odd that the "x" button doesn't just stop it...