Skip to content

Route preview and turn-by-turn UI in the same view? #4031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sundeepgupta opened this issue Jul 26, 2022 · 11 comments
Closed

Route preview and turn-by-turn UI in the same view? #4031

sundeepgupta opened this issue Jul 26, 2022 · 11 comments
Assignees
Labels
question Need advice or clarification.

Comments

@sundeepgupta
Copy link

sundeepgupta commented Jul 26, 2022

Hi there, I've been looking at how things are done and it seems that the route preview needs to be shown in a NavigationMapView, but then the navigation is done by presenting/pushing/embedding a NavigationViewController - which also has its own NavigationMapView.

I haven't seen any docs/examples where the same NavigationMapView is used. Is there a reason for this? Did I miss something in the docs? Is it possible to use the same view for both - perhaps with NavigationViewController?

One thing I see is that navigation is started when NavigationViewController loads:

// Start the navigation service on presentation.
navigationService.start()

@MaximAlien MaximAlien added the question Need advice or clarification. label Jul 26, 2022
@MaximAlien
Copy link
Contributor

@sundeepgupta, that's correct, one clarification regarding NavigationViewController case is that internally it uses NavigationView, that actually contains NavigationMapView. NavigationView adds some more UI on top: top and bottom banner containers , floating buttons, speed limit and road name label. #4017 added that ability to access some of NavigationView APIs via NavigationViewController (not in GA yet). I think that you can use it independently as well.

Speaking of MapboxNavigationService usage with NavigationMapView: it's possible, to use it outside of NavigationViewController but we do not have public docs for this at this point (I'll create a ticket to document it). You can check our internal example as a reference.

Regarding NavigationMapView re-usage between preview and active navigation state: it's also possible (with some caveats). There is NavigationOptions.navigationMapView property, you can assign your current NavigationMapView instance there, it'll then be used by NavigationViewController. Beware that NavigationViewController will apply several changes to that NavigationMapView (NavigationCamera will be switched to .following state etc), that will not be reverted when dismissing NavigationViewController, so at this point end user is responsible for this (e.g. setting gesture recognizers, changing MapView style etc).

In #4022 we try to improve these transitions and then document them, but at this point such functionality is not released yet.

@MaximAlien MaximAlien self-assigned this Jul 26, 2022
@MaximAlien
Copy link
Contributor

So in short here're some configurations you can have:

  • Preview in NavigationMapView - active navigation in NavigationViewController.
  • Preview in NavigationMapView - active navigation in NavigationViewController with NavigationMapView instance re-usage from preview state. See NavigationOptions.navigationMapView.
  • Preview and active navigation in NavigationMapView. See example.
  • Preview and active navigation with NavigationView. Will be available in v2.7.

@sundeepgupta
Copy link
Author

Thanks for the comprehensive answer. Based on what you say, would you agree that the more advisable route is to use the first configuration if there's not too much customization needed:

  • Preview in NavigationMapView - active navigation in NavigationViewController

If so, I'd want make it look like everything is being done in a single view, so I'd want to embed the NavigationViewController into the VC holding the original NavigationMapView with the route preview and show/hide preview and navigation.

When the navigation is in progress, and the user wants to pause/stop the navigation, I'd want to show an updated route preview. Is there a way to update the route preview automatically? Or would a new Directions.shared.calculate call be needed in this case? Or is there a way to do this more simply via NavigationViewController. I see NavigationCameraState.following and .overview, but don't see how to set this explicitly.

@MaximAlien
Copy link
Contributor

@sundeepgupta, guide for navigation camera APIs can be found here. Basically everything related to work with navigation camera is done via NavigationMapView.navigationCamera property.

Speaking of preferred presentation choice: it depends on your application features and how you want to extend certain functionality in future. Preview in NavigationMapView - active navigation in NavigationViewController approach is the most popular one and we showcase it in our examples, but there is more work to do if you want a seamless transition. We actually try to improve this part by refining our APIs. You can look at #4022 as a reference.

I'd want to show an updated route preview. Is there a way to update the route preview automatically? Or would a new Directions.shared.calculate call be needed in this case?

Depends on a level of changes that were made to the route line during active navigation. If a lot of changes were made to the MapView style we cannot guarantee it, if a route line was simply shown without major changes you can directly access NavigationMapView APIs to present original route line using NavigationMapView.showcase(_:routesPresentationStyle:animated:) or NavigationMapView.show(_:layerPosition:legIndex:) after dismissing NavigationViewController.

@sundeepgupta
Copy link
Author

Thank you, I will look into those things you mention.

@sundeepgupta
Copy link
Author

sundeepgupta commented Jul 27, 2022

@MaximAlien, #4022 is what we're after and I see there are changes required to the SDK. I'm trying to decide if we should

  1. Wait for GA release.
  2. Wait for Beta release.
  3. Wait for the PR to merge.
  4. Consume the PR branch/code via fork.

Can you share any ETAs on the first three options?

@MaximAlien
Copy link
Contributor

Hello @sundeepgupta, please see my answers:

  1. Add custom NavigationViewController transitions. #4022 will be available in v2.7.0 GA (will be released in three weeks, during a week of August 15th).
  2. v2.7.0-beta.3 will be available this week, possibly tomorrow, or on Friday. It'll contain this PR.
  3. I'll merge this PR today, beware that this is not a "final look" of the APIs, we will do some testing to make a decision, also even though some APIs were made public, they're undocumented yet. I'd also like to note that there is quite some work to be done on a client side (presentation and dismissal transitions should be implemented by the client). I've also noticed some issues here and there, I'll be addressing them in further releases.

After releasing GA we plan to create several examples to showcase such functionality in mapbox/mapbox-navigation-ios-examples#171 and mapbox/mapbox-navigation-ios-examples#170.

@sundeepgupta
Copy link
Author

Thanks @MaximAlien those timelines will be helpful for us.

Can you elaborate on:

I've also noticed some issues here and there

@MaximAlien
Copy link
Contributor

I've also noticed some issues here and there

It'll depend on the level of complexity of your app, but if you heavily modify NavigationMapView you have to remember to revert all previous modifications (e.g. I've noticed that gesture recognizers might not work, if NavigationViewController.routeLineTracksTraversal is set to true after dismissal route line might end up trimmed, route duration annotations will have to be removed (shown via NavigationMapView.showRouteDurations(along:)) etc).

@sundeepgupta
Copy link
Author

Ok I see. thank you.

@samuelalake
Copy link

After releasing GA we plan to create several examples to showcase such functionality in mapbox/mapbox-navigation-ios-examples#171 and mapbox/mapbox-navigation-ios-examples#170.

Hey @MaximAlien , do you know if these examples are released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Need advice or clarification.
Projects
None yet
Development

No branches or pull requests

3 participants