react-native-graph icon indicating copy to clipboard operation
react-native-graph copied to clipboard

onPointSelected is very slow when I update a state

Open Spoutnik97 opened this issue 3 years ago • 1 comments

Hi, I tried to update a state in my component, thanks to onPointSelected props, but when I swipe my finger on the line, the pointer is very very slow to update.

I guess it is because I set a state at each time setFingerX is called

Do you have an idea how to update my state ?

 const [selectedGraphPoint, setSelectedGraphPoint] = useState<GraphPoint>({
    value: 0,
    date: new Date(),
  });

 return (<>
            <TotalAmountCard amount={selectedGraphPoint.value} />
            <LineGraph
              points={points}
              color={theme.colors.base.text.secondary}
              style={styles.graphContainer}
              enablePanGesture
              animated
              onPointSelected={setSelectedGraphPoint}
            />
  </>)

Spoutnik97 avatar Jun 15 '22 14:06 Spoutnik97

Hello, I had the same issue, please check this https://github.com/margelo/react-native-graph/issues/8 Long story short you need to move your state to animated values

DDushkin avatar Jun 15 '22 14:06 DDushkin

Hello, I had the same issue, please check this #8 Long story short you need to move your state to animated values

Yes, @DDushkin is right.

The onPointSelected callback will run on every change of the AnimatedValue driving the graph.

So any changes triggered by that callback, will have to be run on the UI thread...

Will close this, as this should be fixed.

Feel free to open a new issue, if you still have any issues

chrispader avatar Sep 12 '22 16:09 chrispader