Skip to content

Commit f6b8b09

Browse files
committed
Improve robustness to future failure cases; ensure no unnecessary updates
1 parent 1cb4ef0 commit f6b8b09

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

Sources/MapLibreSwiftUI/MapView.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ public struct MapView: UIViewRepresentable {
8484
public func updateUIView(_ mapView: MLNMapView, context: Context) {
8585
context.coordinator.parent = self
8686

87-
switch styleSource {
88-
case let .url(styleURL):
89-
if styleURL != mapView.styleURL {
90-
mapView.styleURL = styleURL
91-
}
92-
}
93-
9487
applyModifiers(mapView, runUnsafe: true)
9588

9689
// FIXME: This should be a more selective update

Sources/MapLibreSwiftUI/MapViewCoordinator.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class MapViewCoordinator: NSObject {
1111
// every update cycle so we can avoid unnecessary updates
1212
private var snapshotUserLayers: [StyleLayerDefinition] = []
1313
private var snapshotCamera: MapViewCamera?
14+
private var snapshotStyleSource: MapStyleSource?
1415

1516
// Indicates whether we are currently in a push-down camera update cycle.
1617
// This is necessary in order to ensure we don't keep trying to reset a state value which we were already processing
@@ -102,12 +103,16 @@ public class MapViewCoordinator: NSObject {
102103
// MARK: - Coordinator API - Styles + Layers
103104

104105
@MainActor func updateStyleSource(_ source: MapStyleSource, mapView: MLNMapView) {
105-
switch (source, parent.styleSource) {
106+
switch (source, snapshotStyleSource) {
106107
case let (.url(newURL), .url(oldURL)):
107108
if newURL != oldURL {
108109
mapView.styleURL = newURL
109110
}
111+
case let (.url(newURL), .none):
112+
mapView.styleURL = newURL
110113
}
114+
115+
snapshotStyleSource = source
111116
}
112117

113118
@MainActor func updateLayers(mapView: MLNMapView) {

0 commit comments

Comments
 (0)