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]: onUpdate doesn't update the value in a ref #3558

Closed
sulemanbutt10 opened this issue Jul 1, 2024 · 1 comment
Closed

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

sulemanbutt10 opened this issue Jul 1, 2024 · 1 comment

Comments

@sulemanbutt10
Copy link

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 React from 'react';
import {
  MapView,
  Camera,
  UserLocation,
  UserLocationRenderMode
} from '@rnmapbox/maps';


  const addPoint = () => {
  // This function just handles the adding of a point on current location
  //  onPressAddPoint(currentPosition.current ?? [0, 0]);
  };
  

class BugReportExample extends React.Component {
  render() {
    return (
      <MapView style={{flex: 1}}>
        <Camera centerCoordinate={currentPosition.current ?? [0,0]} zoomLevel={14} />
     
  <UserLocation
          minDisplacement={1}
          animated
          androidRenderMode="gps"
          showsUserHeadingIndicator
          renderMode={UserLocationRenderMode.Native}
          onUpdate={({ coords: { longitude, latitude } }) => {
            currentPosition.current = [longitude, latitude];
          }}
        />
      </MapView>
    );
  }
}

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)

This error only occurs while the location is moving.

Additional links and references

No response

@sulemanbutt10 sulemanbutt10 added the bug 🪲 Something isn't working label Jul 1, 2024
Copy link

github-actions bot commented Jul 1, 2024

Lint failed 😭

Please fix the errors in your code example - More info.:

error: 'currentPosition' is not defined (no-undef) at example.jsx:21:35:
  19 |     return (
  20 |       <MapView style={{flex: 1}}>
> 21 |         <Camera centerCoordinate={currentPosition.current ?? [0,0]} zoomLevel={14} />
     |                                   ^
  22 |      
  23 |   <UserLocation
  24 |           minDisplacement={1}


error: 'currentPosition' is not defined (no-undef) at example.jsx:30:13:
  28 |           renderMode={UserLocationRenderMode.Native}
  29 |           onUpdate={({ coords: { longitude, latitude } }) => {
> 30 |             currentPosition.current = [longitude, latitude];
     |             ^
  31 |           }}
  32 |         />
  33 |       </MapView>


2 errors found.```

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

No branches or pull requests

1 participant