How to take screenshot and share it in react native
Here we will take a screenshot of the screen or part of the screen and share it on the share api.
- installation : yarn add react-native-view-shot
- now import the plugin in your component
import ViewShot from ‘react-native-view-shot’;
- Now wrap the View or part you want to capture inside ViewShot
- here is the function used to fire screenshot api.
- .capture() function returns a promise with url of the screenshot present in cache.
Which we use further for our usecase such as sharing it directly.
- You can also omit the components you don’t want to show in the screenshot like here I have removed the share Button known as FAB and written outside of the view shot company. But its using absolute positioning to render above the view.
- Reference this for the code https://www.gkmit.co/blog/mobile-development/capture-and-share-screenshot-in-react-native