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]: Android - Compass not rotating on initial load #2543

Open
Bastich-dev opened this issue Jan 13, 2023 · 6 comments
Open

[Bug]: Android - Compass not rotating on initial load #2543

Bastich-dev opened this issue Jan 13, 2023 · 6 comments
Labels
Android Android related tickets

Comments

@Bastich-dev
Copy link

Bastich-dev commented Jan 13, 2023

Mapbox Implementation

Mapbox

Mapbox Version

10.7.0

Platform

Android

@rnmapbox/maps version

10.0.0-beta.64 & 10.0.0-beta.62

Standalone component to reproduce

import { MAPBOX_ACCESS_TOKEN } from '@constants';

import MapboxGL, { MapView } from '@rnmapbox/maps';

import { Button, Text, View } from 'react-native';

import { createStackNavigator } from '@react-navigation/stack';
import { NavigationContainer, useNavigation } from '@react-navigation/native';
import React , { useState } from 'react';

MapboxGL.setAccessToken(MAPBOX_ACCESS_TOKEN);

export default function App() {
    const Stack = createStackNavigator();

    return (
        <NavigationContainer>
            <Stack.Navigator id="App">
                <Stack.Screen name={'MAP_SCREEN'} component={PageMap} />
                <Stack.Screen name={'OTHER_SCREEN'} component={PageOther} />
            </Stack.Navigator>
        </NavigationContainer>
    );
}

function PageMap() {
    const { navigate } = useNavigation();
    const [compassWorking, setCompassWorking] = useState(false);

    return (
        <View style={fullPageStyle}>
            <Button
                title="go to OTHER screen"
                onPress={() => {
                    setCompassWorking(true);
                    navigate('OTHER_SCREEN');
                }}
            />
            <Text>
                {compassWorking
                    ? 'Now the compass rotating well'
                    : 'The compass not rotating until you go to another screen and go back to this screen'}
            </Text>
            <MapView
                style={{ flex: 1 }}
                compassEnabled={true}
                rotateEnabled={true}
                scrollEnabled={true}
                pitchEnabled={true}
            />
        </View>
    );
}

function PageOther() {
    const { navigate } = useNavigation();
    return (
        <View style={fullPageStyle}>
            <Button title="go back to MAP screen" onPress={() => navigate('MAP_SCREEN')} />
            <Text>Now go back to Map Screen and the compass will rotating well</Text>
        </View>
    );
}

const fullPageStyle = {
    width: '100%',
    height: '100%',
    backgroundColor: '#FF000022',
};

Observed behavior and steps to reproduce

The compass on initial load of MapView not rotating until you go to another screen, and go back to the screen with the map.

After go to antoher screen and go back to the screen map, the compass work perfectly.

Expected behavior

Compass rotate on the first render of MapView

Notes / preliminary analysis

Android version : 12 SP1A.210812.016
Development environment
Using Expo 47.0.0

Packages version tested :

@react-navigation/native : 6.1.2 & 6.0.10
@react-navigation/stack : 6.3.11 & 6.2.1
@rnmapbox/maps : 10.0.0-beta.64 & 10.0.0-beta.62
expo : 47.0.0


Maybe kinda related to these pull requests :
#2427
#2352

Additional links and references

You'll need these two libs in addition for make the exemple work :

  • @react-navigation/native
  • @react-navigation/stack

I think you can copy/paste the exemple ( except the MAPBOX_ACCESS_TOKEN ) and see what is going wrong.

Do you think you could make it rotate work for the next beta version ?
Or maybe you got a little hack in React-native to resolve this ?

BIG Thanks for providing this lib 👍

@Bastich-dev Bastich-dev changed the title [Bug]: Android - Compass not rotating on first render MapView [Bug]: Android - Compass not rotating on initial load MapView Jan 16, 2023
@Bastich-dev Bastich-dev changed the title [Bug]: Android - Compass not rotating on initial load MapView [Bug]: Android - Compass not rotating on initial load Jan 16, 2023
@jfaq89
Copy link

jfaq89 commented Feb 16, 2023

I am experiencing the same problem. Any news here?

@jfaq89
Copy link

jfaq89 commented Feb 16, 2023

In my case I am using 10.0.0-beta.69

@mfazekas mfazekas added the Android Android related tickets label Feb 26, 2023
@mfazekas
Copy link
Contributor

I was testing with current main and it seems to work on first load. So should be fixed in beta70

image

@mfazekas
Copy link
Contributor

This was the component I've used to reproduce in our test app:

import MapboxGL, { MapView } from '@rnmapbox/maps';
import { Button, Text, View } from 'react-native';
import React, { useState } from 'react';

function PageMap({navigation}) {
  const [compassWorking, setCompassWorking] = useState(false);

  return (
    <View style={{ flex: 1 }}>
      <Button
        title="go to OTHER screen"
        onPress={() => {
          setCompassWorking(true);
          navigation.navigate('ScreenWithoutMap');
        }}
      />
      <Text>
        {compassWorking
          ? 'Now the compass rotating well'
          : 'The compass not rotating until you go to another screen and go back to this screen'}
      </Text>
      <MapView
        style={{ flex: 1 }}
        compassEnabled={true}
        rotateEnabled={true}
        scrollEnabled={true}
        pitchEnabled={true}
      />
    </View>
  );
}

const fullPageStyle = {
  width: '100%',
  height: '100%',
  backgroundColor: '#FF000022',
};

export default PageMap;

@mfazekas mfazekas reopened this Feb 26, 2023
@mfazekas
Copy link
Contributor

mfazekas commented Feb 26, 2023

Actually still see the issue


Some notes to myself, when it's working it's working via this:

onCameraMove:188, CompassViewPlugin
lambda 'forEach' in 'onCameraMove':153, MapPluginRegistry
onCameraMove:152, MapPluginRegistry
_init_$lambda-0:83, MapController
...
onCameraChanged:-1, MapController$$ExternalSyntheticLambda1
..
setCamera:-1, CameraManager

@wen-kai
Copy link
Contributor

wen-kai commented Mar 14, 2023

As of the past month on Android we've had to explicitly call locationManager.start() for user location/heading to update; otherwise, UserLocation would just stay stuck on initial load. May be related here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Android related tickets
Projects
None yet
Development

No branches or pull requests

4 participants