Created
December 9, 2022 15:30
-
-
Save nympheastudio/6915895c8349c3da9a5c287128344405 to your computer and use it in GitHub Desktop.
The height, width, and quality options can be adjusted to control the size and quality of the screenshot.
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 React from 'react'; | |
import { View, Button, Alert } from 'react-native'; | |
import { takeSnapshotAsync } from 'expo'; | |
class ScreenshotExample extends React.Component { | |
takeScreenshot = async () => { | |
try { | |
const result = await takeSnapshotAsync(this.view, { | |
result: 'file', | |
height: 500, | |
width: 300, | |
quality: 0.5 | |
}); | |
Alert.alert('Screenshot saved to', result); | |
} catch (error) { | |
Alert.alert('Oops, something went wrong!', error.message); | |
} | |
}; | |
render() { | |
return ( | |
<View ref={view => (this.view = view)}> | |
<Button onPress={this.takeScreenshot} title="Take Screenshot" /> | |
</View> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment