Optimize rendering for extremely large canvas (Copy Google Recorder UI) #2469
-
Hi, I am trying to display a large number of items on a canvas (potentially 100k plus) but it crashes after a few thousands. Screen.Recording.2024-06-11.at.8.37.54.AM.movIn my case if I try to display a big canvas, it crashes after a few thousand items and I get errors such as:
So instead I think a workaround would be to have a fixed size canvas so that only visible items are rendered... But I havent found the correct way to implement. const Minimal = () => {
const { width: screenWidth } = useWindowDimensions();
const canvasWidth = screenWidth; // Canvas width is twice the screen width
const styles = React.useMemo(
() => getStyles(screenWidth, canvasWidth),
[screenWidth, canvasWidth],
);
const translateX = useSharedValue(0);
const panGesture = Gesture.Pan().onUpdate((event) => {
translateX.value += event.translationX;
console.log(`translateX: ${translateX.value}`);
});
return (
<View style={styles.container}>
<GestureDetector gesture={panGesture}>
<View style={styles.canvasContainer}>
<Canvas style={{ height: 300 }}>
{Array.from({ length: 100 }, (_, index) => {
return (
<RoundedRect
key={"r" + index}
x={130 * (index + 1) + translateX.value}
y={64}
width={128}
height={128}
r={10}
/>
);
})}
</Canvas>
</View>
</GestureDetector>
</View>
);
}; Here the translateX.value change is not detected in the main thread so it doesnt drag my rectangles. What would you recommend to implement a similar experience as the demo? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
have you looked into the atlas API? seems to be what you need: https://shopify.github.io/react-native-skia/docs/shapes/atlas/ |
Beta Was this translation helpful? Give feedback.
it's actually possible that the Atlas API may not work for this use case. The waveform size would need to be scale on the Y axis and the Atlas API doesn't support non uniform scaling. Sorry for the misleading suggestion