mapbox / mapbox/mapbox-maps-swiftui-demo

@EnvironmentObject instead of @State not working

Open
#11 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
29
Forks
13
PR merge metrics
No merged PRs in 30d

Description

I tried to use an @EnvironmentObject as Binding. It inits the map with given annotation but when the @EnvironmentObject is updated MapBox will not update the annotations.

`struct ContentView: View {
@EnvironmentObject var annotationVM: AnnotationsVM

var body: some View {
MapView(annotationsX: $annotationVM.allAnnotations).centerCoordinate(.init(latitude: 37.791293, longitude: -122.396324)).zoomLevel(16)
}
}`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ContentView example, tracing the MapView call and the AnnotationsVM.allAnnotations binding to determine why later environment-object updates do not reach the annotations. Done means MapView reflects changes to the environment object's annotations after initialization; no test file is identified in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.