react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

🐛 react-native-skia removed support for `onLayout` in v2.2.1

Open maksymblank opened this issue 1 year ago • 28 comments

What's happening?

onLayout that's used in SkiaCameraCanvas.tsx was recently removed in @shopify/react-native-skia v2.2.1 release and is now replaced with onSize.

Workaround for now is to downgrade @shopify/react-native-skia to v2.2.0 or lower.

Reproduceable Code

const frameProcessor = useSkiaFrameProcessor(
    frame => {
      'worklet';

      frame.render();
    },
    [],
  );

VisionCamera Version

@shopify/react-native-skia @^2.2.1

Can you reproduce this issue in the VisionCamera Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

maksymblank avatar Aug 07 '25 01:08 maksymblank

Guten Tag, Hans here 🍻.

Thank you for reporting zhis issue! It seems like you are facing a problem with onLayout being removed in a recent update of @shopify/react-native-skia, and I appreciate you providing useful information. However, I noticed zat you haven’t attached any relevant logs or detailed information about your camera device and environment.

For better assistance, could you please provide logs from Xcode or Android Studio, depending on your development environment? You can gather logs using adb logcat for Android or by viewing the logs in Xcode when running your app.

Also, to make sure this issue gets the attention it deserves, feel free to support zhe project by becoming a sponsor here, if possible.

Looking forward to your response!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

maintenance-hans avatar Aug 07 '25 01:08 maintenance-hans

If you or someone else has the issue yet, since you are using the Skia v2 and onLayout was obsoleted, you need to apply some changes to */node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx. If you'd like to specify the canvas size on the UI thread and you are using RN reanimated, follow this guide:

https://shopify.github.io/react-native-skia/docs/canvas/overview/#ui-thread

Otherwise:

https://shopify.github.io/react-native-skia/docs/canvas/overview/#js-thread

Then, use the patch-package lib to patch it. Also, I attached the patch file for the size specifying on the UI thread (guide 1), so that you can alternatively copy it to the patches dir and use the lib for patching it.

Note: the patch file is compatible with react-native-vision-camera version 4.7.1

react-native-vision-camera+4.7.1.patch

Mhp23 avatar Aug 17 '25 17:08 Mhp23

Hi @mrousavy , any updates on this?

hoanghai9650 avatar Sep 23 '25 11:09 hoanghai9650

Thanks @Mhp23 your patch does work. With skia 2.2.13 the error is now gone, using a useSkiaFrameProcessor does freeze the image on ios though. Can't find a solution yet.

maxximee avatar Oct 03 '25 07:10 maxximee

Hi @maksymblank, you're welcome. I also came across the issue that, if I’m not wrong, starts from version 2.2.11. I didn’t have enough time to explore the reason for the issue, so I recommend downgrading the lib to 2.2.10 until the issue is found and solved.

Mhp23 avatar Oct 03 '25 20:10 Mhp23

Hi @maksymblank, you're welcome. I also came across the issue that, if I’m not wrong, starts from version 2.2.11. I didn’t have enough time to explore the reason for the issue, so I recommend downgrading the lib to 2.2.10 until the issue is found and solved.

Exactly, the behaviour changes between 2.2.10 and 2.2.11. In 2.2.10 it works but the memory increases indefinetly until the app crashes, starting from 2.2.11 it just freezes after less than a second.

I've been using version 1.10 successfully until now, but I've migrated from expo 52 to 53 and new arch, so I can't revert back to version 1.x sadly. I'm a bit stuck and trying to fix the vision-camera but without any luck so far.

maxximee avatar Oct 06 '25 01:10 maxximee

In IOS as soon as the camera screen is pushed into the navigation stack after two seconds it throws onLayout not being supported on New Arch.

Is downgrading the packages the only option left or going back to Old Arch? I have to undo all the migration i did for RN 0.81 and Expo 54.

Been stuck with this for 5 days. I cant figure out anything except patch-package and updating it to onSize, but i am not sure if i do that the results would be the same as before.

Raman-Halder avatar Oct 08 '25 07:10 Raman-Halder

In IOS as soon as the camera screen is pushed into the navigation stack after two seconds it throws onLayout not being supported on New Arch.

Is downgrading the packages the only option left or going back to Old Arch? I have to undo all the migration i did for RN 0.81 and Expo 54.

Been stuck with this for 5 days. I cant figure out anything except patch-package and updating it to onSize, but i am not sure if i do that the results would be the same as before.

Even if you fix that error, you'll still face a freeze after a few seconds. There is also a memory leak that leads to crash after a few seconds on older versions. I managed to make it kind of work using one of 2.2.0 version and limiting the fps to 10 (above 12/15 fps it crashes). This leaves just enough time for the memory to be flushed before the app crashes. This means your app's memory will increase really high then be flushed just on time before a crash... Needless to say it's not great but with current state it's as good as I got it running

@Mhp23 By the way, I've noticed your patch has an incorrect size and zooms in the picture. But it's a good start, thanks for it anyways.

maxximee avatar Oct 08 '25 07:10 maxximee

I've been using version 1.10 successfully until now, but I've migrated from expo 52 to 53 and new arch, so I can't revert back to version 1.x sadly. I'm a bit stuck and trying to fix the vision-camera but without any luck so far.

FYI 1.x can work in RN new arch -- I had it working in Expo 52

therealpurplemana avatar Oct 18 '25 19:10 therealpurplemana

Would really appreciate having this fixed. I'm new to React Native and am just following the basic instructions to install React Native, Vision Camera, and Skia from the official docs. Unfortunately it's broken due to this error.

ERROR <Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size

Deps are here:

"expo": "~54.0.20"
"react": "19.1.0",
"react-native": "0.81.5",
"@shopify/react-native-skia": "2.2.12",
"react-native-reanimated": "~4.1.1",

It ends me up in this situation after running:

npx create-expo-app@latest
npx expo install react-native-vision-camera
npm i @shopify/react-native-skia
npm i react-native-reanimated

If anyone has a suggestion for how to bypass this, I'd appreciate it. Otherwise I guess I just need to wait until this issue is fixed to develop my camera effects app. I am doing Android fwiw.

I should mention that I did try and downgrade react-native-skia to 2.2.10 as some suggested, however it didn't fix the issue. I can't go back to 1.x without causing a whole bunch of dependency incompatibilities.

EDIT

Confirmed that @Mhp23 's patch did work against react-native-vision-camera 4.7.2 to support react-native-skia 2.2.12

EDIT2

It's not working when the phone is rotated

MaxPleaner avatar Oct 30 '25 09:10 MaxPleaner

Mesmo problema aqui.

Allyson1602 avatar Nov 06 '25 20:11 Allyson1602

Tried to update the SkiaCameraCanvas.tsx with the new UI and JS methods set by @shopify/react-native-skia

Both lead to a frozen camera.

tmoubarak avatar Nov 17 '25 11:11 tmoubarak

Tried to update the SkiaCameraCanvas.tsx with the new UI and JS methods set by @shopify/react-native-skia

Both lead to a frozen camera.

Same here, it fixed the error in the log, but frozen camera. My only work-around was to use an old version of skia (2.2.4) and set fps to 15 + format to 2048. It leads to a low resolution preview with bad frame rate, but it's the only work-around I've found. I tried a lot to fiddle with the values (fps / resolution), but as soon as I increase either one the crashes start to show up on low-end devices like iphone 12

maxximee avatar Dec 01 '25 06:12 maxximee

is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size

@mrousavy getting the same issue any solution on this

pankajtime123 avatar Dec 20 '25 19:12 pankajtime123

Is there any update on this? I'm trying to apply a blur background filter and this prevents me doing it.

rewebcan avatar Jan 07 '26 17:01 rewebcan

Is there any update on this @mrousavy ? useSkiaFrameProcessor cannot be used right now, due to this . @maxximee did you find any reliable workaround for this with new arch? Thanks

srivastava9 avatar Jan 24 '26 08:01 srivastava9

Is there any update on this @mrousavy ? useSkiaFrameProcessor cannot be used right now, due to this . @maxximee did you find any reliable workaround for this with new arch? Thanks

Not really, on android I disable frame processor (no available workaround), on ios I use an old version before the onLayout bug and limit format to 2048x2048 to avoid the memory leak exception. Looks like crap but it's the only way until this is fixed.

maxximee avatar Jan 24 '26 08:01 maxximee

This is working for us with latest Skia (yes, latest), expo 53. You need to watch your GC much more carefully than 1.X

react-native-vision-camera+4.7.3.patch:

diff --git a/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx b/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx
index 56d4e0e..2c7da4b 100644
--- a/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx
+++ b/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx
@@ -1,4 +1,5 @@
 import React, { useCallback, useState } from 'react'
+import { View } from 'react-native'
 import type { LayoutChangeEvent, ViewProps } from 'react-native'
 import type { CameraProps } from '../types/CameraProps'
 import type { ISharedValue } from 'react-native-worklets-core'
@@ -47,10 +48,12 @@ function SkiaCameraCanvasImpl({ offscreenTextures, resizeMode = 'cover', childre
   }, [])
 
   return (
-    <SkiaProxy.Canvas {...props} onLayout={onLayout} pointerEvents="none">
-      {children}
-      <SkiaProxy.Image x={0} y={0} width={width} height={height} fit={resizeMode} image={texture} />
-    </SkiaProxy.Canvas>
+    <View {...props} onLayout={onLayout} style={[props.style, { flex: 1 }]}>
+      <SkiaProxy.Canvas style={{ width, height }} pointerEvents="none">
+        {children}
+        <SkiaProxy.Image x={0} y={0} width={width} height={height} fit={resizeMode} image={texture} />
+      </SkiaProxy.Canvas>
+    </View>
   )
 }

therealpurplemana avatar Jan 24 '26 17:01 therealpurplemana

This is working for us with latest Skia (yes, latest), expo 53. You need to watch your GC much more carefully than 1.X

react-native-vision-camera+4.7.3.patch:

diff --git a/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx b/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx
index 56d4e0e..2c7da4b 100644
--- a/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx
+++ b/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx
@@ -1,4 +1,5 @@
 import React, { useCallback, useState } from 'react'
+import { View } from 'react-native'
 import type { LayoutChangeEvent, ViewProps } from 'react-native'
 import type { CameraProps } from '../types/CameraProps'
 import type { ISharedValue } from 'react-native-worklets-core'
@@ -47,10 +48,12 @@ function SkiaCameraCanvasImpl({ offscreenTextures, resizeMode = 'cover', childre
   }, [])
 
   return (
-    <SkiaProxy.Canvas {...props} onLayout={onLayout} pointerEvents="none">
-      {children}
-      <SkiaProxy.Image x={0} y={0} width={width} height={height} fit={resizeMode} image={texture} />
-    </SkiaProxy.Canvas>
+    <View {...props} onLayout={onLayout} style={[props.style, { flex: 1 }]}>
+      <SkiaProxy.Canvas style={{ width, height }} pointerEvents="none">
+        {children}
+        <SkiaProxy.Image x={0} y={0} width={width} height={height} fit={resizeMode} image={texture} />
+      </SkiaProxy.Canvas>
+    </View>
   )
 }

That removes the error, but doesn't fix the existential bugs sadly. iOS will still freeze / crash because of memory leak and android will still crash or show black screen on about 10% of all devices. It might work for you on your development device, but trust me once you deploy on PROD you will see high crash rates and regret.

maxximee avatar Jan 26 '26 04:01 maxximee

PM me on discord. I’ll add you to TestFlight. It’s not crashing. I had to lower the camera resolution.

On Sun, Jan 25, 2026 at 8:47 PM maxximee @.***> wrote:

maxximee left a comment (mrousavy/react-native-vision-camera#3598) https://github.com/mrousavy/react-native-vision-camera/issues/3598#issuecomment-3797886385

This is working for us with latest Skia (yes, latest), expo 53. You need to watch your GC much more carefully than 1.X

react-native-vision-camera+4.7.3.patch:

diff --git a/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx b/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx index 56d4e0e..2c7da4b 100644 --- a/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx +++ b/node_modules/react-native-vision-camera/src/skia/SkiaCameraCanvas.tsx @@ -1,4 +1,5 @@ import React, { useCallback, useState } from 'react' +import { View } from 'react-native' import type { LayoutChangeEvent, ViewProps } from 'react-native' import type { CameraProps } from '../types/CameraProps' import type { ISharedValue } from 'react-native-worklets-core' @@ -47,10 +48,12 @@ function SkiaCameraCanvasImpl({ offscreenTextures, resizeMode = 'cover', childre }, [])

return (

  • <SkiaProxy.Canvas {...props} onLayout={onLayout} pointerEvents="none">
  •  {children}
    
  •  <SkiaProxy.Image x={0} y={0} width={width} height={height} fit={resizeMode} image={texture} />
    
  • </SkiaProxy.Canvas>
  • <View {...props} onLayout={onLayout} style={[props.style, { flex: 1 }]}>
  •  <SkiaProxy.Canvas style={{ width, height }} pointerEvents="none">
    
  •    {children}
    
  •    <SkiaProxy.Image x={0} y={0} width={width} height={height} fit={resizeMode} image={texture} />
    
  •  </SkiaProxy.Canvas>
    

) }

That removes the error, but doesn't fix the existential bugs sadly. iOS will still freeze / crash because of memory leak and android will still crash or show black screen on about 10% of all devices. It might work for you on your development device, but trust me once you deploy on PROD you will see high crash rates and regret.

— Reply to this email directly, view it on GitHub https://github.com/mrousavy/react-native-vision-camera/issues/3598#issuecomment-3797886385, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATTERSZW7PEJMLSGPNTZ5AL4IWL6JAVCNFSM6AAAAACDJQRROCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTOOJXHA4DMMZYGU . You are receiving this because you commented.Message ID: @.***>

therealpurplemana avatar Jan 26 '26 05:01 therealpurplemana