Skip to content

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

Description

@fractalscape13

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲Something isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions