schiewe / react-native-clipboard

React Native Clipboard API for both iOS and Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@react-native-community/clipboard

Build Status Version Supports iOS and Android MIT License Lean Core Badge

React Native Clipboard API for both iOS and Android

iOS Android

Getting started

Install the library using either Yarn:

yarn add @react-native-community/clipboard

or npm:

npm install --save @react-native-community/clipboard

Link

  • React Native v0.60+

For iOS, use cocoapods to link the package.

run the following command:

$ cd ios && pod install

For android, the package will be linked automatically on build.

  • React Native <= 0.59

run the following command to link the package:

$ react-native link @react-native-community/clipboard

or you could follow the instructions to manually link the project

Upgrading to React Native 0.60+

New React Native comes with autolinking feature, which automatically links Native Modules in your project. In order to get it to work, make sure you unlink Clipboard first:

$ react-native unlink @react-native-community/clipboard

Migrating from the core react-native module

This module was created when the NetInfo was split out from the core of React Native. To migrate to this module you need to follow the installation instructions above and then change you imports from:

import { Clipboard } from "react-native";

to:

import Clipboard from "@react-native-community/clipboard";

Usage

Start by importing the library:

import Clipboard from "@react-native-community/clipboard";

type Props = $ReadOnly<{||}>;
type State = {|
  clipboardContent: string,
|};

export default class App extends React.Component<Props, State> {
  state = {
    clipboardContent: 'The state variable which contains Clipboard Content',
  };

  readFromClipboard = async () => {
    const content = await Clipboard.getString();
    this.setState({clipboardContent: content});
  };

  writeToClipboard = async () => {
    Clipboard.setString(this.state.text);
    alert('Copied to clipboard');
  };
}

Maintainers

Contributing

Please see the contributing guide.

License

The library is released under the MIT licence. For more information see LICENSE.

About

React Native Clipboard API for both iOS and Android.

License:MIT License


Languages

Language:Java 26.5%Language:JavaScript 25.0%Language:Objective-C 24.4%Language:Ruby 17.2%Language:Starlark 6.8%