mapbox / mapbox/mapbox-navigation-ios
Unexpected safe area insets on CarPlayNavigationViewController
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 918
- Forks
- 326
- Avg merge
- 1h 16m
- Merged PRs (30d)
- 3
Description
### Mapbox Navigation SDK version
2.13.0 and 2.11.0
### Steps to reproduce
Hello! I'm using Xcode 14.3.1 with an iOS 16.4 simulator. I've also seen this issue on a physical device.
1. Run the Example-CarPlay project.
2. Disable route simulation.
3. Set the simulator on the "Freeway Drive" location.
4. Drop a pin anywhere and start navigation with a CarPlay window active.
5. Occasionally tap the map to open the navigation bar and/or open the feedback UI.
Keep an eye on the current street label and camera's position relative to the user puck.
https://github.com/mapbox/mapbox-navigation-ios/assets/1591735/78f6ea63-c79e-4b12-8ffc-4f3d2f275d6d
### Expected behavior
The leading and trailing safe area insets stay consistent and don't briefly change values.
### Actual behavior
Every so often, the CarPlayNavigationViewController's `viewSafeAreaInsetsDidChange` gets called with incorrect/unexpected insets that don't account for the necessary horizontal safe areas of the CarPlay window. When this happens, the map's camera will center the puck on the whole screen, causing it to partially draw under the maneuver UI. The current street label will also draw underneath the maneuver UI.
This seems to arise more frequently when the navigation bar is presented after tapping on the screen or after dismissing the feedback UI. After a moment, `viewSafeAreaInsetsDidChange` will be called with the expected values and the UI will correct itself.
I'm not sure if this is something related to the SDK itself, or if this is a bug within Apple's CarPlay framework. I'm curious if anyone has leads. _I've seen this issue within the Mapbox Navigation SDK inside my own CarPlay app as well, which does not have a feedback button and instead displays a pan button at that position._
---
I've been able to capture the bug in logs by inserting one print statement in CarPlayNavigationViewController:
```Swift
public override func viewSafeAreaInsetsDidChange() {
... ...
print("Safe area insets did change \(view.safeAreaInsets)")
}
```
Using the default CarPlay simulator size:
- when the UI is acting as expected, the edge insets looks like `UIEdgeInsets(top: 44.0, left: 195.0, bottom: 0.0, right: 38.0)`
- when the bug arises, the insets change to `UIEdgeInsets(top: 44.0, left: 45.0, bottom: 0.0, right: 0.0)`.
You can see the horizontal safe area is incorrect, particularly on the left side. Thank you for the assistance!
### Is this a one-time issue or a repeatable issue?
repeatable
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Example-CarPlay project and CarPlayNavigationViewController, focusing on viewSafeAreaInsetsDidChange. Reproduce the issue with route simulation disabled and inspect the logged safe area values when presenting the navigation bar or dismissing feedback UI. Done means the horizontal insets remain correct and the map camera, maneuver UI, and current street label no longer overlap.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100