YanYuanFE / react-native-signature-canvas

:black_nib: React Native Signature Component based WebView Canvas for Android && IOS && expo
MIT License
417 stars 149 forks source link

getting white screen when taking screenshot #320

Closed Akshaybagai52 closed 5 months ago

Akshaybagai52 commented 1 year ago

When i'm taking screenshot with "react-native-view-shot" package then i'm getting blank in signature screen can anyone tell me what to do for this behaviour

YanYuanFE commented 1 year ago

https://github.com/gre/react-native-view-shot/issues?q=webview+canvas

YanYuanFE commented 1 year ago

The problem is caused by the use of Webview and Canvas. I think of an alternative. You can use the generated signature base64 to replace the webview after drawing, so that you can take a screenshot

Akshaybagai52 commented 1 year ago

can you elaborate more to me so that i can try that Thanks for reply

YanYuanFE commented 1 year ago
export default function App() {
  const [img, setImg] = useState(null);
  const [sign, setSign] = useState(null);
  const ref = useRef();

  const onCapture = () => {
    ref.current.capture().then(uri => {
      console.log("do something with ", uri);
      setImg(uri);
      // setSign(null);
    });
  }

  useEffect(() => {
    if(sign) {
      setTimeout(() => {
        onCapture();
      }, 300)
    }
  }, [sign]);
  return (
      <View style={styles.container}>
        <ViewShot ref={ref} options={{ fileName: "Your-File-Name", format: "png", quality: 0.9, result: 'data-uri' }}>
          <View style={{
            width: 400,
            height: 300
          }}>
            {sign ? (
                <Image
                    resizeMode={"contain"}
                    style={{ width: 400, height: 114 }}
                    source={{ uri: sign }}
                />
            ) : <Sign text="Test" onOK={(img) => {
              console.log('ok')
              setSign(img);
              onCapture();
            }} />}
          </View>
          <Text>...Something to rasterize...</Text>
        </ViewShot>
        <View style={styles.preview}>
          {img ? (
              <Image
                  resizeMode={"contain"}
                  style={{ width: 335, height: 114 }}
                  source={{ uri: img }}
              />
          ) : null}
        </View>
      </View>
  );
}