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

Conversation

frederoni
Copy link
Contributor

@frederoni frederoni commented Nov 14, 2018

Fixes #1731

  • Update UserCourseView instantaneously when a camera change is triggered by a user interaction.
  • Update UserCourseView instantaneously when the map view’s layout margin changes.
Before After
before after
rotate_before rotate_after

cc @1ec5 @vincethecoder @JThramer

@@ -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.

Copy link
Contributor

@JThramer JThramer left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
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.

Suggested changelog entry:

Fixed an issue causing UserCourseView to lag behind NavigationMapView whenever the map’s camera or content insets change significantly.

@@ -225,6 +225,11 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {
addGestureRecognizer(mapTapGesture)
}

open override func layoutMarginsDidChange() {
super.layoutMarginsDidChange()
enableFrameByFrameCourseViewTracking(for: 3)
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.

@akitchen akitchen added this to the v0.25.0 milestone Nov 15, 2018
@JThramer JThramer merged commit 175a214 into master Nov 15, 2018
@1ec5 1ec5 deleted the fred/instant-puck-updates branch December 5, 2019 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants