Skip to content

view.takeScreenshot does not work for react-native-skia canvas #4489

@mauricedoepke

Description

@mauricedoepke

What happened?

When taking a screenshot of a view, react native skia content does not show up.

More data, please!

This issue occures because detox uses a views internal draw function to create the screenshots:

class ViewScreenshot() {
fun takeOf(view: View): ScreenshotResult {
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
view.draw(Canvas(bitmap))
return ScreenshotResult(bitmap)
}
}

rn skia uses a TextureView to draw its contents, this however does not support drawing itself to canvas:
Subclasses of TextureView cannot do their own rendering with the [Canvas](https://developer.android.com/reference/android/graphics/Canvas) object.

https://developer.android.com/reference/android/view/TextureView#draw(android.graphics.Canvas)

It seems possible to implement the desired behaviour through the getBitmap method of TextureView though:
https://github.com/facebook/screenshot-tests-for-android/pull/71/files

The skia maintainer confirmed this issue some time ago already:
Shopify/react-native-skia#1880

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions