如何在 React Native 中分享容器截图 | android 博览会

How to share container screenshot in React Native | Expo for android

我构建了一个应用程序,我想在其中将组件作为图像共享。 我就是这样做的。

 const shareImageHandler = async () => {
try {
  const uri = await captureRef(containerRef, {
    quality: 1,
    format: "jpg",
  });

  await Sharing.shareAsync(uri);
  console.log("action succeed");
} catch (error) {
  console.log("something went wrong!");
}

};

但是我收到了这个错误。

[TypeError: undefined is not an object (evaluating '_expoSharing.default.shareAsync')]

我想作为图像共享的组件。

 <ImageBackground
      ref={containerRef}
      source={{ uri: imgUrl ?? img() }}
      resizeMode="cover"
      style={styles.bgImg}
    >
      <View
        style={{
          width: "100%",
          height: "100%",
          position: "absolute",
          top: 0,
          left: 0,
          backgroundColor: "rgba(0,0,0,.7)",
        }}
      />
      <View style={styles.contentContainer}>
        <Text style={styles.quote}>&#8220; {content} &#8221;</Text>
        <Text style={styles.author}>&mdash;{data}</Text>
      </View>
    </ImageBackground>

我尝试了很多解决方案,但没有人成功。

注意:我可以成功将组件保存为图库中的图像,这只是一个旁注。

此应用程序将仅用于 android 台设备。

提前致谢。

你一定是导入错了,我也是这样,我是这样导入的:

import Sharing from 'expo-sharing';

但正确的方法是这样的:

import * as Sharing from 'expo-sharing';