2015-12-09 10:00:19 -08:00
|
|
|
/**
|
2018-09-11 15:27:47 -07:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-07-12 05:51:57 -07:00
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 05:51:57 -07:00
|
|
|
*
|
2018-05-11 13:32:37 -07:00
|
|
|
* @format
|
2018-08-09 08:32:04 -07:00
|
|
|
* @flow strict-local
|
2015-12-09 10:00:19 -08:00
|
|
|
*/
|
2018-05-11 13:32:37 -07:00
|
|
|
|
2015-12-09 10:00:19 -08:00
|
|
|
'use strict';
|
|
|
|
|
2018-10-30 14:26:13 -07:00
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
2018-11-08 17:17:26 -08:00
|
|
|
const {Clipboard, View, Text, StyleSheet} = ReactNative;
|
2015-12-09 10:00:19 -08:00
|
|
|
|
2018-12-31 08:26:00 -08:00
|
|
|
type Props = $ReadOnly<{||}>;
|
|
|
|
type State = {|
|
|
|
|
content: string,
|
|
|
|
|};
|
|
|
|
|
|
|
|
class ClipboardExample extends React.Component<Props, State> {
|
2016-07-26 01:00:02 -07:00
|
|
|
state = {
|
2018-05-11 13:32:37 -07:00
|
|
|
content: 'Content will appear here',
|
2016-07-26 01:00:02 -07:00
|
|
|
};
|
2016-01-21 09:48:47 -08:00
|
|
|
|
2016-07-26 01:00:02 -07:00
|
|
|
_setClipboardContent = async () => {
|
2015-12-09 10:00:19 -08:00
|
|
|
Clipboard.setString('Hello World');
|
2016-01-20 10:53:59 -08:00
|
|
|
try {
|
2018-10-30 14:26:13 -07:00
|
|
|
const content = await Clipboard.getString();
|
2015-12-09 10:00:19 -08:00
|
|
|
this.setState({content});
|
2016-01-20 10:53:59 -08:00
|
|
|
} catch (e) {
|
2018-05-11 13:32:37 -07:00
|
|
|
this.setState({content: e.message});
|
2016-01-20 10:53:59 -08:00
|
|
|
}
|
2016-07-26 01:00:02 -07:00
|
|
|
};
|
2016-01-21 09:48:47 -08:00
|
|
|
|
2015-12-09 10:00:19 -08:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
2018-11-08 17:17:26 -08:00
|
|
|
<Text onPress={this._setClipboardContent} style={styles.label}>
|
2015-12-09 10:00:19 -08:00
|
|
|
Tap to put "Hello World" in the clipboard
|
|
|
|
</Text>
|
2018-11-08 17:17:26 -08:00
|
|
|
<Text style={styles.content}>{this.state.content}</Text>
|
2015-12-09 10:00:19 -08:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 01:00:02 -07:00
|
|
|
}
|
2015-12-09 10:00:19 -08:00
|
|
|
|
2018-12-31 08:26:00 -08:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
label: {
|
|
|
|
color: 'blue',
|
|
|
|
},
|
|
|
|
content: {
|
|
|
|
color: 'red',
|
|
|
|
marginTop: 20,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-12-09 10:00:19 -08:00
|
|
|
exports.title = 'Clipboard';
|
|
|
|
exports.description = 'Show Clipboard contents.';
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Clipboard.setString() and getString()',
|
2016-01-20 10:53:59 -08:00
|
|
|
render() {
|
2018-05-11 13:32:37 -07:00
|
|
|
return <ClipboardExample />;
|
|
|
|
},
|
|
|
|
},
|
2015-12-09 10:00:19 -08:00
|
|
|
];
|