rnmapbox / maps

A Mapbox react native module for creating custom maps
MIT License
2.26k stars 848 forks source link

[Bug]: onUpdate doesn't update the value in a ref #3557

Closed sulemanbutt10 closed 4 months ago

sulemanbutt10 commented 4 months ago

Mapbox Implementation

Mapbox

Mapbox Version

10.17.0

React Native Version

0.70.15

Platform

iOS, Android

@rnmapbox/maps version

10.0.15

Standalone component to reproduce

import { useEffect, useRef, useState } from 'react'; import { Platform } from 'react-native'; import MapboxGL, { UserLocationRenderMode } from '@rnmapbox/maps'; import { MapState } from '@rnmapbox/maps/lib/typescript/components/MapView'; import { area } from '@turf/turf'; import { isEmpty } from 'lodash'; import { useTranslation } from 'react-i18next'; import { SearchIcon, CurrentLocationIcon, HelpCircleIcon, ResetIcon, OnePinIcon, } from '@ricultx/assets'; import { ConfirmationModal } from '@ricultx/components/Farmer'; import { OutOfAreaModal, WhitePointer } from '@ricultx/components/Field'; import { DistanceLabels, NearbyFields, PolygonDrawing, PolygonJoints, MAP_STYLE_SATELLITE, } from '@ricultx/components/MapComponents'; import { drawFieldNearbyFieldFillLayerStyle } from '@ricultx/components/MapComponents/NearbyBoundaries/NearbyBoundaries.styled'; import { SearchLocationsHandler, SearchLocations, } from '@ricultx/components/SearchLocations'; import { SVGImage } from '@ricultx/components/SVGImage'; import useOrgSpecificConfig from '@ricultx/pattern/ui/hooks/useOrgSpecificConfig'; import { getIsConnected } from '@ricultx/store/nodes/networking'; import { useDeleteRecentUserSearchesMutation, useSaveRecentUserSearchMutation, } from '@ricultx/store/nodes/userSearch'; import { useSelector } from '@ricultx/store/root'; import { useCountryData } from '@ricultx/store/utils'; import { useModalVisible } from '@ricultx/utils/hooks'; import { mapStyle, OptionsContainer, HelpTextContainer, TopOptions, TopOptionItem, CustomControl, HelpTextStyle, AreaTextContainer, } from './DrawFieldFeature.styled'; import { DrawFieldFeatureProps } from './DrawFieldFeature.types'; import { MapButtons } from './MapButtons'; import { useMapDrawing } from './useMapDrawing';

/*

Observed behavior and steps to reproduce

I have made a follow location feature. The camera follows the user if he/she is moving. During the movement, the onUpdate is triggered but it doesnot uPdates the value in "currentPosition.current". Instead it passes some previous value in the function which came across the movement.

Expected behavior

"currentPosition.current" must be updated properly and should give the exact current value of "currentPosition.current" whenever the addPoint function is called.

Notes / preliminary analysis

I have also tried this on newer versions (10.1.1 to 10.1.15) and the latest version (10.1.27) but no luck. When i hanged "minDisplacement" value to 5, it started updating the "curretPosition.current" after moving some meters. But i need that to add that point right where i clicked the button (means right where my current location was displayed)

Additional links and references

No response

github-actions[bot] commented 4 months ago

No code example found in issue body - More info