Skip to content

Commit

Permalink
Merge pull request #43 from stadiamaps/fix-camera-binding-issues
Browse files Browse the repository at this point in the history
Fix camera binding issues
  • Loading branch information
ianthetechie authored Aug 5, 2024
2 parents e958f2e + 1e6f079 commit 02f5a62
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Sources/MapLibreSwiftUI/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SwiftUI

public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentable {
public typealias UIViewControllerType = T
var cameraDisabled: Bool = true
var cameraDisabled: Bool = false

@Binding var camera: MapViewCamera

Expand All @@ -18,7 +18,7 @@ public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentab
var onStyleLoaded: ((MLNStyle) -> Void)?
var onViewPortChanged: ((MapViewPort) -> Void)?

public var mapViewContentInset: UIEdgeInsets = .zero
var mapViewContentInset: UIEdgeInsets? = .zero

var unsafeMapViewControllerModifier: ((T) -> Void)?

Expand Down Expand Up @@ -103,13 +103,16 @@ public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentab

if cameraDisabled == false {
context.coordinator.updateCamera(mapView: uiViewController.mapView,
camera: $camera.wrappedValue,
camera: camera,
animated: isStyleLoaded)
}
}

@MainActor private func applyModifiers(_ mapViewController: T, runUnsafe: Bool) {
mapViewController.mapView.contentInset = mapViewContentInset
if let mapViewContentInset {
mapViewController.mapView.automaticallyAdjustsContentInset = false
mapViewController.mapView.contentInset = mapViewContentInset
}

// Assume all controls are hidden by default (so that an empty list returns a map with no controls)
mapViewController.mapView.logoView.isHidden = true
Expand Down

0 comments on commit 02f5a62

Please sign in to comment.