Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Setting 'defaultSettings' on '<Mapbox.Camera />' showing the wrong location on very first render of the app #3449

Open
sagarshakya opened this issue Apr 10, 2024 · 2 comments
Labels
bug 🪲 Something isn't working

Comments

@sagarshakya
Copy link

sagarshakya commented Apr 10, 2024

Mapbox Implementation

Mapbox

Mapbox Version

default

React Native Version

0.72.4

Platform

Android

@rnmapbox/maps version

10.1.19

Standalone component to reproduce

import React from 'react';
import { StyleSheet, View } from "react-native";

import Mapbox from "@rnmapbox/maps";

Mapbox.setAccessToken("XXX");

export default function App() {
  return (
    <View style={styles.page}>
      <View style={styles.container}>
        <Mapbox.MapView style={styles.map}>
          <Mapbox.Camera
            defaultSettings={{
              centerCoordinate: [13.404684, 52.519254],
              zoomLevel: 14.5,
            }}
          />
        </Mapbox.MapView>
      </View>
    </View>
  );
}
const styles = StyleSheet.create({
  page: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
  },
  container: {
    height: "100%",
    width: "100%",
  },
  map: {
    flex: 1,
  },
});

Observed behavior and steps to reproduce

On the very first render of the map component, when you set the defaultSettings prop on <Mapbox.Camera />, the map shows the wrong location. After you reload the app (or close and open the app), the issue is fixed. The issue occurs only on the very first render. On all subsequent renders, the map shows the correct location as set with defaultSettings.

If you clear the app storage and open the app again, the issue persists.

XRecorder_Edited_10042024_163440.mp4

Expected behavior

The map should show the value set as defaultSettings on <Mapbox.Camera /> component correctly.

Notes / preliminary analysis

No response

Additional links and references

No response

@McFly78
Copy link

McFly78 commented Apr 29, 2024

Same for me on IOS.
When using a created Mapbox studio style, the location used when the app first open is the default location configured for the style in "Default map position" on Mapbox studio.

@yossarin
Copy link

yossarin commented Aug 9, 2024

For me using "@rnmapbox/maps": "10.1.28" it works on IOS.

On Android I have to do a fix:

const defaultSettings = {
  zoomLevel: 5.55,
  centerCoordinate: [16.5, 44.47],
};

let firstRender = true;

class CameraController extends React.PureComponent {
  static propTypes = {...};

  componentDidMount() {
    if (firstRender && Platform.OS === 'android') {
      // https://github.com/rnmapbox/maps/issues/3449
      this.cameraRef.setCamera(defaultSettings);
    }

    firstRender = false;
  }

  render() {
    return (
      <MapboxGL.Camera
        defaultSettings={defaultSettings}
        ref={component => (this.cameraRef = component)}
      />
    );
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants