mapbox / mapbox/mapbox-maps-swiftui-demo
Annotations won't update if there is another @State var on the UI
- Dominant language
- Swift
- Stars
- 29
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Description
Hi @fabian-guerra!
Can you please clarify something:
Mapbox stops updating (calling ```func updateUIView()```) when for any new added annotation when a ```Text("\(annotations.count)")``` is added above the MapView() call like bellow:
```
VStack {
Text("\(annotations.count)")
MapView(annotations: $annotations).centerCoordinate(.init(latitude: 37.791293, longitude: -122.396324)).zoomLevel(16)
Button(action: {
self.annotations.append( MGLPointAnnotation(title: "Mapbox 1", coordinate: .init(latitude: 37.791400, longitude: -122.396200)))
}) {
Text("Add annotation")
}
...
}
```
Does this have to do with the SwiftUI propagation and new UI update pattern? Or am I doing something wrong?
Thanks for any insights (or for pointing out what I am doing wrong).
Best regards,
ps.: I commented this problem here https://github.com/mapbox/mapbox-maps-swiftui-demo/issues/3#issuecomment-600902173
Contributor guide
Research direction
Start by reproducing the reported VStack with Text("\(annotations.count)"), MapView(annotations: $annotations), and the Add annotation button. Inspect the MapView updateUIView path and SwiftUI state propagation, then determine whether newly appended annotations update as expected and document the cause or required change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100