Open
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.
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 but the behavior seems different in SwiftUI.