mapbox / mapbox-maps-swiftui-demo

28 stars 15 forks source link

Annotations won't update if there is another @State var on the UI #5

Open bilics opened 4 years ago

bilics commented 4 years ago

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