Skip to content

Instantly share code, notes, and snippets.

@nympheastudio
Created December 9, 2022 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nympheastudio/6915895c8349c3da9a5c287128344405 to your computer and use it in GitHub Desktop.
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.
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