How to draw multiple circles dynamically (Cartesian Chart tooltip intersections) #2346
-
Hello, I am new to using skia and I am trying to draw multiple circles on a cartesian chart at line intersections. They are used in a tooltip component. Here is my current attempt; however as I pan over the chart the circle Y values do not update in real time because I am using yValue which is a number and not a SharedValue. The x values are just fine as I am passing them in as a shared value.
XToYMapping is just a map Record<xCoordinate, number[yCoordinate1, yCoordinate2...]> so that in the component I can draw n circles at the X coordinate where n is the number array of y coordinates. So if I had x = 32, I would perhaps get out yValues of [100, 22] and I would want to draw 2 circles in that case at their respective y positions. Is there any way I can create an array like SharedValue[] from the useDerivedValue hook that way I can pass in a sharedValue to the cy in the circle? Thanks, any help is much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
To have dynamic arrays of shared values you can look at this example: https://github.com/wcandillon/can-it-be-done-in-react-native/blob/ceb3d22418d6e7d3dc7535e1710f04d03c150b6e/season5/src/Instagram/StickerModal.tsx#L14 (makeMutable is the non hook version of useSharedValue). Of course another great way to animate on a dynamic number of drawing elements is Picture: https://shopify.github.io/react-native-skia/docs/shapes/pictures/ |
Beta Was this translation helpful? Give feedback.
To have dynamic arrays of shared values you can look at this example: https://github.com/wcandillon/can-it-be-done-in-react-native/blob/ceb3d22418d6e7d3dc7535e1710f04d03c150b6e/season5/src/Instagram/StickerModal.tsx#L14 (makeMutable is the non hook version of useSharedValue).
Of course another great way to animate on a dynamic number of drawing elements is Picture: https://shopify.github.io/react-native-skia/docs/shapes/pictures/