How to resize Canvas content when orientation change? #1116
Unanswered
paperbunny
asked this question in
Q&A
Replies: 1 comment
-
The best way to handle it is to assign the canvas size to an animation value and make the layout based on the cavans size: export const Demo = () => {
const size = useValue({ width: 0, height: 0});
const rct = useComputedValue(() => {
const center = vec(size.current.width / 2, size.current.height / 2);
return rrect(rect(center.x-50, center.y-50, 50, 50), 10, 10);
}, [size]);
return (
<Canvas style={{ flex: 1 }} onSize={size}>
<Fill color="red" />
<Group color="lightblue" >
<RoundedRect rect={rct} color="white" />
</Group>
</Canvas>
);
}; see https://shopify.github.io/react-native-skia/docs/canvas/overview#getting-the-canvas-size |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am drawing a rectangle of a canvas on the edge of the screen in iPad landscape. That looks good on iPad landscape but when I change the orientation, I could not see this rectangle which makes sense as landscape iPad has larger width compared to portrait mode. Wanted to ask what is the recommended way to handle this so that canvas content is not lost when orientation is changed from landscape to portrait?
here is code snippet :
Beta Was this translation helpful? Give feedback.
All reactions