首页 > 解决方案 > 反应原生视图拍摄无法收到空消息

问题描述

我想用React Native View Shot 导出图片,但是有一个问题,图片怎么不想导出,所以出现这样的错误。用英文,就像“shot can't receive empty message” 在此处输入图像描述

这是我的代码

import ViewShot, { captureScreen } from 'react-native-view-shot';
const viewShotRef = useRef();
const [handleButton, setHandleButton] = useState(true);

async function captureViewShot() {
  setHandleButton(false);
  const imageURI = await viewShotRef.current.capture();
  console.log(imageURI);
  setHandleButton(true);
  Share.share({ title: 'Nota', url: imageURI });
}

function captureScreenShot() {
  captureScreen({
    format: 'jpg',
    quality: 0.8,
  }).then(
    (uri) => {
      console.log(uri);
      Share.share({ title: 'Nota', url: uri });
    },
    (error) => console.log('IMage gagal to', error)
  );
}

这是我的观点

<ViewShot
  ref={viewShotRef}
  style={{ flex: 1 }}
  options={{ format: 'jpg', quality: 1.0 }}>
  <Table borderStyle={styles.tableStyle}>
    <Row
      data={tableHead}
      style={styles.head}
      textStyle={styles.text}
      flexArr={[1, 2, 1, 1]}
    />
    <Rows data={tableData} textStyle={styles.text} flexArr={[1, 2, 1, 1]} />
  </Table>
</ViewShot>

在我的情况下,我需要 2 个导出,即仅导出表格并导出整个屏幕,但它们都不起作用

标签: javascriptreactjsreact-nativereact-native-androidreact-native-view-shot

解决方案


推荐阅读