Gathering detailed insights and metrics for @react-native-clipboard/clipboard
Gathering detailed insights and metrics for @react-native-clipboard/clipboard
Gathering detailed insights and metrics for @react-native-clipboard/clipboard
Gathering detailed insights and metrics for @react-native-clipboard/clipboard
react-native-web-clipboard
This is a web compatibility layer that should be used with `@react-native-clipboard/clipboard` via a webpack alias sor something similar.
react-copy-to-clipboard
Copy-to-clipboard React component
expo-clipboard
Provides an interface for getting and setting Clipboard content on Android, iOS and Web.
clipboardy
Access the system clipboard (copy/paste)
React Native Clipboard API for both iOS and Android.
npm install @react-native-clipboard/clipboard
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
702 Stars
228 Commits
145 Forks
7 Watching
14 Branches
47 Contributors
Updated on 27 Nov 2024
TypeScript (28.18%)
C++ (24.94%)
Java (22.01%)
Objective-C++ (12.83%)
JavaScript (4.53%)
Ruby (3.47%)
Objective-C (2.73%)
Starlark (1.12%)
C (0.19%)
Cumulative downloads
Total Downloads
Last day
-1.1%
58,763
Compared to previous day
Last week
0.9%
286,764
Compared to previous week
Last month
8.9%
1,237,502
Compared to previous month
Last year
62.6%
12,345,915
Compared to previous year
4
20
React Native Clipboard API for macOS, iOS, Android, and Windows.
macOS | iOS | Android | Windows |
---|---|---|---|
Install the library using either Yarn:
yarn add @react-native-clipboard/clipboard
or npm:
npm install --save @react-native-clipboard/clipboard
For iOS, use cocoapods
to link the package.
run the following command:
$ npx pod-install
For android, the package will be linked automatically on build.
run the following command to link the package:
$ react-native link @react-native-clipboard/clipboard
For iOS, make sure you install the pod file.
cd ios && pod install && cd ..
or you could follow the instructions to manually link the project
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-clipboard/clipboard
react-native
moduleThis module was created when the Clipboard API 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:
1import {Clipboard} from 'react-native';
to:
1import Clipboard from '@react-native-clipboard/clipboard';
1import React, {useState} from 'react'; 2import { 3 SafeAreaView, 4 View, 5 Text, 6 TouchableOpacity, 7 StyleSheet, 8} from 'react-native'; 9import Clipboard from '@react-native-clipboard/clipboard'; 10 11const App = () => { 12 const [copiedText, setCopiedText] = useState(''); 13 14 const copyToClipboard = () => { 15 Clipboard.setString('hello world'); 16 }; 17 18 const fetchCopiedText = async () => { 19 const text = await Clipboard.getString(); 20 setCopiedText(text); 21 }; 22 23 return ( 24 <SafeAreaView style={{flex: 1}}> 25 <View style={styles.container}> 26 <TouchableOpacity onPress={copyToClipboard}> 27 <Text>Click here to copy to Clipboard</Text> 28 </TouchableOpacity> 29 <TouchableOpacity onPress={fetchCopiedText}> 30 <Text>View copied text</Text> 31 </TouchableOpacity> 32 33 <Text style={styles.copiedText}>{copiedText}</Text> 34 </View> 35 </SafeAreaView> 36 ); 37}; 38 39const styles = StyleSheet.create({ 40 container: { 41 flex: 1, 42 justifyContent: 'center', 43 alignItems: 'center', 44 }, 45 copiedText: { 46 marginTop: 10, 47 color: 'red', 48 }, 49}); 50 51export default App;
getString()
1static getString()
Get content of string type, this method returns a Promise
, so you can use following code to get clipboard content
1async _getContent() { 2 var content = await Clipboard.getString(); 3}
getStrings()
1static getStrings()
(iOS only)
Get contents of string array type, this method returns a Promise
, so you can use following code to get clipboard content
1async _getContent() { 2 var content = await Clipboard.getStrings(); 3}
setString()
1static setString(content)
Set content of string type. You can use following code to set clipboard content
1_setContent() {
2 Clipboard.setString('hello world');
3}
Name | Type | Required | Description |
---|---|---|---|
content | string | Yes | The content to be stored in the clipboard |
setStrings()
1static setStrings(content)
(iOS only) Set content of string array type. You can use following code to set clipboard content
1_setContent() {
2 Clipboard.setStrings(['hello world', 'second string']);
3}
Name | Type | Required | Description |
---|---|---|---|
content | string[] | Yes | The content to be stored in the clipboard |
hasString()
1static hasString()
Returns whether the clipboard has content or is empty. Can check if there is a content in clipboard without triggering PasteBoard notification for iOS 14+
hasURL()
1static hasURL()
(iOS only) Returns whether the clipboard has a URL content. Can check if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+
hasNumber()
1static hasNumber()
(iOS 14+ only) Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
hasWebURL()
1static hasWebURL()
(iOS 14+ only) Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
useClipboard
is a utility hooks for the Clipboard
module. data
contains the content stored in the clipboard.
1import React, {useEffect} from 'react'; 2import {Text} from 'react-native'; 3import {useClipboard} from '@react-native-clipboard/clipboard'; 4 5export const HooksSample = () => { 6 const [data, setString] = useClipboard(); 7 8 useEffect(() => { 9 setString('hello world'); 10 }, []); 11 12 return <Text>{data}</Text>; 13};
getImage()
1static getImage()
Get content of image in base64 string type, this method returns a Promise
, so you can use following code to get clipboard content (iOS and Android Only)
1async _getContent() { 2 var content = await Clipboard.getImage(); 3}
If you're using jest
as a test runner, you will need to setup a mock for clipboard, as NativeModules will be undefined when testing with Jest.
Create a jest.setup.js
in your project root,and set up the following to have Clipboard mocked:
1import mockClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock.js'; 2 3jest.mock('@react-native-clipboard/clipboard', () => mockClipboard);
Please see the contributing guide
.
The library is released under the MIT licence. For more information see LICENSE
.
No vulnerabilities found.
Reason
15 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
2 existing vulnerabilities detected
Details
Reason
Found 12/23 approved changesets -- score normalized to 5
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More