Skip to content

RouteResponse usage refactoring#3182

Merged
Udumft merged 12 commits into
mainfrom
vk/2589-route-response-refactor
Aug 4, 2021
Merged

RouteResponse usage refactoring#3182
Udumft merged 12 commits into
mainfrom
vk/2589-route-response-refactor

Conversation

@Udumft
Copy link
Copy Markdown
Contributor

@Udumft Udumft commented Jul 16, 2021

Description

This PR replaces usage of Route + Route index in favor of it's original RouteResponse. It also removes usage of Route.routeIdentifier, as this is a redundant property should be removed too.

Implementation

Most of the changes is just a replacing of IndexedRoute with RouteResponse. But it also forced updating some related entities like CPTrip.userInfo, removing RouteProgress.routeIndex or updating SessionStatewith dedicatedrouteIdentifier`. There are many public API changes.

@Udumft Udumft added op-ex Refactoring, Tech Debt or any other operational excellence work. backwards incompatible changes that break backwards compatibility of public API labels Jul 16, 2021
@Udumft Udumft added this to the v2.0.0 (RC) milestone Jul 16, 2021
@Udumft Udumft self-assigned this Jul 16, 2021
@Udumft Udumft marked this pull request as ready for review July 16, 2021 12:06
@Udumft Udumft requested a review from a team July 16, 2021 12:06
@S2Ler
Copy link
Copy Markdown
Contributor

S2Ler commented Jul 19, 2021

This PR will clash with #3159

Comment thread Sources/MapboxCoreNavigation/Router.swift Outdated
@Udumft Udumft force-pushed the vk/2589-route-response-refactor branch 3 times, most recently from 6ef05e4 to 8b8a416 Compare July 21, 2021 09:05
@Udumft Udumft requested review from a team and S2Ler July 21, 2021 09:14
Comment thread CHANGELOG.md Outdated
Comment thread Sources/MapboxNavigation/CarPlayManagerDelegate.swift Outdated
Comment thread Sources/MapboxCoreNavigation/NavigationService.swift Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2589 mentions:

A convenience initializer for MapboxNavigationService can wrap a Route in a RouteResponse, and a convenience initializer for NavigationViewController can wrap a Route in a RouteResponse and MapboxNavigationService.

Shall we add these convenience inits in this PR? Or what's the reason of not including them?

Copy link
Copy Markdown
Contributor Author

@Udumft Udumft Jul 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My motivation not to add these was that all of the routes are supposed to be a result of API calling, and thus are always wrapped in RouteResponse. If, for some uncommon reason, user is creating a Route object differently, he should take care about correctly wrapping it, providing other required fields like options and identifier.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Udumft ,

I have a use case in which I would prefer injecting a Route and am wondering if I now need to create a convenience init to support? It seems strange to move from a strong required Route, to a model of optionals?

https://github.com/mapbox/straightaway-ios/blob/main/Straightaway/Modules/Map/ContinuousNavigationViewController.swift#L85

Given our UI/ViewModels are intentionally separate from network models, exposing a network response object seemed heavy.

For additional context, in an upcoming feature change, we will be displaying multiple direction options. Which we will display, and begin navigation upon selection of a given route.

cc: @irtemed88

Copy link
Copy Markdown

@dmiluski dmiluski Aug 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Udumft ,

I was seeing if I could get your suggestion for how I could approach this? I took a first stab at the upgrade migration.

Comment thread Example/CustomViewController.swift Outdated
Comment thread Sources/MapboxCoreNavigation/RouteProgress.swift Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code was added to support Storyboards. @MaximAlien please review.

Comment thread Sources/MapboxCoreNavigation/NavigationService.swift Outdated
@S2Ler S2Ler requested a review from 1ec5 July 22, 2021 09:52
@S2Ler
Copy link
Copy Markdown
Contributor

S2Ler commented Jul 22, 2021

@1ec5 Your review is required since you created the original ticket.

@jill-cardamon jill-cardamon force-pushed the vk/2589-route-response-refactor branch from 8b8a416 to 4ac8389 Compare July 23, 2021 00:28
@Udumft Udumft requested review from a team and S2Ler July 23, 2021 09:18
@S2Ler S2Ler requested a review from MaximAlien July 23, 2021 09:19
Copy link
Copy Markdown
Contributor

@S2Ler S2Ler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the following should be done before merge:

  • Verify that Storyboards integration isn't broken cc @MaximAlien
  • Review from @1ec5

Comment thread CHANGELOG.md Outdated
Comment on lines +19 to +26
public let routeResponse: RouteResponse
public let routeIndex: Int
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to add documentation comments about these properties and also the initializer below so that jazzy recognizes them.

Comment thread Sources/MapboxCoreNavigation/Router.swift Outdated
/// The `RouteResponse` containing the route along which the user is expected to travel, plus its index in this `RouteResponse`, if applicable.
///
/// If you want to update the route use `Router.updateRoute(with:routeOptions:)` method.
var indexedRouteResponse: IndexedRouteResponse { get }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it isn’t valid to set indexedRouteResponse directly, let’s make it publicly read-only.

Comment thread Sources/MapboxCoreNavigation/Router.swift Outdated
Comment thread Sources/MapboxNavigation/CPTrip.swift Outdated
Comment thread Sources/MapboxCoreNavigation/NavigationService.swift
Comment thread Sources/MapboxNavigation/NavigationViewController.swift Outdated
@1ec5 1ec5 linked an issue Jul 23, 2021 that may be closed by this pull request
2 tasks
Copy link
Copy Markdown
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meant to attach this approval to #3182 (review):

I think it would be quite beneficial to remove some redundancy in a subsequent PR, now that RouteResponse encapsulates more information, but this PR is mergeable as is once the few bits of missing documentation are added.

Copy link
Copy Markdown
Contributor

@MaximAlien MaximAlien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR brings quite a lot of public API changes. We'll need to create another PR in https://github.com/mapbox/mapbox-navigation-ios-examples to address compilation issues.

/**
A `Route` object constructed by [MapboxDirections](https://docs.mapbox.com/ios/api/directions/).
*/
public var route: Route? {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why NavigationViewController.route, NavigationViewController.routeIndex and NavigationViewController.routeOptions were converted to get-only properties? At this point it breaks functionality, which allows to create NavigationViewController instance via UIStoryboard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These properties were made read-only to introduce single entry-point method for changing the route: updateRoute(with:routeOptions:). Not sure what to do with storyboard scenario...

Copy link
Copy Markdown
Contributor

@1ec5 1ec5 Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3159 was primarily concerned with changing the route during a trip, but the storyboard code path is about setting up the trip in the first place, at a point when we’re not as concerned about the navigator getting only piecemeal input. Can we introduce something specific to storyboards, perhaps even with “forStoryboard” in the name?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to have a special method which setups vc after view controller. This method will set appropriate private variables (could be even grouped in a struct) which will be read in the code which setups vc in storyboards case.

When I read this code I found it confusing why route variable has such strange get/set.

Comment thread Tests/CocoaPodsTest/PodInstall/Podfile.lock Outdated
@MaximAlien
Copy link
Copy Markdown
Contributor

We'll have to also revise documentation after landing current PR: e.g. in https://docs.mapbox.com/ios/beta/navigation NavigationViewController and related APIs are mentioned quite often.

@Udumft Udumft force-pushed the vk/2589-route-response-refactor branch from 95c2db9 to 0849319 Compare July 26, 2021 16:41
@Udumft Udumft requested review from MaximAlien and S2Ler July 27, 2021 12:08
@Udumft Udumft force-pushed the vk/2589-route-response-refactor branch from b0575c3 to 164a251 Compare August 2, 2021 14:57
Comment thread Sources/MapboxNavigation/NavigationViewController.swift Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to perform check to see if view was really loaded? I recall that in previous implementation in #2974 it wasn't needed. Just want to make sure that this will not cause any side effects.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is added since updating routeResponse, routeIndex or routeOptions will not have effect on the contents NavigationViewController if view is already loaded. In this case view - is the Navigation View, and these properties are only stored in NavigationViewController to initialize the NavigationView. So, this check lets user know if this update actually happened or not. Previous implementation did silent update of a local property, but that did not affect the NavigationView if it was already loaded.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be great to create a follow-up ticket to update documentation everywhere. In scope of this PR files like README.md and cover.md can be updated as they show how to use NavigationViewController.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that, thanks

@Udumft Udumft force-pushed the vk/2589-route-response-refactor branch from ab51a6d to fae8fd7 Compare August 3, 2021 14:51
Copy link
Copy Markdown
Contributor

@MaximAlien MaximAlien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes so many public APIs that it's hard to see what can be wrong. On high level seems to look good to me. We should review all docs and update examples to make sure that there is not major regression and everything is up-to-date.

Comment thread Sources/MapboxCoreNavigation/RouteProgress.swift
@Udumft
Copy link
Copy Markdown
Contributor Author

Udumft commented Aug 4, 2021

Ticket to update examples project : mapbox/mapbox-navigation-ios-examples/issues/135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backwards incompatible changes that break backwards compatibility of public API op-ex Refactoring, Tech Debt or any other operational excellence work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace Route with RouteResponse plus route index

5 participants