-
-
Notifications
You must be signed in to change notification settings - Fork 846
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 method and address deprecations #3602
base: main
Are you sure you want to change the base?
Conversation
@mfazekas What would be required to get this merged? |
ios/RNMBX/RNMBXCamera.swift
Outdated
@@ -528,8 +554,11 @@ open class RNMBXCamera : RNMBXMapComponentBase { | |||
return false | |||
} | |||
|
|||
map.mapView.viewport.removeStatusObserver(self) | |||
return super.removeFromMap(map, reason:reason) | |||
withMapView { mapView in |
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.
I'm not sure about this on remove. Maybe just mapView?.viewport
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.
I don't understand the comment exactly - mapView
doesn't need optional chaining if acquired in the withMapView
callback. What's the concern?
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.
First it should be map.withMapView { }
we're in remove so we have a RNMBXMapView we're removing from, passed in as argument .
Second if mapView of RNMBXMapView is null then what was the satusObserver was attached to? Why do we need to remove?
So I think withMapView is unnecessary in this case. Likely not harmful but you have the check carefully as it could easily keep the camera object alive, until we'll have a mapView. Which doesn't sound right, but probably no leak here.
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.
I don't have a strong sense of the implications of the callback architecture (_mapCallbacks.append(callback)
, etc.).
We can do
map._mapView.viewport.removeStatusObserver(self)
but since _mapView
is force-unwrapped, I'm not sure if it could be nil when acquired that way. It'd be the only place in the camera module where map.mapView
is referenced that way. Do you prefer the map._mapView
syntax?
762c1e7
to
2f46a22
Compare
@mfazekas what would be involved in getting this merged? Happy to make changes, but it seems fairly straightforward - please let me know. |
camera: .init(cameraState: .init( | ||
center: .init(), | ||
padding: .zero, | ||
zoom: zoom ?? 0, |
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.
I've found that I have more consistant results by using zoom: .zero
. If zoom is set on this camera is seems to effect the positioning.
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.
@mfazekas @naftalibeder I'll aim to make a demo this afternoon of why i've highlighted this.. but when moving the camera with setCamera from a centerCoordinates position to setCamera with bounds it seems that zoom is applied to the final position. Adding this zoom: .zero
looks to fix this problem thou I need to look at why.
bearing: heading ?? map.mapboxMap.cameraState.bearing, | ||
pitch: pitch ?? map.mapboxMap.cameraState.pitch | ||
)), | ||
coordinatesPadding: padding, |
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.
why do we use coordinatePadding and not camera padding?
Description
Fixes camera bounds-with-padding bug in v11 described in mapbox/mapbox-maps-ios#2134.
Checklist
CONTRIBUTING.md
yarn generate
in the root folder/example
app.I added/updated a sample - if a new feature was implemented (/example
)