Skip to content

Navigator Tiles management#2823

Merged
MaximAlien merged 9 commits into
release-v2.0from
vk/430-tile-manager
Mar 2, 2021
Merged

Navigator Tiles management#2823
MaximAlien merged 9 commits into
release-v2.0from
vk/430-tile-manager

Conversation

@Udumft
Copy link
Copy Markdown
Contributor

@Udumft Udumft commented Feb 22, 2021

This PR solves Navigator instance management by introducing single entry point and sharing existing instances. It also ensures that all Navigators are properly configured when initialized.

@Udumft Udumft added op-ex Refactoring, Tech Debt or any other operational excellence work. ✓ ready for review labels Feb 22, 2021
@Udumft Udumft requested a review from a team February 22, 2021 14:06
@Udumft Udumft self-assigned this Feb 22, 2021
@1ec5 1ec5 added this to the v2.0.0 (Public Preview) milestone Feb 23, 2021
Comment thread CHANGELOG.md Outdated
Comment thread Sources/MapboxCoreNavigation/NavigatorProvider.swift Outdated
Comment thread Sources/MapboxCoreNavigation/NavigatorProvider.swift Outdated
tilesConfig: TilesConfig())

self.systemLocationManager = systemLocationManager ?? NavigationLocationManager()
self.navigatorWithHistory = NavigatorProvider.sharedWeakNavigator()
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.

For clarity, can we rename NavigatorProvider to Navigator, rename NavigatorProvider.sharedWeakNavigator() to a computed variable called Navigator.shared that returns an instance of Navigator, and fold NavigatorWithHistory’s members into Navigator? Basically, Navigator would be a public SDK wrapper for the Navigator (and HistoryRecorder) provided by MapboxNavigationNative. I don’t think we’d need a separate factory class to vend the singleton.

(By the way, this Navigator wrapper idea was why we originally created the Router protocol. But that protocol would need some cleanup to be relevant here.)

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.

@1ec5, Navigator shared instance logic is now part of Navigator.swift extension. Navigator.shared, Navigator.tilesVersion, Navigator.tilesURL, Navigator.enableHistoryRecorder(), Navigator.disableHistoryRecorder(), Navigator.history() is exposed to outer world. Please let me know what you think.

/**
Creates a cache for tiles of the given version and configures the navigator to use this cache.
*/
func configureNavigator(withTilesVersion tilesVersion: String) throws {
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.

The original idea was to defer the navigator’s creation and configuration until the map SDK starts consuming location updates from PassiveLocationManager. Now that configuration happens earlier when attaching the PassiveLocationManager to the MapView. The nice thing about waiting until startUpdatingLocation() is that we could make it completely asynchronous without having to synchronize within a factory method.

Comment thread Sources/MapboxCoreNavigation/NavigatorProvider.swift Outdated
@1ec5 1ec5 mentioned this pull request Feb 26, 2021
@MaximAlien
Copy link
Copy Markdown
Contributor

@1ec5, can you please give it another pass. After adding proposed changes passive/active navigation seems to be working fine, but it'd be good to add some unit-tests (I think this is currently blocked).

Provides a new or an existing one `Navigator` instance along with related `HistoryRecorderHandle`,
satisfying provided configuration (`tilesVersion` and `tilesURL`).
*/
private static let navigatorWithHistoryRecorder: (Navigator, HistoryRecorderHandle) = {
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 hope that tuple usage is fine in this case. Not sure it's worth creating another entity for this similar to NavigatorWithHistory.

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.

5ac8c9a for #2808 defines a similar struct, NavigatorResources, which is more flexible than a tuple. I think that flexibility will be necessary for #2834.

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.

Tuple is no longer relevant after adding CoreNavigationNavigator.swift (btw feel free to propose better naming if you have any ideas). Shall I remove NavigatorResources in scope of this PR? As I can see it's not used anywhere at the moment.

return (navigator, historyRecorder)
}()

func status(at timestamp: Date) -> NavigationStatus {
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've removed navigatorIsActive() as it wasn't used anywhere.

@MaximAlien MaximAlien force-pushed the vk/430-tile-manager branch from 95e1936 to a7e26cf Compare March 2, 2021 00:51
Comment on lines +25 to +30
/**
Shared instance on `Navigator`.
*/
static let shared: Navigator = {
return navigatorWithHistoryRecorder.0
}()
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 should’ve been clearer in #2823 (comment): the suggestion was to use composition/encapsulation rather than an extension. MapboxCoreNavigation.Navigator would be a singleton containing a MapboxNavigationNative.Navigator. This way the raw methods defined by MapboxNavigationNative won’t be exposed to the developer. It’ll also be possible to encapsulate other resources at the same time, such as HistoryRecorderHandle – obviating both the NavigationResources struct from 5ac8c9a and the (Navigator, HistoryRecorderHandle) tuple defined in this PR.

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.

Got it. Please check latest update, CoreNavigationNavigator.swift now encapsulates both HistoryRecorderHandle and MapboxNavigationNative.Navigator. Access point is possible via Navigator.shared static computed property.

Comment thread Sources/MapboxCoreNavigation/PassiveLocationDataSource.swift
Comment thread CHANGELOG.md Outdated
@MaximAlien MaximAlien merged commit b399b62 into release-v2.0 Mar 2, 2021
@MaximAlien MaximAlien deleted the vk/430-tile-manager branch March 2, 2021 21:30
@truburt truburt modified the milestones: v2.0.0 (Public Preview) (iOS), v2.0.0 (Public Preview) Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

op-ex Refactoring, Tech Debt or any other operational excellence work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants