Changing MapViewPort to MapViewProxy #65
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue/Motivation
MLNMapView
offers many properties and functions that are useful to developers, things like contentInset or convert functions can be used to create more complex camera interactions, like checking if aFeature
is already visible on the map (and not covered by a bottom sheet or similar), and if it is, not moving the camera.At the same time we don't want to expose
MLNMapView
to developers, as this would allow developers to modifyMLNMapView
in a way that clashes with swiftui-dsl.This PR changes the existing
MapViewPort
to instead beMapViewProxy
: a read only proxy to functions and properties ofMLNMapView
. This way, developers can store a reference to theMapViewProxy
struct, and get access to properties and functions of theMLNMapView
. TheMLNMapView
is not directly exposed, and only functions are exposed that do not alter state. Properties are only expose their getter.The proxy pattern is already used by features such as
GeometryReader
orScrollViewReader
. Newer functions of swift appear not to use the reader pattern, but prefer a onChange pattern, for example https://www.hackingwithswift.com/quick-start/swiftui/how-to-detect-when-the-size-or-position-of-a-view-changes - so SwiftUI users should feel right at home.This allows developers to write a function like this:
Additional Information
I have only exposed the properties that I need for my specific use case, but if we agree with this implementation, future properties and functions that are to be exposed could be added here.
I have renamed the properties that MapViewProxy already had to their MLNMapView name: my thinking here is that this way, people can directly use the MLNMapView documentation on the usage of these properties,