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

Viewed 209

I have built an application where I want to share a component as an image. I am doing it like so.

 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!");
}

};

But I am getting this error.

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

the component that I want to share as an image.

 <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>

I have tried many solutions but no one did the trick.

Note: I am able to save the component as an image in the gallery successfully, It is just a side note.

This application will be used only for android devices.

Thanks In advance.

1 Answers

You must be importing the lib wrong, the same happened to me, I was importing like this:

import Sharing from 'expo-sharing';

but the right way is this:

import * as Sharing from 'expo-sharing';
Related