mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
6b354155ed
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53002 Changelog: [Internal] Reviewed By: marcoww6 Differential Revision: D79524515 fbshipit-source-id: 18b96538a62c7ae5912b1e89d2b50c1420c7eaf5
77 lines
1.9 KiB
JavaScript
77 lines
1.9 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';
|
|
|
|
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
|
|
|
|
const ScreenshotManager = require('../../../NativeModuleExample/NativeScreenshotManager');
|
|
const {RNTesterThemeContext} = require('../../components/RNTesterTheme');
|
|
const React = require('react');
|
|
const {Alert, Image, StyleSheet, Text, View} = require('react-native');
|
|
|
|
class ScreenshotExample extends React.Component<{...}, $FlowFixMe> {
|
|
state: any | {uri: void} = {
|
|
uri: undefined,
|
|
};
|
|
|
|
render(): React.Node {
|
|
return (
|
|
<RNTesterThemeContext.Consumer>
|
|
{theme => (
|
|
<View style={style.container}>
|
|
<Text
|
|
onPress={this.takeScreenshot}
|
|
style={[style.button, {color: theme.LabelColor}]}>
|
|
Click to take a screenshot
|
|
</Text>
|
|
<Image
|
|
style={[style.image, {backgroundColor: theme.LabelColor}]}
|
|
source={{uri: this.state.uri}}
|
|
/>
|
|
</View>
|
|
)}
|
|
</RNTesterThemeContext.Consumer>
|
|
);
|
|
}
|
|
|
|
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',
|
|
},
|
|
});
|
|
|
|
exports.title = 'Snapshot / Screenshot';
|
|
exports.category = 'Basic';
|
|
exports.description = 'API to capture images from the screen.';
|
|
exports.examples = [
|
|
{
|
|
title: 'Take screenshot',
|
|
render(): React.MixedElement {
|
|
return <ScreenshotExample />;
|
|
},
|
|
},
|
|
] as Array<RNTesterModuleExample>;
|