Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maskaravivek/978a29d9897fd5528c408365940dded8 to your computer and use it in GitHub Desktop.
Save maskaravivek/978a29d9897fd5528c408365940dded8 to your computer and use it in GitHub Desktop.
import { useRef } from "react";
import { View, Button } from "react-native";
import ViewShot from "react-native-view-shot";
import Share from "react-native-share";
import RNFS from "react-native-fs";
export default function MorgageCalculatorSummary() {
const ref = useRef();
const captureAndShareScreenshot = () => {
if (!ref || !ref.current) {
return;
}
ref.current.capture().then((uri: any) => {
RNFS.readFile(uri, "base64").then((res) => {
let urlString = "data:image/jpeg;base64," + res;
let options = {
title: "Share Title",
message: "Share Message",
url: urlString,
type: "image/jpeg",
};
Share.open(options)
.then((res) => {
console.log(res);
})
.catch((err) => {
err && console.log(err);
});
});
});
};
return (
<Box>
<Button
onPress={() => {
captureAndShareScreenshot();
}}
>
Share
</Button>
<ViewShot ref={ref}>
<View>
<Text>My custom view...</Text>
</View>
</ViewShot>
</Box>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment