Repository navigation
fix(ios): send the current camera when onCameraChanged is registered - #4430
Open
aderiushev wants to merge 1 commit into
Open
aderiushev wants to merge 1 commit into
aderiushev wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
On iOS,
MapViewsends camera changes to JS only after JS has asked for them (setHandledMapChangedEventsWithEvents, whichMapViewcalls fromcomponentDidMountand again when a callback prop changes). A camera change before that is never sent, and nothing sends the camera afterwards. So when JS asks late,onCameraChangedgets no camera until the map moves:componentDidMount(timing-dependent; we hit it every time in our app's map screen, which mounts many layers);onCameraChangedis set after the map has settled (always).onMapIdlestill reports the right camera, so an app that keeps the camera fromonCameraChangeddisagrees with the map until the user touches it.This PR: when
.cameraChangedis newly in the handled set, send the current camera once, asapplyOnMapChangewould (not when.regionIsChangingis registered, which takes precedence there). It goes throughwithMapView, so it waits for the map view. Registering the same set again (MapViewdoes that on every render with an inline callback) sends nothing.Android is not changed. There the handled set starts as
null, so camera changes before the first registration are sent; a listener added later gets no camera until the map moves there too (from readingRNMBXMapView.kt, not run). I can add the same one-shot on Android if you want both to behave the same. #4426 fixes the Android start-camera loss from the 10 ms drop.Checklist
CONTRIBUTING.mdyarn generatein the root folder (no changes)/exampleapp./example)Screenshot OR Video
The reproducer below in the example app (
mainat 47a736a, React Native 0.84.1, New Architecture, Mapbox 11.33.0), iOS 26.5 simulator (iPhone 16). The map opens at zoom 12 and is never touched; each run is a fresh app launch.main'busy'(JS busy 3 s while the map mounts), 10 runs: noonCameraChangedat all'late'(onCameraChangedset at the first idle), 3 runs:onCameraChangedcallsIn every run
onMapIdlereported zoom 12.00. Without the busy child the start camera usually comes aftercomponentDidMount, which is why the'busy'case is timing-dependent; in one run with this PR the one-shot carried the map's first camera (zoom 0.47) and the start camera followed as a normal change. The text area has a fixed height: text that grows would resize the map, and a resize is a camera change of its own.Component to reproduce the issue you're fixing
BugReportExample.js — 'busy' and 'late' modes, counts onCameraChanged for a map that is never moved
🤖 Generated with Claude Code