margelo / react-native-graph

📈 Beautiful, high-performance Graphs and Charts for React Native built with Skia
https://margelo.io
MIT License
2.08k stars 118 forks source link

How onGestureStart, onGestureEnd and onPointSelected work?! #81

Open ziziele opened 1 year ago

ziziele commented 1 year ago

Could someone please edit the documentation or explain how to make it work?

I spent 3 days and still can't figure it out. The person who made this package is not cool.

const Test = ({ setPriceTitle }) => {
  const currentPrice = 0;

  const onGestureStart = useCallback(() => {
    hapticFeedback("impactLight");
  }, []);

  const onGestureEnd = useCallback(() => {
    setPriceTitle(currentPrice);
  }, [currentPrice, setPriceTitle]);

  const onPointSelected = useCallback((p) => {
    setPriceTitle(p);
  }, []);

  return (
    <LineGraph
      points={somePoints}
      color={someColors}
      style={someStyles}
      animated={true}
      onGestureStart={onGestureStart}
      onPointSelected={onPointSelected}
      onGestureEnd={onGestureEnd}
    />
  );
};

export default Test;
michaelpomogajko commented 1 year ago

What exactly is not clear? onPointSelected takes a callback and passes the current point. From there you can set it via state and do whatever you want