Skip to content

Commit

Permalink
Improve robustness to future failure cases; ensure no unnecessary upd…
Browse files Browse the repository at this point in the history
…ates
  • Loading branch information
ianthetechie committed Apr 16, 2024
1 parent 1cb4ef0 commit f6b8b09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 0 additions & 7 deletions Sources/MapLibreSwiftUI/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ public struct MapView: UIViewRepresentable {
public func updateUIView(_ mapView: MLNMapView, context: Context) {
context.coordinator.parent = self

switch styleSource {
case let .url(styleURL):
if styleURL != mapView.styleURL {
mapView.styleURL = styleURL
}
}

applyModifiers(mapView, runUnsafe: true)

// FIXME: This should be a more selective update
Expand Down
7 changes: 6 additions & 1 deletion Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class MapViewCoordinator: NSObject {
// every update cycle so we can avoid unnecessary updates
private var snapshotUserLayers: [StyleLayerDefinition] = []
private var snapshotCamera: MapViewCamera?
private var snapshotStyleSource: MapStyleSource?

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

@MainActor func updateStyleSource(_ source: MapStyleSource, mapView: MLNMapView) {
switch (source, parent.styleSource) {
switch (source, snapshotStyleSource) {
case let (.url(newURL), .url(oldURL)):
if newURL != oldURL {
mapView.styleURL = newURL
}
case let (.url(newURL), .none):
mapView.styleURL = newURL
}

snapshotStyleSource = source
}

@MainActor func updateLayers(mapView: MLNMapView) {
Expand Down

0 comments on commit f6b8b09

Please sign in to comment.