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]: Camera.onUserTrackingModeChange not called on followUserMode change on Android #3017

Closed
andrei-tofan opened this issue Aug 28, 2023 · 13 comments · Fixed by #3122
Closed

Comments

@andrei-tofan
Copy link
Contributor

andrei-tofan commented Aug 28, 2023

Mapbox Implementation

Mapbox

Mapbox Version

default

Platform

Android

@rnmapbox/maps version

10.0.12

Standalone component to reproduce

import React, {useState} from 'react';
import Mapbox, {Camera, MapView, UserTrackingMode} from '@rnmapbox/maps';
import {Button, Platform} from 'react-native';

const App = () => {
  const [followUserMode, setFollowUserMode] = useState<
    UserTrackingMode | undefined
  >(UserTrackingMode.Follow);

  return (
    <>
      {Object.values(UserTrackingMode).map((mode: any) => (
        <Button
          key={mode}
          title={`${mode} ${mode === followUserMode ? '(active)' : ''}`}
          onPress={() => {
            console.log('setMode', mode);
           setFollowUserMode(mode);
          }}
        />
      ))}
      <MapView style={{flex: 1}}>
        <Mapbox.UserLocation visible showsUserHeadingIndicator />

        <Camera
          followUserLocation
          followUserMode={followUserMode}
          onUserTrackingModeChange={(event: any) => {
            console.log(
              `onUserTrackingModeChange(${event.nativeEvent.payload.followUserMode})`,
            );

            setFollowUserMode(
              event.nativeEvent.payload.followUserMode || undefined,
            );
          }}
        />
      </MapView>
    </>
  );
};

export default App;

Observed behavior and steps to reproduce

When changing the followUserMode, the onUserTrackingModeChange callback is called on iOS but is not called on Android.

Expected behavior

The onUserTrackingModeChange callback should be called on both platforms.

Notes / preliminary analysis

No response

Additional links and references

Found a comment about this issue here:
#1090

@andrei-tofan
Copy link
Contributor Author

any updates on this, can I help fix it in any way?

@mfazekas
Copy link
Contributor

@andrei-tofan sorry I did not have time to look into it.

Trying on current main or 10.1 beta-s would help.

You can also try to debug the viewport code https://github.com/rnmapbox/maps/pull/2767/files

@andrei-tofan
Copy link
Contributor Author

Tested with v10.1.0-beta.11 and the issue is still there, will have a look. Thanks!

@mfazekas
Copy link
Contributor

Hm I don't seem to be able to reproduce the issue with the included sample code:

Screen.Recording.2023-10-13.at.13.54.30.mov

@andrei-tofan
Copy link
Contributor Author

Can you also include the logs to see if the

console.log(`onUserTrackingModeChange(${event.nativeEvent.payload})`);

gets called?

@mfazekas
Copy link
Contributor

The button's were changed so it got called.

This is the console log:

 LOG  Running "RNMapboxGLExample" with {"rootTag":21}
 LOG  onUserTrackingModeChange([object Object])
 LOG  onUserTrackingModeChange([object Object])
 LOG  mode normal
 LOG  onUserTrackingModeChange([object Object])
 LOG  onUserTrackingModeChange([object Object])
 LOG  mode compass
 LOG  onUserTrackingModeChange([object Object])
 LOG  onUserTrackingModeChange([object Object])
 LOG  mode normal
 LOG  onUserTrackingModeChange([object Object])
 LOG  onUserTrackingModeChange([object Object])
 LOG  mode compass
 LOG  onUserTrackingModeChange([object Object])
 LOG  onUserTrackingModeChange([object Object])

@jaltin
Copy link
Contributor

jaltin commented Oct 16, 2023

Hi @mfazekas,

I am a colleague of @andrei-tofan and helping him with this issue, hence why I also get involved in this thread.

We are not getting the onUserTrackingModeChange log in the same way as you on Android.

See the attached video where I try to illustrate when it is firing only when dragging on the map with finger (an android phone running os 9).

IMG_7407.MOV

I have also tested on an Android tablet with os 11 and having the same problem there.

On iOS it is firing on every mode change, just as in your console log example.

I hope this helps in illustrating the problem we are having, but let me know if we can provide further info.

@andrei-tofan
Copy link
Contributor Author

andrei-tofan commented Oct 16, 2023

Hi @mfazekas, I've attached a video created using the example app in the project showing the behaviour on iOS and what I think should happen on Android as well.
https://drive.google.com/file/d/1L2KoiprRt7_Uj4hXLAKxKL_180KfGuyL/view?usp=sharing

@mfazekas
Copy link
Contributor

@jaltin Ok sorry I wasn't careful enough reading the issue. So you're missing onUserTrackingModeChange in case you're programatically changing followUserMode on the Camera.

@andrei-tofan
Copy link
Contributor Author

Yes, and because of this we don't know if the mode was really changed. Ideally, onUserTrackingModeChange should be called if followUserLocation or followUserLocation changes, no matter if the change is due to user interaction or was made programmatically.

@mfazekas
Copy link
Contributor

@andrei-tofan this should be addressed in 10.1.0-beta.13

@andrei-tofan
Copy link
Contributor Author

@mfazekas thank you for the fix, tested and onUserTrackingModeChange is called when followUserMode is changed programmatically but found 2 additional issues related to setting followUserLocation programmatically.

  1. on Android, when I set followUserLocation to false the onUserTrackingModeChange is not called (is called on set to true).
  2. on iOS, when I set followUserLocation to false the onUserTrackingModeChange is called but the followUserLocation property in the payload is set to true instead of false.

Let me know if I should open a separate issue for this.

@andrei-tofan
Copy link
Contributor Author

@mfazekas I will open 2 separate issues for the items from the comment above

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 a pull request may close this issue.

3 participants