Shopify / Shopify/react-native-skia

Canvas size behaviour regression when transformed

Open
#3,836 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
8.6k
Forks
647
Avg merge
1d 17h
Merged PRs (30d)
35

Description

Description

There appears to have been a regression in the behaviour of canvas onSize at some point between 2.2.12 and 2.6.2, specifically when the canvas is itself transformed. The width and height supplied by onSize appear to use the size on-screen after the transform has been applied, rather than its "natural" layout size as rendered. This causes anything that is drawn using the canvas size as input to be drawn at the wrong size when there is a canvas transform applied.

React Native Skia Version

2.6.2

React Native Version

0.81.5

Using New Architecture
  • Enabled
Steps to Reproduce

Apply a scale transformation to the canvas (either directly or via a parent view), then render a <Rect> with the width and height from the canvas size.

The expected behaviour in the code below is that the red <Rect> fills the canvas and the view behind it (so that no blue appears). However, it renders at half size.

  const size = useSharedValue({ width: 0, height: 0 });
  const width = useDerivedValue(() => size.value.width);
  const height = useDerivedValue(() => size.value.height);

  return (
    <View style={{transform: [{ scale: 0.5, backgroundColor: 'blue' }]}}>
      <Canvas style={{ flex: 1 }} onSize={size}>
        <Rect
          x={0}
          y={0}
          width={width}
          height={height}
          color="red"
          style="fill"
        ></Rect>
      </Canvas>
    </View>  
  );
Snack, Code Example, Screenshot, or Link to Repository

The example above can be checked out from https://github.com/donaldharvey/react-native-skia-canvas-size-regression.

Behaviour in 2.6.2:

Image

Behaviour in 2.2.12:

Image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Canvas onSize entry point and use the linked reproduction to compare reported dimensions with and without the parent scale transform. Verify the behavior against React Native Skia 2.2.12 and 2.6.2; done means the transformed example receives natural layout dimensions and the Rect fills the canvas.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
computer-graphics, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.