Clipboard #

Clipboard gives you an interface for setting and getting content from Clipboard on both iOS and Android

Methods #

static getString() #

Get content of string type, this method returns a Promise, so you can use following code to get clipboard content

async _getContent() { var content = await Clipboard.getString(); }

static setString(content) #

Set content of string type. You can use following code to set clipboard content

_setContent() { Clipboard.setString('hello world'); }

@param the content to be stored in the clipboard.

You can edit the content above on GitHub and send us a pull request!

Examples #

Edit on GitHub
'use strict'; var React = require('react'); var ReactNative = require('react-native'); var { Clipboard, View, Text, } = ReactNative; class ClipboardExample extends React.Component { state = { content: 'Content will appear here' }; _setClipboardContent = async () => { Clipboard.setString('Hello World'); try { var content = await Clipboard.getString(); this.setState({content}); } catch (e) { this.setState({content:e.message}); } }; render() { return ( <View> <Text onPress={this._setClipboardContent} style={{color: 'blue'}}> Tap to put "Hello World" in the clipboard </Text> <Text style={{color: 'red', marginTop: 20}}> {this.state.content} </Text> </View> ); } } exports.title = 'Clipboard'; exports.description = 'Show Clipboard contents.'; exports.examples = [ { title: 'Clipboard.setString() and getString()', render() { return <ClipboardExample/>; } } ];