Fix SnapshotExample

Reviewed By: fkgozali

Differential Revision: D5327149

fbshipit-source-id: 685bd2f52b6457b03db2e49df67c9830dd6c102a
This commit is contained in:
Spencer Ahrens 2017-06-27 09:35:01 -07:00 committed by Facebook Github Bot
parent 22ab231c2e
commit 1a5489bb70
1 changed files with 12 additions and 16 deletions

View File

@ -8,18 +8,13 @@
*
* @flow
* @providesModule SnapshotExample
* @format
*/
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {
Image,
StyleSheet,
Text,
UIManager,
View,
} = ReactNative;
const React = require('react');
const ReactNative = require('react-native');
const {Alert, Image, StyleSheet, Text, View} = ReactNative;
class ScreenshotExample extends React.Component {
state = {
@ -32,20 +27,19 @@ class ScreenshotExample extends React.Component {
<Text onPress={this.takeScreenshot} style={style.button}>
Click to take a screenshot
</Text>
<Image style={style.image} source={{uri: this.state.uri}}/>
<Image style={style.image} source={{uri: this.state.uri}} />
</View>
);
}
takeScreenshot = () => {
UIManager
.takeSnapshot('window', {format: 'jpeg', quality: 0.8}) // See UIManager.js for options
.then((uri) => this.setState({uri}))
.catch((error) => alert(error));
ReactNative.takeSnapshot('window', {format: 'jpeg', quality: 0.8}) // See UIManager.js for options
.then(uri => this.setState({uri}))
.catch(error => Alert.alert(error));
};
}
var style = StyleSheet.create({
const style = StyleSheet.create({
button: {
marginBottom: 10,
fontWeight: '500',
@ -63,6 +57,8 @@ exports.description = 'API to capture images from the screen.';
exports.examples = [
{
title: 'Take screenshot',
render(): React.Element<any> { return <ScreenshotExample />; }
render(): React.Element<any> {
return <ScreenshotExample />;
},
},
];