react-native-skia: Web Animations Broken

Description

Looks like web animations are broken on the newest version. I don’t know the exact version this bug was introduced in, but I can confirm that our web animations were working in v1.7.6. As far as I can tell, this affects all Skia animations using Reanimated.

Expected: Blue square in reproduction slides back and forth. Actual: Blue square in reproduction does not move.

React Native Skia Version

1.11.4

React Native Version

React Native Web: 0.19.12

Using New Architecture

  • Enabled

Steps to Reproduce

https://github.com/nathan-ahn/skia-web-animation-bug

Reproducing

  1. Install yarn install
  2. Run web yarn web
  3. See the blue square (Skia) not move (Pink square included to demonstrate Reanimated is working)

Notes

I usually prefer to use Expo for minimum reproducible examples but can’t until #2914 is resolved. I’m using the same Solito setup to that we use in production to get Skia web to work. I don’t believe that any of the Next.js workarounds are causing this issue, but happy to reproduce using Expo Router once #2914 is fixed.

Snack, Code Example, Screenshot, or Link to Repository

https://github.com/nathan-ahn/skia-web-animation-bug

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (11 by maintainers)

Most upvoted comments

thanks for your support on this 🙏

Same here. Using a library like this one with the latest version of Skia 1.11.8 on the web : https://github.com/doublelam/react-native-free-canvas

The animation does not work.

Also when a rerender occur with a different stroke property on my SkiaPath, I have the error Cannot read properties of undefined (reading 'Kd'). The stack :

Uncaught Error
Cannot read properties of undefined (reading 'Kd')
Call Stack
pc
node_modules/canvaskit-wasm/bin/full/canvaskit.js
<anonymous>
node_modules/canvaskit-wasm/bin/full/canvaskit.js
a.Canvas.prototype.drawPath
node_modules/canvaskit-wasm/bin/full/canvaskit.js
drawPath
node_modules/@shopify/react-native-skia/lib/module/skia/web/JsiSkCanvas.js
drawPath
node_modules/@shopify/react-native-skia/lib/module/sksg/Recorder/commands/Drawing.js
paints.forEach$argument_0
node_modules/@shopify/react-native-skia/lib/module/sksg/Recorder/Player.js

To reproduce in summary :

const pathSharedVal = useSharedValue(Skia.Path.Make());
const derivedPathSharedVal = useDerivedValue(
    () => pathSharedVal.value.toSVGString(),
    [],
  );

const gesture = useMemo(
    () =>
      Gesture.Pan()
        .averageTouches(true)
        .minDistance(0)
        .maxPointers(1)
        .onBegin((e) => {
          "worklet";
          const touch = e;
          pathSharedVal.modify((v) => {
            v.reset();
            v.moveTo(touch.x || 0, touch.y || 0);
            v.lineTo(touch.x || 0, touch.y || 0);
            return v;
          });
        })
        .onUpdate((e) => {
          "worklet";
          if (pathSharedVal.value.isEmpty()) {
            return;
          }
          pathSharedVal.modify((v) => {
            v.lineTo(e.x || 0, e.y || 0);
            return v;
          });
        })
        .onFinalize(() => {
          "worklet";
          if (pathSharedVal.value.isEmpty()) {
            return;
          }
          runOnJS(addDrawn)({
            key: generateUniqueKey("path"),
            path: getSharedValue(derivedPathSharedVal),
            ...stroke,
          } as DrawingPath);
        }),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    [stroke],
  );

return (
    <GestureDetector gesture={gesture}>
      <View style={styles.canvas} ref={viewRef}>
          <Canvas style={styles.canvas}>
            {drawnPaths.map((path) => (
              <Path style="stroke" {...path} key={path.key} />
            ))}
            <Path path={derivedPathSharedVal} style="stroke" {...stroke} />
          </Canvas>
      </View>
    </GestureDetector>
  );