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

useChartPressState does not work with newer versions of Reanimated #227

Open
3 tasks done
michaeltugby0 opened this issue Mar 29, 2024 · 9 comments
Open
3 tasks done

Comments

@michaeltugby0
Copy link

michaeltugby0 commented Mar 29, 2024

Prerequisites

  • I have searched the open issues to make sure I'm not opening a duplicate issue
  • I have read through the docs before asking a question
  • I am using the latest version of victory-native-xl

Describe Your Environment

What version of victory-native-xl are you using? (can be found by running npm list --depth 0 victory-native)
40.1.0

What version of React and React Native are you using?
React: 18.2.0
React Native: 0.73.6

What version of Reanimated and React Native Skia are you using?
Reanimated: 3.8.1
Skia: 1.2.0

Are you using Expo or React Native CLI?
React Native CLI + Repack

What platform are you on? (e.g., iOS, Android)
Android

Describe the Problem

There seems to be a compatibility issue with newer versions of Reanimated when using useChartPressState. The bug first occurred in 3.7.0 of Reanimated (3.6.3 is the last I could get working). From my initial testing, the gesture handlers are all fine and activating as expected. However, the shared values are not updating. I suspect it may be because of the way the shared values are being updated here, which goes against what Reanimated recommends here (the last point, to be specific).

Expected behavior: [What you expect to happen]
isActive to switch to true when a user presses on their device.

Actual behavior: [What actually happens]
Nothing happens because isActive never changes to true.

Additional Information

Reproduction: https://github.com/michaeltugby0/victory-native-reanimated-bug

@nirmaanlabs
Copy link

I have the same problem @michaeltugby0 what version you ended up using then ?

@zibs
Copy link
Contributor

zibs commented Apr 9, 2024

Thanks for calling this out. Hopefully can take a look shortly.

@michaeltugby0
Copy link
Author

michaeltugby0 commented Apr 10, 2024

I have the same problem @michaeltugby0 what version you ended up using then ?

@nirmaanlabs 3.6.3 was the latest one I could get working.

@zibs zibs self-assigned this Apr 11, 2024
@zibs
Copy link
Contributor

zibs commented Apr 11, 2024

Hey @michaeltugby0 and @nirmaanlabs -- I'm looking into this and can't really reproduce the issue. It seems like it's working fine to me, but maybe I'm misunderstanding something? Can you provide more details, or better yet, and example application and explain the issue more thoroughly?

Thanks!

Below is what I spun up and tested with:

    "@shopify/react-native-skia": "^1.0.3",
    "react": "18.2.0",
    "react-native": "0.73.3",
    "react-native-gesture-handler": "^2.14.1",
    "react-native-reanimated": "3.8.1",
    "victory-native": "^40.1.0"
import * as React from 'react';
import {View} from 'react-native';
import {CartesianChart, Line, useChartPressState} from 'victory-native';
import {Circle} from '@shopify/react-native-skia';
import {type SharedValue} from 'react-native-reanimated';

export function MyChart() {
  const {state, isActive} = useChartPressState({x: 0, y: {highTmp: 0}});
  const {state: state2, isActive: isActive2} = useChartPressState({
    x: 0,
    y: {highTmp: 0},
  });

  return (
    <View style={{height: 300}}>
      <CartesianChart
        data={DATA}
        xKey="day"
        yKeys={['highTmp']}
        axisOptions={{}}
        chartPressState={[state, state2]}>
        {({points}) => (
          <>
            <Line points={points.highTmp} color="red" strokeWidth={3} />
            {isActive && (
              <ToolTip x={state.x.position} y={state.y.highTmp.position} />
            )}
            {isActive2 && (
              <ToolTip x={state2.x.position} y={state2.y.highTmp.position} />
            )}
          </>
        )}
      </CartesianChart>
    </View>
  );
}

function ToolTip({x, y}: {x: SharedValue<number>; y: SharedValue<number>}) {
  return <Circle cx={x} cy={y} r={8} color="black" />;
}

const DATA = Array.from({length: 31}, (_, i) => ({
  day: i,
  highTmp: 40 + 30 * Math.random(),
}));

@michaeltugby0
Copy link
Author

Hey @zibs, thanks for looking into it! I suspect there must be some other element that's causing the problem. I have some free time over the weekend, so I'll see if I can get a repro going for you.

@michaeltugby0
Copy link
Author

michaeltugby0 commented Apr 13, 2024

Hey again @zibs, managed to reproduce it. Strangely, it only occurs when building with Repack. I've attached a link to the repo at the end of the original post.

@zibs
Copy link
Contributor

zibs commented Apr 18, 2024

I'm not as familiar with Repack myself, nor why it would be handling this differently, so if either of you want to take a stab at this, please feel free!

@zibs zibs removed their assignment Apr 18, 2024
@nirmaanlabs
Copy link

It is working for me now @zibs @michaeltugby0

@KonarkRajMisra
Copy link

how did you get it to work @nirmaanlabs?

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

No branches or pull requests

4 participants