rnmapbox / rnmapbox/maps

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

Open
#4,213 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug 🪲
Dominant language
Kotlin
Stars
2.9k
Forks
947
Avg merge
6d 37m
Merged PRs (30d)
1

Description

Mapbox Version

11.20.1

React Native Version

0.83.6

Platform

Android

@rnmapbox/maps version

10.3.1

Standalone component to reproduce
import React from "react";
import { View } from "react-native";
import Mapbox, { Camera, MapState, 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}`);
};

const MapReproScreen = () => (
  <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>
);

export default MapReproScreen;

Observed behavior and steps to reproduce

On Android only, onCameraChanged fires twice on app launch with center=[0,0], even though the camera is initialized with a different defaultSettings.centerCoordinate.

Observed logs:
COORDS ->> lng: 0 lat: 0
COORDS ->> lng: 0 lat: 0

Expected behavior

Expected: onCameraChanged should not emit [0,0] during initialization when the configured initial camera center is [-93.265, 44.9778].

Question: should consumers gate onCameraChanged behind a specific map/camera readiness event, or is this a bug?

Notes / preliminary analysis

No response

Additional links and references

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no source files or tests. Start by running the supplied React Native reproduction on Android and tracing the initialization path for onCameraChanged against Camera defaultSettings. Done means initialization no longer emits [0,0], or the documented readiness behavior clearly explains how consumers should avoid those events.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, javascript, react-native
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.