Skip to content

feat: let native code know when Camera is about to move the map - #4371

Merged
mfazekas merged 1 commit into
mainfrom
feat/camera-will-move-map-notification
Oct 19, 2026
Merged

mfazekas merged 1 commit into
mainfrom
feat/camera-will-move-map-notification

Conversation

@mfazekas

Copy link
Copy Markdown
Contributor

Description

Added a native hook on RNMBXMapView that is called right before <Camera> moves the map. Native code that shares the map, e.g. a navigation camera adopting it through RNMBXMapViewFactory, needs to yield when <Camera> takes over, otherwise it snaps the map back.

It is called for the stop props (including setCamera / fitBounds / flyTo / moveTo / zoomTo via ref), moveBy, scaleBy and followUserLocation, but not for defaultSettings or user gestures. It follows the existing per-map addGestureDelegate pattern rather than adding a NotificationCenter name, so both platforms share the same concept:

  • iOS: RNMBXCameraDelegate.cameraWillMoveMap(_:), registered with RNMBXMapView.addCameraDelegate(_:) / removeCameraDelegate(_:) (weak).
  • Android: OnCameraWillMoveMapListener.onCameraWillMoveMap(mapView), registered with RNMBXMapView.addOnCameraWillMoveMapListener / removeOnCameraWillMoveMapListener.

On Android, animated moves were already visible through CameraAnimationsLifecycleListener, but instant moves (animationDuration: 0, setCamera) and viewport transitions are not.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder (native-only API, nothing generated)
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios
    • In V11 mode/android
    • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

Screenshot OR Video

Tested with a temporary example screen (below) plus a temporary native delegate/listener that logs every call, kept out of this PR. On both platforms each of prop instant, prop animated, setCamera and moveBy produced exactly one call, with the RNMBXMapView hosting the map; pans/swipes produced none. On Android, a CameraAnimationsLifecycleListener logged alongside saw nothing for the instant prop move and the instant setCamera.

Component to reproduce the issue you're fixing

const centers = [[-74.006, 40.7128], [2.3522, 48.8566], [19.0402, 47.4979]];

const CameraWillMoveRepro = () => {
  const camera = useRef(null);
  const [index, setIndex] = useState(0);
  const [duration, setDuration] = useState(0);
  const next = (d) => { setDuration(d); setIndex((i) => (i + 1) % centers.length); };

  return (
    <View style={{ flex: 1 }}>
      <MapView style={{ flex: 1 }}>
        <Camera
          ref={camera}
          defaultSettings={{ centerCoordinate: centers[0], zoomLevel: 3 }}
          centerCoordinate={index === 0 ? undefined : centers[index]}
          zoomLevel={index === 0 ? undefined : 4}
          animationDuration={duration}
        />
      </MapView>
      <Button title="prop instant" onPress={() => next(0)} />
      <Button title="prop animated" onPress={() => next(500)} />
      <Button title="ref setCamera" onPress={() => camera.current?.setCamera({ centerCoordinate: centers[1], zoomLevel: 5, animationDuration: 0 })} />
      <Button title="ref moveBy" onPress={() => camera.current?.moveBy({ x: 50, y: 0 })} />
    </View>
  );
};

Add a per-map hook on RNMBXMapView, called right before <Camera> moves the
map from its stop props (and setCamera, fitBounds, flyTo, ...), moveBy,
scaleBy or followUserLocation. Native code driving the same map, such as a
navigation camera adopting it through RNMBXMapViewFactory, can then yield.

iOS: RNMBXCameraDelegate with RNMBXMapView.addCameraDelegate /
removeCameraDelegate (weak, like addGestureDelegate).
Android: OnCameraWillMoveMapListener with
RNMBXMapView.addOnCameraWillMoveMapListener / removeOnCameraWillMoveMapListener.
@mfazekas
mfazekas force-pushed the feat/camera-will-move-map-notification branch from adadd71 to 1fb77b5 Compare October 19, 2026 06:03
@mfazekas
mfazekas merged commit 46a2a9c into main Oct 19, 2026
9 checks passed
@mfazekas
mfazekas deleted the feat/camera-will-move-map-notification branch October 19, 2026 09:30

This branch was previously deployed

1 inactive deployment
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.

1 participant