Files
react-native/packages/rn-tester/js/examples/Snapshot/SnapshotExample.js
T
Pieter Vanderwerff ee3d3c248d Add missing class annotations xplat/js
Reviewed By: SamChou19815

Differential Revision: D38373443

fbshipit-source-id: 1222c4845ebd6b72bd6f54af1a27cf8542dd883a
2022-08-03 12:43:58 -07:00

66 lines
1.5 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const React = require('react');
const {Alert, Image, StyleSheet, Text, View} = require('react-native');
const ScreenshotManager = require('../../../NativeModuleExample/NativeScreenshotManager');
class ScreenshotExample extends React.Component<{...}, $FlowFixMeState> {
state: any | {uri: void} = {
uri: undefined,
};
render(): React.Node {
return (
<View style={style.container}>
<Text onPress={this.takeScreenshot} style={style.button}>
Click to take a screenshot
</Text>
<Image style={style.image} source={{uri: this.state.uri}} />
</View>
);
}
takeScreenshot = () => {
ScreenshotManager.takeScreenshot('window', {format: 'jpeg', quality: 0.8}) // See UIManager.js for options
.then(uri => this.setState({uri}))
.catch(error => Alert.alert(error));
};
}
const style = StyleSheet.create({
container: {
flex: 1,
},
button: {
marginBottom: 10,
fontWeight: '500',
},
image: {
flex: 1,
resizeMode: 'contain',
backgroundColor: 'black',
},
});
exports.title = 'Snapshot / Screenshot';
exports.category = 'Basic';
exports.description = 'API to capture images from the screen.';
exports.examples = [
{
title: 'Take screenshot',
render(): React.Element<any> {
return <ScreenshotExample />;
},
},
];