how to programmatically take a screenshot in react-native

后端 未结 2 1242
情书的邮戳
情书的邮戳 2021-02-07 13:26

How can I take a screenshot in ReactNative. I need a screenshot and put it in Image component. How could I do?

2条回答
  •  野性不改
    2021-02-07 14:03

    There is a library to do just that: React Native View Shot

    import RNViewShot from "react-native-view-shot";
    
    RNViewShot.takeSnapshot(viewRef, {
      format: "jpeg",
      quality: 0.8
    })
    .then(
      uri => console.log("Image saved to", uri),
      error => console.error("Oops, snapshot failed", error)
    );
    

提交回复
热议问题