react-native-skia icon indicating copy to clipboard operation
react-native-skia copied to clipboard

Html <canvas> does not resize correctly with the window

Open jack-beanstalk-2022 opened this issue 1 year ago • 0 comments

Description

React native skia <Canvas> on web ultimately renders to a html <canvas> inside a <div>. The div is resized when the browser window resizes but the <canvas> is not.

Here is an example: my <Canvas> was originally 500x714, that lead to a 1000x1428 <canvas>. When I shrink the window size, <div> gets resized, but <canvas> remains at 1000x1428. Screenshot 2024-07-26 at 8 59 54 AM

I think this is due to: https://github.com/Shopify/react-native-skia/blob/45ae9cb3f1067b51958f2f1cdaa95a2ecd33f4de/package/src/views/SkiaBaseWebView.tsx#L47 here we are reusing original canvas.clientWidth rather than the width / height from the layout event. Is there a reason not to?

Version

1.2.3

Steps to reproduce

  1. create a simple web app with <Canvas>
  2. open element inspector from developer tools, find the html <canvas>
  3. resize the browser
  4. observe <canvas> does not change size

Snack, code example, screenshot, or link to a repository

Here is https://github.com/Shopify/react-native-skia/blob/45ae9cb3f1067b51958f2f1cdaa95a2ecd33f4de/package/src/views/SkiaBaseWebView.tsx#L47

jack-beanstalk-2022 avatar Jul 26 '24 16:07 jack-beanstalk-2022