2016-02-23 10:26:11 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2016-02-23 10:26:11 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule SnapshotExample
|
2016-02-23 10:26:11 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2016-02-23 10:26:11 +00:00
|
|
|
var {
|
|
|
|
Image,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
UIManager,
|
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2016-02-23 10:26:11 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
class ScreenshotExample extends React.Component {
|
|
|
|
state = {
|
|
|
|
uri: undefined,
|
|
|
|
};
|
2016-02-23 10:26:11 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text onPress={this.takeScreenshot} style={style.button}>
|
|
|
|
Click to take a screenshot
|
|
|
|
</Text>
|
|
|
|
<Image style={style.image} source={{uri: this.state.uri}}/>
|
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2016-02-23 10:26:11 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
takeScreenshot = () => {
|
2016-02-23 10:26:11 +00:00
|
|
|
UIManager
|
2016-02-24 17:05:28 +00:00
|
|
|
.takeSnapshot('window', {format: 'jpeg', quality: 0.8}) // See UIManager.js for options
|
2016-02-23 10:26:11 +00:00
|
|
|
.then((uri) => this.setState({uri}))
|
|
|
|
.catch((error) => alert(error));
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
}
|
2016-02-23 10:26:11 +00:00
|
|
|
|
|
|
|
var style = StyleSheet.create({
|
|
|
|
button: {
|
|
|
|
marginBottom: 10,
|
|
|
|
fontWeight: '500',
|
|
|
|
},
|
|
|
|
image: {
|
|
|
|
flex: 1,
|
|
|
|
height: 300,
|
|
|
|
resizeMode: 'contain',
|
|
|
|
backgroundColor: 'black',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
exports.title = 'Snapshot / Screenshot';
|
|
|
|
exports.description = 'API to capture images from the screen.';
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Take screenshot',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> { return <ScreenshotExample />; }
|
2016-02-23 10:26:11 +00:00
|
|
|
},
|
|
|
|
];
|