gre / react-native-view-shot

Snapshot a React Native view and save it to an image
https://github.com/gre/react-native-view-shot-example
MIT License
2.64k stars 343 forks source link

on Android, capture GL Views: handleGLSurfaceViewOnAndroid #471

Open michalis-ligopsychakis opened 1 year ago

michalis-ligopsychakis commented 1 year ago

Hello everyone :) I am trying to capture a screenshot on android but I get blank image. I want to ask, where can I use the "handleGLSurfaceViewOnAndroid" prop in order to fix that ..?

react-native: 0.64.4 react-native-view-shot: 3.1.2 @viro-community/react-viro: 2.23.0

skizzo commented 1 year ago

Hey there, fellow react-viro user :)

I'm using React Native 0.71.7 so it might be that this won't work in your case, but this works for me:

captureScreen({
  format: "jpg",
  quality: 0.8,
  handleGLSurfaceViewOnAndroid: true // <-- add this property here
}).then(
  (uri) => console.log("Image saved to", uri),
  (error) => console.error("Oops, snapshot failed", error)
);

Weirdly enough, this only captures the Viro view, any other React Native components that are above it are not included in the resulting screenshot.