mapbox / mapbox/mapbox-maps-ios
Can't animate moving `MapViewAnnotation`
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
## Observed behavior and steps to reproduce
Changing the `coordinate` of a `MapViewAnnotation` via `withAnimation` causes the view to **re-appear** instead of **moving** to the new location.
```swift
import SwiftUI
@_spi(Experimental) import MapboxMaps
struct MapboxMapView: View {
private let position = Viewport.camera(
center: .londonA,
zoom: 16
)
@State var curLocation: CLLocationCoordinate2D = .londonA
var body: some View {
Map(initialViewport: position) {
MapViewAnnotation(coordinate: curLocation) {
Circle()
}
}
.ignoresSafeArea()
.overlay(alignment: . bottomTrailing) {
Button("Change location") {
withAnimation {
curLocation = .londonB // SHOULD CAUSE THE ANNOTATION TO MOVE, NOT RE-APPEAR
}
}
}
}
}
extension CLLocationCoordinate2D {
static let londonA = CLLocationCoordinate2D(
latitude: 51.507222,
longitude: -0.1275
)
static let londonB = CLLocationCoordinate2D(
latitude: 51.508222,
longitude: -0.1276
)
}
```
## Expected behavior
The annotation should **move** to the new location.
## Notes / preliminary analysis
Seems to have been possible in [UIKit examples](https://github.com/mapbox/mapbox-maps-ios/blob/9dafb886f53d01753ee08cbaba2011b6612fa37f/Apps/Examples/Examples/All%20Examples/Annotations/ViewAnnotationAnimationExample.swift#L98) but the behavior seems different in SwiftUI.
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 by running the SwiftUI reproduction with MapViewAnnotation and compare its behavior with the UIKit ViewAnnotationAnimationExample linked in the issue. Trace how the SwiftUI annotation responds to coordinate changes under withAnimation; done means the annotation moves smoothly to londonB rather than disappearing and reappearing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100