Skip to content

fix(android): defer initial camera events until defaults apply - #4354

Closed
RobJacobson wants to merge 1 commit into
rnmapbox:mainfrom
RobJacobson:codex/fix-android-camera-startup-current
Closed

RobJacobson wants to merge 1 commit into
rnmapbox:mainfrom
RobJacobson:codex/fix-android-camera-startup-current

Conversation

@RobJacobson

Copy link
Copy Markdown
Contributor

Description

On Android, the Mapbox camera-change listener can run before the <Camera defaultSettings> attachment callbacks have applied the configured camera. During that startup window, onCameraChanged can expose the SDK's temporary [0, 0] center.

Hold camera-change notifications until attachment callbacks finish, then emit one change event pair for the resulting camera state. Subsequent camera changes continue through the normal event path.

Fixes #4213

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder — N/A; this Android lifecycle fix changes no generated code or docs
  • I tested the fix on the /example app
    • In V11 mode/iOS — N/A; Android-only change
    • In New Architecture mode/iOS — N/A; Android-only change
    • In V11 mode/Android
    • In New Architecture mode/Android
  • I added/updated a sample — N/A; this is a bug fix

Screenshot OR Video

N/A; the issue is about the values emitted during map startup.

Component to reproduce the issue you're fixing

import React from "react";
import { View } from "react-native";
import Mapbox, { Camera, MapView } from "@rnmapbox/maps";

const onCameraChanged = (mapState) => {
  const center = mapState?.properties?.center;
  if (!Array.isArray(center)) return;

  const [lng, lat] = center;
  if (lng !== 0 && lat !== 0) return;

  console.log(`COORDS ->> lng: ${lng} lat: ${lat}`);
};

export default function MapReproScreen() {
  return (
    <View style={{ flex: 1 }}>
      <MapView
        style={{ flex: 1 }}
        styleURL={Mapbox.StyleURL.Satellite}
        onCameraChanged={onCameraChanged}
      >
        <Camera
          defaultSettings={{
            centerCoordinate: [-93.265, 44.9778],
            zoomLevel: 6,
          }}
        />
      </MapView>
    </View>
  );
}

Before/after reproduction evidence

  • Before the fix, the Android emulator emitted center=[0,0] during startup, followed by the configured center. The issue reporter observes the zero center twice; this reproduction run observed it once.
  • After the fix, startup emitted the configured center [-93.265, 44.9778] and no [0,0] event. Panning the map continued to emit updated camera centers.

Validation evidence

  • Android Kotlin compilation and the example app debug build succeeded.
  • The example app was launched on an Android AVD; startup and pan behavior were checked against the reproducer.
  • Jest: 27 suites and 238 tests passed.
  • ESLint passed with example/build/** excluded. The unfiltered lint run reports one no-undef error for Buffer in the generated example/build/circle-native-gate/server.cjs; it is unrelated to this change.

- Hold startup camera notifications until attachment callbacks apply camera defaults
- Coalesce startup changes and emit the resulting camera state once
- Preserve later camera change events and valid [0, 0] centers
@RobJacobson

Copy link
Copy Markdown
Contributor Author

Closing this duplicate in favor of #4355. It follows the same Android startup camera change; #4355 preserves that fix, adds focused CameraChangeEventGate tests, and consolidates the validation record.

@RobJacobson
RobJacobson deleted the codex/fix-android-camera-startup-current branch October 14, 2026 00:01

This branch was successfully deployed

1 active 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.

[Bug]: Android: onCameraChanged fires with [0,0] on launch

1 participant