Skip to content

MapContent ignores @Observable updates – not aligned with SwiftUI expectations #2354

@pjanik

Description

@pjanik

Environment

  • Xcode version: 16.4
  • iOS version: 18.6
  • Devices affected: any
  • Maps SDK Version: 11.14.0

Observed behavior and steps to reproduce

MapContent does not react to @Observable state updates. Here's the minimal test case:

@Observable
class TestViewModel {
  var pluckBearing = false
}

struct MapTestContent: MapContent {
  let viewModel: TestViewModel

  var body: some MapContent {
    if viewModel.pluckBearing {
      Puck2D(bearing: .heading)
    } else {
      Puck2D(bearing: .none)
    }
  }
}

struct MapTest: View {
  let viewModel = TestViewModel()

  var body: some View {
    VStack {
      Map {
        MapTestContent(viewModel: viewModel)
      }

      Button("Toggle Puck Bearing") {
        viewModel.pluckBearing.toggle()
      }
    }
  }
}

Tapping the button has currently no effect.

Expected behavior

Tapping the button should update pluck style. So, I'd expect MapContent get re-evaluated when @Observable state is updated.

Notes / preliminary analysis

The ability to update only the leaf nodes of the map declaration tree could lead to significant performance improvements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SwiftUIIssues and features related to SwiftUI support.bug 🪲Something is broken!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions