coinjar / react-native-wagmi-charts

A sweet & simple chart library for React Native that will make us feel like We're All Gonna Make It.
MIT License
589 stars 116 forks source link

Is there a way to get clicks on crosshairs in a candlestick chart? #150

Closed jihoon8730 closed 7 months ago

jihoon8730 commented 1 year ago

image true if the crosshair is touched, false if not, etc.

honeybadger26 commented 7 months ago

Hi @jihoon8730

Do you mean detecting if the crosshair is active? That can be done by using the CandlestickChart.useChart hook and checking that currentX and currentY are not equal to -1

import { runOnJS, useDerivedValue } from 'react-native-reanimated';
import { CandlestickChart } from 'react-native-wagmi-charts';

const PositionText = () => {
  const { currentX, currentY } = CandlestickChart.useChart(); // These are Reanimated shared values
  const [crosshairActive, setCrosshairActive] = React.useState(false);

  useDerivedValue(() => {
    runOnJS(setCrosshairActive)(currentX.value !== -1 && currentY.value !== -1);
  });

  return <Text>Crosshair active: {crosshairActive ? 'Yes' : 'No'}</Text>;
};
jihoon8730 commented 7 months ago

@honeybadger26

This is an old post, but but using a different chart solved it! Thank you so much for your answer

I'll pin it in case it helps anyone else