When changing device settings between light mode and dark mode my Google Maps mapStyle is not updating. The other views successfully toggle to the selected mode, it's just the map that doesn't change.
The mapStyle does change correctly when my app is restarted.
struct MapView: UIViewRepresentable {
@Environment(\.colorScheme) var colorScheme
private let mapView = GMSMapView(frame: .zero)
private let defaultZoomLevel: Float = 10
func makeUIView(context: Context) -> GMSMapView {
mapView.delegate = context.coordinator
applyColorSchemeToMap()
return mapView
}
func updateUIView(_ mapView: GMSMapView, context: Context) {
applyColorSchemeToMap()
}
func applyColorSchemeToMap() {
do {
if let styleURL = Bundle.main.url(forResource: colorScheme == .dark ? "night_map_style" : "map_style", withExtension: "json") {
mapView.mapStyle = try GMSMapStyle(contentsOfFileURL: styleURL)
} else {
NSLog("Unable to find style.json")
}
} catch {
NSLog("One or more of the map styles failed to load. \(error)")
}
}