Skip to content
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

Merged
merged 2 commits into from
Aug 5, 2024
Merged

Fix camera binding issues #43

merged 2 commits into from
Aug 5, 2024

Conversation

ianthetechie
Copy link
Collaborator

This fixes two issues with camera handling introduced in #39.

  • The default configuration disables all camera updates. While this may be required for certain edge use cases, this should not be the default.
  • The default behavior of MLNMapView within a UIViewController creates an "edit war" if you are trying to set content insets, which all navigation use cases will need to do. This was pretty hard to foresee, but the docs on the contentInsets property do mention the behavior.

@ianthetechie ianthetechie requested a review from Archdoog August 1, 2024 04:59
@ianthetechie
Copy link
Collaborator Author

Would love a review from @Patrick-Kladek and/or @hactar on this, since it does make a few changes you probably should know about.

Copy link
Collaborator Author

@ianthetechie ianthetechie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments to help review...

@@ -5,7 +5,7 @@ import SwiftUI

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

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.

@@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two point of note here:

  1. I apologise if I've forgotten a reason that this was supposed to be public, but I don't see an obvious reason so removed that modifier.
  2. I made the insets optional because I think that it's quite possible that someone (maybe @Patrick-Kladek and @hactar?) actually DO want the default behavior! (More in a future comment at the use site.)

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

if cameraDisabled == false {
context.coordinator.updateCamera(mapView: uiViewController.mapView,
camera: $camera.wrappedValue,
camera: camera,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

@Patrick-Kladek Patrick-Kladek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have briefly tested this in our App and it doesn't break anything. Based on this I can confirm it works with Navigation

@ianthetechie ianthetechie merged commit 02f5a62 into main Aug 5, 2024
4 checks passed
@ianthetechie ianthetechie deleted the fix-camera-binding-issues branch August 5, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants