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

fix(android): on user tracking mode change #3122

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

mfazekas
Copy link
Contributor

@mfazekas mfazekas commented Oct 19, 2023

Fixes: #3017

@mfazekas
Copy link
Contributor Author

Used the following example to test:

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

const App = () => {
  const [followUserMode, setFollowUserMode] = useState<UserTrackingMode | null>(
    UserTrackingMode.Follow,
  );
  const [followUserLocation, setFollowUserLocation] = useState<boolean>(true);

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

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

            setFollowUserMode(event.nativeEvent.payload.followUserMode || null);
            console.log(
              `setFollowUserLocation(${
                event.nativeEvent.payload.followUserMode != null
              })`,
            );
            setFollowUserLocation(
              event.nativeEvent.payload.followUserMode != null,
            );
          }}
        />
      </MapView>
    </>
  );
};

@mfazekas mfazekas force-pushed the mfazekas/fix-android-on-user-tracking-mode-change branch from 9455e8a to 6c85b2f Compare October 19, 2023 13:38
@mfazekas mfazekas force-pushed the mfazekas/fix-android-on-user-tracking-mode-change branch from 6c85b2f to 11216b1 Compare October 19, 2023 13:40
@mfazekas mfazekas merged commit b08319a into main Oct 19, 2023
9 checks passed
@mfazekas mfazekas deleted the mfazekas/fix-android-on-user-tracking-mode-change branch October 19, 2023 14:21
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 this pull request may close these issues.

[Bug]: Camera.onUserTrackingModeChange not called on followUserMode change on Android
1 participant