mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
Return a Promise for Clipboard.getString()
Summary:
For clipboard, add error callback in Android. Code like
```javascript
Clipboard.getString((content)=>{
//do something
},(error)=>{
//do something for error
})
```
Closes https://github.com/facebook/react-native/pull/4792
Reviewed By: svcscm
Differential Revision: D2844937
Pulled By: nicklockwood
fb-gh-sync-id: 19953807ff07238e6a6ef5aedf1a3fcbca7e62a1
This commit is contained in:
committed by
facebook-github-bot-5
parent
1dffd056bf
commit
15f806957f
@@ -23,23 +23,25 @@ var {
|
||||
} = React;
|
||||
|
||||
var ClipboardExample = React.createClass({
|
||||
getInitialState: function() {
|
||||
getInitialState() {
|
||||
return {
|
||||
content: 'Content will appear here'
|
||||
};
|
||||
},
|
||||
|
||||
_setContentToClipboard:function(){
|
||||
async _setClipboardContent(){
|
||||
Clipboard.setString('Hello World');
|
||||
Clipboard.getString(content => {
|
||||
try {
|
||||
var content = await Clipboard.getString();
|
||||
this.setState({content});
|
||||
});
|
||||
} catch (e) {
|
||||
this.setState({content:e.message});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View>
|
||||
<Text onPress={this._setContentToClipboard} style={{color: 'blue'}}>
|
||||
<Text onPress={this._setClipboardContent} style={{color: 'blue'}}>
|
||||
Tap to put "Hello World" in the clipboard
|
||||
</Text>
|
||||
<Text style={{color: 'red', marginTop: 20}}>
|
||||
@@ -55,6 +57,8 @@ exports.description = 'Show Clipboard contents.';
|
||||
exports.examples = [
|
||||
{
|
||||
title: 'Clipboard.setString() and getString()',
|
||||
render(): ReactElement { return <ClipboardExample />; }
|
||||
render() {
|
||||
return <ClipboardExample/>;
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user