googlemaps / react-native-navigation-sdk

React Native library (Beta) for bringing Google Navigation SDK to Android and iOS apps using React.
https://www.npmjs.com/package/@googlemaps/react-native-navigation-sdk
Apache License 2.0
30 stars 6 forks source link

Clicking on marker jumps a bit if another marker is already opened #41

Closed ziga-hvalec closed 7 months ago

ziga-hvalec commented 8 months ago

If I click on one marker map nicely animates to it. but if i then click on another the maps jumps a bit. If i close a marker by clicking on map and then click on another marker, map again animates nicely

Environment details

  1. Specify the API at the beginning of the title (for example, "Places: ...") navigation sdk
  2. OS type and version ios 16
  3. Library version and other environment information tag 0.1.4

Steps to reproduce

  1. click on marker.
  2. click on another markers
  3. observer weird jump

Code example

import React, { useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { Dimensions, LayoutChangeEvent, StyleSheet, View } from 'react-native';
import {
  MapType,
  MapViewCallbacks,
  MapViewController,
} from 'react-native-navigation-sdk/components/maps/mapView/types';
import NavigationView from 'react-native-navigation-sdk/components/navigation/navigationView/index';
import {
  NavigationViewCallbacks,
  NavigationViewController,
} from 'react-native-navigation-sdk/components/navigation/navigationView/types';

import { Routes } from '../../../navigation/routes';
import { MainStackNavigatorParamList } from '../../../navigation/Navigation';
import { MainHeader } from '../../../components/headers/mainHeader/MainHeader';
import { ScreenWrapper } from '../../../components/screenWrapper/ScreenWrapper';
import { Container } from '../../../components/layout/container/Container';

interface Marker {
  label: string;
  sublabel: string;
  latitude: number;
  longitude: number;
}

export interface TasksMapParams {
  markers: Marker[];
}

const style = StyleSheet.create({
  wrapper: {
    flex: 1,
  },
});

export const TasksMap = () => {
  const navigation =
    useNavigation<NativeStackNavigationProp<MainStackNavigatorParamList>>();
  const route =
    useRoute<RouteProp<MainStackNavigatorParamList, Routes.TasksMap>>();

  const { t } = useTranslation();

  const [mapViewController, setMapViewController] =
    useState<MapViewController | null>(null);

  const mapRef = useRef<View>();

  const [mapHeight, setMapHeight] = useState<number | undefined>();

  const navViewWidth = Dimensions.get('window').width;

  const onMapReady = () => {
    const markers = route.params.markers;
    markers.forEach(marker => {
      mapViewController?.addMarker({
        position: {
          lat: Number(marker.latitude),
          lng: Number(marker.longitude),
        },
        title: marker.label,
        snippet: marker.sublabel,
        visible: true,
      });
    });

    // mapViewController?.setMyLocationButtonEnabled(false);
    mapViewController?.setTiltGesturesEnabled(false);
    // mapViewController?.setMapType(MapType.NORMAL);
    // mapViewController?.moveCamera({
    //   target: {
    //     lat: markers[0].latitude,
    //     lng: markers[0].longitude,
    //   },
    //   tilt: 0,
    //   zoom: 15,
    //   bearing: 0,
    // });
  };

  const mapViewCallbacks: MapViewCallbacks = {
    onMapReady,
  };

  const setHeight = () => {
    mapRef.current?.measure((_, __, ___, height) => {
      setMapHeight(height);
    });
  };

  return (
    <ScreenWrapper
      header={
        <MainHeader onBack={navigation.goBack} label={t('tasksMap.header')} />
      }>
      <View
        style={style.wrapper}
        onLayout={() => setHeight()}
        ref={(element: View) => (mapRef.current = element)}>
        {!!mapHeight && (
          <NavigationView
            width={navViewWidth}
            height={mapHeight}
            androidStylingOptions={{}}
            iOSStylingOptions={{}}
            mapViewCallbacks={mapViewCallbacks}
            onMapViewControllerCreated={setMapViewController}
            onNavigationViewControllerCreated={() => {}}
            termsAndConditionsDialogOptions={{}}
          />
        )}
      </View>
    </ScreenWrapper>
  );
};
ArturoSalazarB16 commented 8 months ago

@zbillones-navagis can you please take a look?

ArturoSalazarB16 commented 7 months ago

Hey there! We have migrated to the latest native iOS NavSDK and i am not able to repro the issue, this should be fixed. Please feel free to re-open in case you still see on your end