-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix camera binding issues #43
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two point of note here:
|
||
|
||
var unsafeMapViewControllerModifier: ((T) -> Void)? | ||
|
||
|
@@ -103,13 +103,16 @@ public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentab | |
|
||
if cameraDisabled == false { | ||
context.coordinator.updateCamera(mapView: uiViewController.mapView, | ||
camera: $camera.wrappedValue, | ||
camera: camera, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sometimes forget the details of binding syntactic sugar, but I am pretty sure this is equivalent. |
||
animated: isStyleLoaded) | ||
} | ||
} | ||
|
||
@MainActor private func applyModifiers(_ mapViewController: T, runUnsafe: Bool) { | ||
mapViewController.mapView.contentInset = mapViewContentInset | ||
if let mapViewContentInset { | ||
mapViewController.mapView.automaticallyAdjustsContentInset = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, here's where things get a bit funny. We HAVE to disable automatic inset adjustment here, but as initially submitted, this PR does NOT have a solution for opting back in once you've disabled it. It feels like the API for doing so would be a bit clunky. For example, we could add a modifier which sets this explicitly, but then it's going to sometimes conflict with this and so it won't take effect. A second approach might be to model content insets as an enum. I think that works.... Is it really a binary choice of full manual or full auto? |
||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obvious change discussed on Slack.