Created
June 26, 2023 04:06
-
-
Save maskaravivek/978a29d9897fd5528c408365940dded8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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