Skip to content
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

Update UserCourseView instantaneously #1838

Merged
merged 4 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### CarPlay

* Fixed an issue causing `UserCourseView` to lag behind `NavigationMapView` whenever the map’s camera or content insets change significantly or when the map rotates. ([#1838](https://github.com/mapbox/mapbox-navigation-ios/pull/1838))
* Renamed `CarPlayManager(_:)` to `CarPlayManager(styles:directions:eventsManager:)` and `CarPlayNavigationViewController(with:mapTemplate:interfaceController:manager:styles:)` to `CarPlayNavigationViewController(navigationService:mapTemplate:interfaceController:manager:styles:)`. These initializers now accept an array of `Style` objects to apply throughout the CarPlay interface, similar to `NavigationViewController`. You can also change the styles at any time by setting the `CarPlayManager.styles` property. ([#1836](https://github.com/mapbox/mapbox-navigation-ios/pull/1836))
* `CarPlayManager(styles:directions:eventsManager:)` also allows you to pass in a custom `Directions` object to use when calculating routes. ([#1834](https://github.com/mapbox/mapbox-navigation-ios/pull/1834/))
* Removed the `StyleManager(_:)` initializer. After initializing a `StyleManager` object, set the `StyleManager.delegate` property to ensure that the style manager’s settings take effect. ([#1836](https://github.com/mapbox/mapbox-navigation-ios/pull/1836))
Expand Down
15 changes: 13 additions & 2 deletions MapboxNavigation/NavigationMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {
addGestureRecognizer(mapTapGesture)
}

open override func layoutMarginsDidChange() {
super.layoutMarginsDidChange()
enableFrameByFrameCourseViewTracking(for: 3)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would preferably avoid this frame by frame tracking but using updateCourseTracking(location:camera:animated:false) did not mitigate the lag/animation. cc @1ec5

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps there’s a race condition in which this method gets called before the map view updates its center coordinate to reflect the margin change, so that by the time we convert the user location to a center point within the (non)animation block, the center point still reflects the old margins.

UIView.animate(withDuration: duration, delay: 0, options: [.curveLinear, .beginFromCurrentState], animations: {
self.userCourseView?.center = self.convert(location.coordinate, toPointTo: self)
})

Temporarily enabling frame-by-frame course tracking ensures that the view moves as soon as the map adjusts to the new content insets (since that requires the map view to render another frame):

guard shouldPositionCourseViewFrameByFrame else { return }
guard let location = userLocationForCourseTracking else { return }
userCourseView?.center = convert(location.coordinate, toPointTo: self)

Temporarily reenabling frame-by-frame course tracking isn’t the end of the world, though if it really comes down to this race condition, then I’d think a shorter duration would still be sufficient to work around it.

}

//MARK: - Overrides

open override func prepareForInterfaceBuilder() {
Expand Down Expand Up @@ -389,8 +394,14 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {

if sender.state == .changed {
guard let location = userLocationForCourseTracking else { return }
userCourseView?.layer.removeAllAnimations()
userCourseView?.center = convert(location.coordinate, toPointTo: self)

if let userCourseView = userCourseView as? UserCourseView {
userCourseView.update?(location: location,
pitch: camera.pitch,
direction: direction,
animated: false,
tracksUserCourse: tracksUserCourse)
}
}
}

Expand Down