@react-native-clipboard/clipboard 1.12.1 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RNCClipboard.podspec +18 -2
- package/android/build.gradle +67 -1
- package/android/src/main/java/com/reactnativecommunity/clipboard/ClipboardModule.java +52 -1
- package/android/src/main/java/com/reactnativecommunity/clipboard/ClipboardPackage.java +89 -3
- package/android/src/paper/java/com/reactnativecommunity/clipboard/NativeClipboardModuleSpec.java +96 -0
- package/dist/Clipboard.js +16 -16
- package/dist/NativeClipboardModule.d.ts +147 -0
- package/dist/NativeClipboardModule.js +44 -0
- package/ios/RNCClipboard.h +12 -2
- package/ios/{RNCClipboard.m → RNCClipboard.mm} +19 -0
- package/macos/RNCClipboard.m +8 -0
- package/package.json +5 -4
- package/src/Clipboard.ts +208 -0
- package/src/Clipboard.web.ts +37 -0
- package/src/NativeClipboardModule.ts +201 -0
- package/src/index.ts +3 -0
- package/src/useClipboard.ts +35 -0
package/RNCClipboard.podspec
CHANGED
|
@@ -2,6 +2,8 @@ require 'json'
|
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
4
|
|
|
5
|
+
fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
|
|
6
|
+
|
|
5
7
|
Pod::Spec.new do |s|
|
|
6
8
|
s.name = "RNCClipboard"
|
|
7
9
|
s.version = package['version']
|
|
@@ -10,11 +12,25 @@ Pod::Spec.new do |s|
|
|
|
10
12
|
|
|
11
13
|
s.authors = package['author']
|
|
12
14
|
s.homepage = package['homepage']
|
|
13
|
-
s.platforms = { :ios => "9.0", :osx => "10.14" }
|
|
14
15
|
|
|
15
16
|
s.source = { :git => "https://github.com/react-native-clipboard/clipboard", :tag => "v#{s.version}" }
|
|
16
17
|
s.ios.source_files = "ios/**/*.{h,m,mm}"
|
|
17
18
|
s.osx.source_files = "macos/**/*.{h,m,mm}"
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
if fabric_enabled
|
|
21
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
22
|
+
|
|
23
|
+
s.pod_target_xcconfig = {
|
|
24
|
+
'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly"',
|
|
25
|
+
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
|
|
26
|
+
}
|
|
27
|
+
s.platforms = { ios: '11.0', tvos: '11.0' }
|
|
28
|
+
s.compiler_flags = folly_compiler_flags + ' -DRCT_NEW_ARCH_ENABLED'
|
|
29
|
+
|
|
30
|
+
install_modules_dependencies(s)
|
|
31
|
+
else
|
|
32
|
+
s.platforms = { :ios => "9.0", :tvos => "9.0" }
|
|
33
|
+
|
|
34
|
+
s.dependency "React-Core"
|
|
35
|
+
end
|
|
20
36
|
end
|
package/android/build.gradle
CHANGED
|
@@ -19,13 +19,75 @@ def getExtOrIntegerDefault(name) {
|
|
|
19
19
|
|
|
20
20
|
apply plugin: 'com.android.library'
|
|
21
21
|
|
|
22
|
+
def resolveReactNativeDirectory() {
|
|
23
|
+
// monorepo workaround
|
|
24
|
+
// react-native can be hoisted or in project's own node_modules
|
|
25
|
+
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
|
|
26
|
+
if (reactNativeFromProjectNodeModules.exists()) {
|
|
27
|
+
return reactNativeFromProjectNodeModules
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def reactNativeFromNodeModulesWithLibrary = file("${projectDir}/../../react-native")
|
|
31
|
+
if (reactNativeFromNodeModulesWithLibrary.exists()) {
|
|
32
|
+
return reactNativeFromNodeModulesWithLibrary
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw new Exception(
|
|
36
|
+
"[react-native-clipboard] Unable to resolve react-native location in " +
|
|
37
|
+
"node_modules. You should add project extension property (in app/build.gradle) " +
|
|
38
|
+
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
def REACT_NATIVE_DIR = resolveReactNativeDirectory()
|
|
43
|
+
|
|
44
|
+
def reactProperties = new Properties()
|
|
45
|
+
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
|
46
|
+
|
|
47
|
+
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
|
|
48
|
+
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
|
|
49
|
+
|
|
50
|
+
def isNewArchitectureEnabled() {
|
|
51
|
+
// To opt-in for the New Architecture, you can either:
|
|
52
|
+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
|
|
53
|
+
// - Invoke gradle with `-newArchEnabled=true`
|
|
54
|
+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
|
|
55
|
+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (isNewArchitectureEnabled()) {
|
|
59
|
+
apply plugin: "com.facebook.react"
|
|
60
|
+
}
|
|
61
|
+
|
|
22
62
|
android {
|
|
63
|
+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
64
|
+
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
|
|
65
|
+
namespace "com.reactnativecommunity.clipboard"
|
|
66
|
+
}
|
|
67
|
+
|
|
23
68
|
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
|
|
24
69
|
|
|
70
|
+
// Used to override the NDK path/version on internal CI or by allowing
|
|
71
|
+
// users to customize the NDK path/version from their root project (e.g. for M1 support)
|
|
72
|
+
if (rootProject.hasProperty("ndkPath")) {
|
|
73
|
+
ndkPath rootProject.ext.ndkPath
|
|
74
|
+
}
|
|
75
|
+
if (rootProject.hasProperty("ndkVersion")) {
|
|
76
|
+
ndkVersion rootProject.ext.ndkVersion
|
|
77
|
+
}
|
|
78
|
+
|
|
25
79
|
defaultConfig {
|
|
26
80
|
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
|
|
27
81
|
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
|
|
28
82
|
}
|
|
83
|
+
|
|
84
|
+
sourceSets.main {
|
|
85
|
+
java {
|
|
86
|
+
if (!isNewArchitectureEnabled()) {
|
|
87
|
+
srcDirs += 'src/paper/java'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
29
91
|
}
|
|
30
92
|
|
|
31
93
|
repositories {
|
|
@@ -35,5 +97,9 @@ repositories {
|
|
|
35
97
|
|
|
36
98
|
dependencies {
|
|
37
99
|
//noinspection GradleDynamicVersion
|
|
38
|
-
|
|
100
|
+
if (isNewArchitectureEnabled() && REACT_NATIVE_MINOR_VERSION < 71) {
|
|
101
|
+
implementation project(":ReactAndroid")
|
|
102
|
+
} else {
|
|
103
|
+
implementation 'com.facebook.react:react-native:+'
|
|
104
|
+
}
|
|
39
105
|
}
|
|
@@ -24,6 +24,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
|
|
24
24
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
25
25
|
import com.facebook.react.bridge.ReactMethod;
|
|
26
26
|
import com.facebook.react.bridge.Promise;
|
|
27
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
27
28
|
import com.facebook.react.module.annotations.ReactModule;
|
|
28
29
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
29
30
|
|
|
@@ -35,7 +36,7 @@ import java.nio.ByteBuffer;
|
|
|
35
36
|
* A module that allows JS to get/set clipboard contents.
|
|
36
37
|
*/
|
|
37
38
|
@ReactModule(name = ClipboardModule.NAME)
|
|
38
|
-
public class ClipboardModule extends
|
|
39
|
+
public class ClipboardModule extends NativeClipboardModuleSpec {
|
|
39
40
|
|
|
40
41
|
public static final String CLIPBOARD_TEXT_CHANGED = "RNCClipboard_TEXT_CHANGED";
|
|
41
42
|
private ReactApplicationContext reactContext;
|
|
@@ -79,6 +80,26 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
@Override
|
|
84
|
+
public void getStrings(Promise promise) {
|
|
85
|
+
promise.reject("Clipboard:getStrings", "getStrings is not supported on Android");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Override
|
|
89
|
+
public void getImagePNG(Promise promise) {
|
|
90
|
+
promise.reject("Clipboard:getImagePNG", "getImagePNG is not supported on Android");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Override
|
|
94
|
+
public void getImageJPG(Promise promise) {
|
|
95
|
+
promise.reject("Clipboard:getImageJPG", "getImageJPG is not supported on Android");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Override
|
|
99
|
+
public void setImage(String content, Promise promise) {
|
|
100
|
+
promise.reject("Clipboard:setImage", "setImage is not supported on Android");
|
|
101
|
+
}
|
|
102
|
+
|
|
82
103
|
@ReactMethod
|
|
83
104
|
public void setString(String text) {
|
|
84
105
|
try {
|
|
@@ -90,6 +111,11 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
|
|
90
111
|
}
|
|
91
112
|
}
|
|
92
113
|
|
|
114
|
+
@Override
|
|
115
|
+
public void setStrings(ReadableArray content) {
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
93
119
|
@ReactMethod
|
|
94
120
|
public void hasString(Promise promise) {
|
|
95
121
|
try {
|
|
@@ -101,6 +127,26 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
|
|
101
127
|
}
|
|
102
128
|
}
|
|
103
129
|
|
|
130
|
+
@Override
|
|
131
|
+
public void hasImage(Promise promise) {
|
|
132
|
+
promise.reject("Clipboard:hasImage", "hasImage is not supported on Android");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@Override
|
|
136
|
+
public void hasURL(Promise promise) {
|
|
137
|
+
promise.reject("Clipboard:hasURL", "hasURL is not supported on Android");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@Override
|
|
141
|
+
public void hasNumber(Promise promise) {
|
|
142
|
+
promise.reject("Clipboard:hasNumber", "hasNumber is not supported on Android");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@Override
|
|
146
|
+
public void hasWebURL(Promise promise) {
|
|
147
|
+
promise.reject("Clipboard:hasWebURL", "hasWebURL is not supported on Android");
|
|
148
|
+
}
|
|
149
|
+
|
|
104
150
|
@ReactMethod
|
|
105
151
|
public void getImage(Promise promise){
|
|
106
152
|
ClipboardManager clipboardManager = getClipboardService();
|
|
@@ -191,6 +237,11 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
|
|
191
237
|
// Keep: Required for RN built in Event Emitter Calls.
|
|
192
238
|
}
|
|
193
239
|
|
|
240
|
+
@Override
|
|
241
|
+
public void removeListeners(double count) {
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
194
245
|
@ReactMethod
|
|
195
246
|
public void removeListeners(Integer count) {
|
|
196
247
|
// Keep: Required for RN built in Event Emitter Calls.
|
|
@@ -1,16 +1,103 @@
|
|
|
1
1
|
package com.reactnativecommunity.clipboard;
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.TurboReactPackage;
|
|
6
|
+
import com.facebook.react.ViewManagerOnDemandReactPackage;
|
|
7
|
+
import com.facebook.react.bridge.ModuleSpec;
|
|
4
8
|
import com.facebook.react.bridge.NativeModule;
|
|
5
9
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
11
|
+
import com.facebook.react.module.annotations.ReactModuleList;
|
|
12
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
13
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
14
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
|
6
15
|
import com.facebook.react.uimanager.ViewManager;
|
|
7
16
|
|
|
8
17
|
import java.util.ArrayList;
|
|
9
18
|
import java.util.Collections;
|
|
19
|
+
import java.util.HashMap;
|
|
10
20
|
import java.util.List;
|
|
21
|
+
import java.util.Map;
|
|
22
|
+
|
|
23
|
+
import javax.annotation.Nonnull;
|
|
24
|
+
|
|
25
|
+
@ReactModuleList(
|
|
26
|
+
nativeModules = {
|
|
27
|
+
ClipboardModule.class,
|
|
28
|
+
})
|
|
29
|
+
public class ClipboardPackage extends TurboReactPackage implements ViewManagerOnDemandReactPackage {
|
|
30
|
+
|
|
31
|
+
/** {@inheritDoc} */
|
|
32
|
+
@Override
|
|
33
|
+
public List<String> getViewManagerNames(ReactApplicationContext reactContext) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
11
36
|
|
|
12
|
-
|
|
37
|
+
@Override
|
|
38
|
+
protected List<ModuleSpec> getViewManagers(ReactApplicationContext reactContext) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** {@inheritDoc} */
|
|
43
|
+
@Override
|
|
44
|
+
public @Nullable ViewManager createViewManager(
|
|
45
|
+
ReactApplicationContext reactContext, String viewManagerName) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
13
48
|
|
|
49
|
+
@Override
|
|
50
|
+
public NativeModule getModule(String name, @Nonnull ReactApplicationContext reactContext) {
|
|
51
|
+
switch (name) {
|
|
52
|
+
case ClipboardModule.NAME:
|
|
53
|
+
return new ClipboardModule(reactContext);
|
|
54
|
+
default:
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Override
|
|
60
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
61
|
+
try {
|
|
62
|
+
Class<?> reactModuleInfoProviderClass =
|
|
63
|
+
Class.forName("com.reactnativecommunity.clipboard.ClipboardPackage$$ReactModuleInfoProvider");
|
|
64
|
+
return (ReactModuleInfoProvider) reactModuleInfoProviderClass.newInstance();
|
|
65
|
+
} catch (ClassNotFoundException e) {
|
|
66
|
+
// ReactModuleSpecProcessor does not run at build-time. Create this ReactModuleInfoProvider by
|
|
67
|
+
// hand.
|
|
68
|
+
return new ReactModuleInfoProvider() {
|
|
69
|
+
@Override
|
|
70
|
+
public Map<String, ReactModuleInfo> getReactModuleInfos() {
|
|
71
|
+
final Map<String, ReactModuleInfo> reactModuleInfoMap = new HashMap<>();
|
|
72
|
+
|
|
73
|
+
Class<? extends NativeModule>[] moduleList =
|
|
74
|
+
new Class[] {
|
|
75
|
+
ClipboardModule.class,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
for (Class<? extends NativeModule> moduleClass : moduleList) {
|
|
79
|
+
ReactModule reactModule = moduleClass.getAnnotation(ReactModule.class);
|
|
80
|
+
|
|
81
|
+
reactModuleInfoMap.put(
|
|
82
|
+
reactModule.name(),
|
|
83
|
+
new ReactModuleInfo(
|
|
84
|
+
reactModule.name(),
|
|
85
|
+
moduleClass.getName(),
|
|
86
|
+
reactModule.canOverrideExistingModule(),
|
|
87
|
+
reactModule.needsEagerInit(),
|
|
88
|
+
reactModule.hasConstants(),
|
|
89
|
+
reactModule.isCxxModule(),
|
|
90
|
+
TurboModule.class.isAssignableFrom(moduleClass)));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return reactModuleInfoMap;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
} catch (InstantiationException | IllegalAccessException e) {
|
|
97
|
+
throw new RuntimeException(
|
|
98
|
+
"No ReactModuleInfoProvider for com.reactnativecommunity.clipboard.ClipboardPackage$$ReactModuleInfoProvider", e);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
14
101
|
@Override
|
|
15
102
|
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
16
103
|
return Collections.emptyList();
|
|
@@ -24,5 +111,4 @@ public class ClipboardPackage implements ReactPackage {
|
|
|
24
111
|
|
|
25
112
|
return modules;
|
|
26
113
|
}
|
|
27
|
-
|
|
28
114
|
}
|
package/android/src/paper/java/com/reactnativecommunity/clipboard/NativeClipboardModuleSpec.java
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateModuleJavaSpec.js
|
|
9
|
+
*
|
|
10
|
+
* @nolint
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
package com.reactnativecommunity.clipboard;
|
|
14
|
+
|
|
15
|
+
import com.facebook.proguard.annotations.DoNotStrip;
|
|
16
|
+
import com.facebook.react.bridge.Promise;
|
|
17
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
18
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
19
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
20
|
+
import com.facebook.react.bridge.ReactModuleWithSpec;
|
|
21
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
22
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
|
23
|
+
|
|
24
|
+
public abstract class NativeClipboardModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
|
|
25
|
+
public NativeClipboardModuleSpec(ReactApplicationContext reactContext) {
|
|
26
|
+
super(reactContext);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@ReactMethod
|
|
30
|
+
@DoNotStrip
|
|
31
|
+
public abstract void getString(Promise promise);
|
|
32
|
+
|
|
33
|
+
@ReactMethod
|
|
34
|
+
@DoNotStrip
|
|
35
|
+
public abstract void getStrings(Promise promise);
|
|
36
|
+
|
|
37
|
+
@ReactMethod
|
|
38
|
+
@DoNotStrip
|
|
39
|
+
public abstract void getImagePNG(Promise promise);
|
|
40
|
+
|
|
41
|
+
@ReactMethod
|
|
42
|
+
@DoNotStrip
|
|
43
|
+
public abstract void getImageJPG(Promise promise);
|
|
44
|
+
|
|
45
|
+
@ReactMethod
|
|
46
|
+
@DoNotStrip
|
|
47
|
+
public abstract void setImage(String content, Promise promise);
|
|
48
|
+
|
|
49
|
+
@ReactMethod
|
|
50
|
+
@DoNotStrip
|
|
51
|
+
public abstract void getImage(Promise promise);
|
|
52
|
+
|
|
53
|
+
@ReactMethod
|
|
54
|
+
@DoNotStrip
|
|
55
|
+
public abstract void setString(String content);
|
|
56
|
+
|
|
57
|
+
@ReactMethod
|
|
58
|
+
@DoNotStrip
|
|
59
|
+
public abstract void setStrings(ReadableArray content);
|
|
60
|
+
|
|
61
|
+
@ReactMethod
|
|
62
|
+
@DoNotStrip
|
|
63
|
+
public abstract void hasString(Promise promise);
|
|
64
|
+
|
|
65
|
+
@ReactMethod
|
|
66
|
+
@DoNotStrip
|
|
67
|
+
public abstract void hasImage(Promise promise);
|
|
68
|
+
|
|
69
|
+
@ReactMethod
|
|
70
|
+
@DoNotStrip
|
|
71
|
+
public abstract void hasURL(Promise promise);
|
|
72
|
+
|
|
73
|
+
@ReactMethod
|
|
74
|
+
@DoNotStrip
|
|
75
|
+
public abstract void hasNumber(Promise promise);
|
|
76
|
+
|
|
77
|
+
@ReactMethod
|
|
78
|
+
@DoNotStrip
|
|
79
|
+
public abstract void hasWebURL(Promise promise);
|
|
80
|
+
|
|
81
|
+
@ReactMethod
|
|
82
|
+
@DoNotStrip
|
|
83
|
+
public abstract void setListener();
|
|
84
|
+
|
|
85
|
+
@ReactMethod
|
|
86
|
+
@DoNotStrip
|
|
87
|
+
public abstract void removeListener();
|
|
88
|
+
|
|
89
|
+
@ReactMethod
|
|
90
|
+
@DoNotStrip
|
|
91
|
+
public abstract void addListener(String eventName);
|
|
92
|
+
|
|
93
|
+
@ReactMethod
|
|
94
|
+
@DoNotStrip
|
|
95
|
+
public abstract void removeListeners(double count);
|
|
96
|
+
}
|
package/dist/Clipboard.js
CHANGED
|
@@ -21,7 +21,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.Clipboard = void 0;
|
|
23
23
|
var react_native_1 = require("react-native");
|
|
24
|
-
var
|
|
24
|
+
var NativeClipboardModule_1 = __importStar(require("./NativeClipboardModule"));
|
|
25
25
|
/**
|
|
26
26
|
* `Clipboard` gives you an interface for setting and getting content from Clipboard on both iOS and Android
|
|
27
27
|
*/
|
|
@@ -35,7 +35,7 @@ exports.Clipboard = {
|
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
getString: function () {
|
|
38
|
-
return
|
|
38
|
+
return NativeClipboardModule_1.default.getString();
|
|
39
39
|
},
|
|
40
40
|
/**
|
|
41
41
|
* (iOS Only)
|
|
@@ -47,7 +47,7 @@ exports.Clipboard = {
|
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
49
|
getStrings: function () {
|
|
50
|
-
return
|
|
50
|
+
return NativeClipboardModule_1.default.getStrings();
|
|
51
51
|
},
|
|
52
52
|
/**
|
|
53
53
|
* Get clipboard image as PNG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
@@ -58,7 +58,7 @@ exports.Clipboard = {
|
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
60
|
getImagePNG: function () {
|
|
61
|
-
return
|
|
61
|
+
return NativeClipboardModule_1.default.getImagePNG();
|
|
62
62
|
},
|
|
63
63
|
/**
|
|
64
64
|
* Get clipboard image as JPG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
@@ -69,7 +69,7 @@ exports.Clipboard = {
|
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
71
|
getImageJPG: function () {
|
|
72
|
-
return
|
|
72
|
+
return NativeClipboardModule_1.default.getImageJPG();
|
|
73
73
|
},
|
|
74
74
|
/**
|
|
75
75
|
* (iOS Only)
|
|
@@ -85,7 +85,7 @@ exports.Clipboard = {
|
|
|
85
85
|
if (react_native_1.Platform.OS !== 'ios') {
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
NativeClipboardModule_1.default.setImage(content);
|
|
89
89
|
},
|
|
90
90
|
/**
|
|
91
91
|
* (Android Only)
|
|
@@ -97,7 +97,7 @@ exports.Clipboard = {
|
|
|
97
97
|
* ```
|
|
98
98
|
*/
|
|
99
99
|
getImage: function () {
|
|
100
|
-
return
|
|
100
|
+
return NativeClipboardModule_1.default.getImage();
|
|
101
101
|
},
|
|
102
102
|
/**
|
|
103
103
|
* Set content of string type. You can use following code to set clipboard content
|
|
@@ -109,7 +109,7 @@ exports.Clipboard = {
|
|
|
109
109
|
* @param the content to be stored in the clipboard.
|
|
110
110
|
*/
|
|
111
111
|
setString: function (content) {
|
|
112
|
-
|
|
112
|
+
NativeClipboardModule_1.default.setString(content);
|
|
113
113
|
},
|
|
114
114
|
/**
|
|
115
115
|
* Set content of string array type. You can use following code to set clipboard content
|
|
@@ -121,7 +121,7 @@ exports.Clipboard = {
|
|
|
121
121
|
* @param the content to be stored in the clipboard.
|
|
122
122
|
*/
|
|
123
123
|
setStrings: function (content) {
|
|
124
|
-
|
|
124
|
+
NativeClipboardModule_1.default.setStrings(content);
|
|
125
125
|
},
|
|
126
126
|
/**
|
|
127
127
|
* Returns whether the clipboard has content or is empty.
|
|
@@ -133,7 +133,7 @@ exports.Clipboard = {
|
|
|
133
133
|
* ```
|
|
134
134
|
*/
|
|
135
135
|
hasString: function () {
|
|
136
|
-
return
|
|
136
|
+
return NativeClipboardModule_1.default.hasString();
|
|
137
137
|
},
|
|
138
138
|
/**
|
|
139
139
|
* Returns whether the clipboard has an image or is empty.
|
|
@@ -145,7 +145,7 @@ exports.Clipboard = {
|
|
|
145
145
|
* ```
|
|
146
146
|
*/
|
|
147
147
|
hasImage: function () {
|
|
148
|
-
return
|
|
148
|
+
return NativeClipboardModule_1.default.hasImage();
|
|
149
149
|
},
|
|
150
150
|
/**
|
|
151
151
|
* (iOS Only)
|
|
@@ -162,7 +162,7 @@ exports.Clipboard = {
|
|
|
162
162
|
if (react_native_1.Platform.OS !== 'ios') {
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
|
-
return
|
|
165
|
+
return NativeClipboardModule_1.default.hasURL();
|
|
166
166
|
},
|
|
167
167
|
/**
|
|
168
168
|
* (iOS 14+ Only)
|
|
@@ -179,7 +179,7 @@ exports.Clipboard = {
|
|
|
179
179
|
if (react_native_1.Platform.OS !== 'ios') {
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
|
-
return
|
|
182
|
+
return NativeClipboardModule_1.default.hasNumber();
|
|
183
183
|
},
|
|
184
184
|
/**
|
|
185
185
|
* (iOS 14+ Only)
|
|
@@ -196,7 +196,7 @@ exports.Clipboard = {
|
|
|
196
196
|
if (react_native_1.Platform.OS !== 'ios') {
|
|
197
197
|
return;
|
|
198
198
|
}
|
|
199
|
-
return
|
|
199
|
+
return NativeClipboardModule_1.default.hasWebURL();
|
|
200
200
|
},
|
|
201
201
|
/**
|
|
202
202
|
* (iOS and Android Only)
|
|
@@ -209,7 +209,7 @@ exports.Clipboard = {
|
|
|
209
209
|
* ```
|
|
210
210
|
*/
|
|
211
211
|
addListener: function (callback) {
|
|
212
|
-
return (0,
|
|
212
|
+
return (0, NativeClipboardModule_1.addListener)(callback);
|
|
213
213
|
},
|
|
214
214
|
/**
|
|
215
215
|
* (iOS and Android Only)
|
|
@@ -219,6 +219,6 @@ exports.Clipboard = {
|
|
|
219
219
|
* ```
|
|
220
220
|
*/
|
|
221
221
|
removeAllListeners: function () {
|
|
222
|
-
(0,
|
|
222
|
+
(0, NativeClipboardModule_1.removeAllListeners)();
|
|
223
223
|
},
|
|
224
224
|
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { TurboModule, EmitterSubscription } from 'react-native';
|
|
2
|
+
import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
export interface Spec extends TurboModule {
|
|
4
|
+
/**
|
|
5
|
+
* Get content of string type, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
6
|
+
* ```javascript
|
|
7
|
+
* async _getContent() {
|
|
8
|
+
* var content = await Clipboard.getString();
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
getString(): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* (iOS Only)
|
|
15
|
+
* Get contents of string array type, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
16
|
+
* ```javascript
|
|
17
|
+
* async _getContent() {
|
|
18
|
+
* var content = await Clipboard.getStrings();
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
getStrings(): Promise<string[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Get clipboard image as PNG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
25
|
+
* ```javascript
|
|
26
|
+
* async _getContent() {
|
|
27
|
+
* var content = await Clipboard.getImagePNG();
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
getImagePNG(): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Get clipboard image as JPG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
34
|
+
* ```javascript
|
|
35
|
+
* async _getContent() {
|
|
36
|
+
* var content = await Clipboard.getImageJPG();
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
getImageJPG(): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* (iOS Only)
|
|
43
|
+
* Set content of base64 image type. You can use following code to set clipboard content
|
|
44
|
+
* ```javascript
|
|
45
|
+
* _setContent() {
|
|
46
|
+
* Clipboard.setImage(...);
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
* @param the content to be stored in the clipboard.
|
|
50
|
+
*/
|
|
51
|
+
setImage(content: string): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* (Android Only)
|
|
54
|
+
* Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
55
|
+
* ```javascript
|
|
56
|
+
* async _getContent() {
|
|
57
|
+
* var content = await Clipboard.getImage();
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
getImage(): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Set content of string type. You can use following code to set clipboard content
|
|
64
|
+
* ```javascript
|
|
65
|
+
* _setContent() {
|
|
66
|
+
* Clipboard.setString('hello world');
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
* @param the content to be stored in the clipboard.
|
|
70
|
+
*/
|
|
71
|
+
setString(content: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* Set content of string array type. You can use following code to set clipboard content
|
|
74
|
+
* ```javascript
|
|
75
|
+
* _setContent() {
|
|
76
|
+
* Clipboard.setStrings(['hello world', 'second string']);
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
* @param the content to be stored in the clipboard.
|
|
80
|
+
*/
|
|
81
|
+
setStrings(content: string[]): void;
|
|
82
|
+
/**
|
|
83
|
+
* Returns whether the clipboard has content or is empty.
|
|
84
|
+
* This method returns a `Promise`, so you can use following code to get clipboard content
|
|
85
|
+
* ```javascript
|
|
86
|
+
* async _hasContent() {
|
|
87
|
+
* var hasContent = await Clipboard.hasString();
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
hasString(): Promise<boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* Returns whether the clipboard has an image or is empty.
|
|
94
|
+
* This method returns a `Promise`, so you can use following code to check clipboard content
|
|
95
|
+
* ```javascript
|
|
96
|
+
* async _hasContent() {
|
|
97
|
+
* var hasContent = await Clipboard.hasImage();
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
hasImage(): Promise<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* (iOS Only)
|
|
104
|
+
* Returns whether the clipboard has a URL content. Can check
|
|
105
|
+
* if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+
|
|
106
|
+
* This method returns a `Promise`, so you can use following code to check for url content in clipboard.
|
|
107
|
+
* ```javascript
|
|
108
|
+
* async _hasURL() {
|
|
109
|
+
* var hasURL = await Clipboard.hasURL();
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
hasURL(): Promise<boolean>;
|
|
114
|
+
/**
|
|
115
|
+
* (iOS 14+ Only)
|
|
116
|
+
* Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
|
|
117
|
+
* if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
|
|
118
|
+
* This method returns a `Promise`, so you can use following code to check for Number content in clipboard.
|
|
119
|
+
* ```javascript
|
|
120
|
+
* async _hasNumber() {
|
|
121
|
+
* var hasNumber = await Clipboard.hasNumber();
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
hasNumber(): Promise<boolean>;
|
|
126
|
+
/**
|
|
127
|
+
* (iOS 14+ Only)
|
|
128
|
+
* Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
|
|
129
|
+
* if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
|
|
130
|
+
* This method returns a `Promise`, so you can use following code to check for WebURL content in clipboard.
|
|
131
|
+
* ```javascript
|
|
132
|
+
* async _hasWebURL() {
|
|
133
|
+
* var hasWebURL = await Clipboard.hasWebURL();
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
hasWebURL(): Promise<boolean>;
|
|
138
|
+
setListener(): void;
|
|
139
|
+
removeListener(): void;
|
|
140
|
+
addListener(eventName: string): void;
|
|
141
|
+
removeListeners(count: Int32): void;
|
|
142
|
+
}
|
|
143
|
+
declare const ClipboardTurboModule: Spec;
|
|
144
|
+
export default ClipboardTurboModule;
|
|
145
|
+
declare const addListener: (callback: () => void) => EmitterSubscription;
|
|
146
|
+
declare const removeAllListeners: () => void;
|
|
147
|
+
export { addListener, removeAllListeners };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeAllListeners = exports.addListener = void 0;
|
|
4
|
+
var react_native_1 = require("react-native");
|
|
5
|
+
var ClipboardTurboModule = react_native_1.TurboModuleRegistry.getEnforcing('RNCClipboard');
|
|
6
|
+
exports.default = ClipboardTurboModule;
|
|
7
|
+
var EVENT_NAME = 'RNCClipboard_TEXT_CHANGED';
|
|
8
|
+
var eventEmitter = new react_native_1.NativeEventEmitter(ClipboardTurboModule);
|
|
9
|
+
var listenerCount = eventEmitter.listenerCount;
|
|
10
|
+
// listenerCount is only available from RN 0.64
|
|
11
|
+
// Older versions only have `listeners`
|
|
12
|
+
if (!listenerCount) {
|
|
13
|
+
listenerCount = function (eventType) {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
return eventEmitter.listeners(eventType).length;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
listenerCount = eventEmitter.listenerCount.bind(eventEmitter);
|
|
20
|
+
}
|
|
21
|
+
var addListener = function (callback) {
|
|
22
|
+
if (listenerCount(EVENT_NAME) === 0) {
|
|
23
|
+
ClipboardTurboModule.setListener();
|
|
24
|
+
}
|
|
25
|
+
var res = eventEmitter.addListener(EVENT_NAME, callback);
|
|
26
|
+
// Path the remove call to also remove the native listener
|
|
27
|
+
// if we no longer have listeners
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
res._remove = res.remove;
|
|
30
|
+
res.remove = function () {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
this._remove();
|
|
33
|
+
if (listenerCount(EVENT_NAME) === 0) {
|
|
34
|
+
ClipboardTurboModule.removeListener();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return res;
|
|
38
|
+
};
|
|
39
|
+
exports.addListener = addListener;
|
|
40
|
+
var removeAllListeners = function () {
|
|
41
|
+
eventEmitter.removeAllListeners(EVENT_NAME);
|
|
42
|
+
ClipboardTurboModule.removeListener();
|
|
43
|
+
};
|
|
44
|
+
exports.removeAllListeners = removeAllListeners;
|
package/ios/RNCClipboard.h
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
#ifndef RNCClipboard_h
|
|
2
2
|
#define RNCClipboard_h
|
|
3
3
|
|
|
4
|
-
#
|
|
4
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
5
|
+
#import <rnclipboard/rnclipboard.h>
|
|
6
|
+
#else
|
|
7
|
+
#import <React/RCTBridge.h>
|
|
8
|
+
#endif
|
|
9
|
+
|
|
5
10
|
#import <React/RCTEventEmitter.h>
|
|
6
11
|
|
|
7
|
-
@interface RNCClipboard : RCTEventEmitter
|
|
12
|
+
@interface RNCClipboard : RCTEventEmitter
|
|
8
13
|
|
|
14
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
15
|
+
<NativeClipboardModuleSpec>
|
|
16
|
+
#else
|
|
17
|
+
<RCTBridgeModule>
|
|
18
|
+
#endif
|
|
9
19
|
@end
|
|
10
20
|
|
|
11
21
|
#endif
|
|
@@ -213,7 +213,26 @@ RCT_EXPORT_METHOD(hasWebURL:(RCTPromiseResolveBlock)resolve
|
|
|
213
213
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
RCT_EXPORT_METHOD(getImage:(RCTPromiseResolveBlock)resolve
|
|
217
|
+
reject:(__unused RCTPromiseRejectBlock)reject){
|
|
218
|
+
reject(@"Clipboard:getImage", @"getImage is not supported on iOS", nil);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
RCT_EXPORT_METHOD(addListener : (NSString *)eventName) {
|
|
222
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
223
|
+
}
|
|
216
224
|
|
|
225
|
+
RCT_EXPORT_METHOD(removeListeners : (NSInteger)count) {
|
|
226
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
#if RCT_NEW_ARCH_ENABLED
|
|
230
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
231
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
232
|
+
{
|
|
233
|
+
return std::make_shared<facebook::react::NativeClipboardModuleSpecJSI>(params);
|
|
234
|
+
}
|
|
235
|
+
#endif
|
|
217
236
|
|
|
218
237
|
|
|
219
238
|
@end
|
package/macos/RNCClipboard.m
CHANGED
|
@@ -31,4 +31,12 @@ RCT_EXPORT_METHOD(getString:(RCTPromiseResolveBlock)resolve
|
|
|
31
31
|
resolve(([pasteboard stringForType:NSPasteboardTypeString] ? : @""));
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
RCT_EXPORT_METHOD(addListener : (NSString *)eventName) {
|
|
35
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
RCT_EXPORT_METHOD(removeListeners : (NSInteger)count) {
|
|
39
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
40
|
+
}
|
|
41
|
+
|
|
34
42
|
@end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-clipboard/clipboard",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "React Native Clipboard API for macOS, iOS, Android, and Windows",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Clipboard",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"android",
|
|
29
29
|
"windows",
|
|
30
30
|
"jest",
|
|
31
|
+
"src",
|
|
31
32
|
"!android/**/build/*"
|
|
32
33
|
],
|
|
33
34
|
"scripts": {
|
|
@@ -69,9 +70,9 @@
|
|
|
69
70
|
"access": "public"
|
|
70
71
|
},
|
|
71
72
|
"codegenConfig": {
|
|
72
|
-
"name": "
|
|
73
|
-
"type": "
|
|
74
|
-
"jsSrcsDir": "
|
|
73
|
+
"name": "rnclipboard",
|
|
74
|
+
"type": "modules",
|
|
75
|
+
"jsSrcsDir": "./src",
|
|
75
76
|
"android": {
|
|
76
77
|
"javaPackageName": "com.reactnativecommunity.clipboard"
|
|
77
78
|
}
|
package/src/Clipboard.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import {EmitterSubscription, Platform} from 'react-native';
|
|
2
|
+
import NativeClipboard, {
|
|
3
|
+
addListener,
|
|
4
|
+
removeAllListeners,
|
|
5
|
+
} from './NativeClipboardModule';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `Clipboard` gives you an interface for setting and getting content from Clipboard on both iOS and Android
|
|
9
|
+
*/
|
|
10
|
+
export const Clipboard = {
|
|
11
|
+
/**
|
|
12
|
+
* Get content of string type, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
13
|
+
* ```javascript
|
|
14
|
+
* async _getContent() {
|
|
15
|
+
* var content = await Clipboard.getString();
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
getString(): Promise<string> {
|
|
20
|
+
return NativeClipboard.getString();
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* (iOS Only)
|
|
24
|
+
* Get contents of string array type, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
25
|
+
* ```javascript
|
|
26
|
+
* async _getContent() {
|
|
27
|
+
* var content = await Clipboard.getStrings();
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
getStrings(): Promise<string[]> {
|
|
32
|
+
return NativeClipboard.getStrings();
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Get clipboard image as PNG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
36
|
+
* ```javascript
|
|
37
|
+
* async _getContent() {
|
|
38
|
+
* var content = await Clipboard.getImagePNG();
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
getImagePNG(): Promise<string> {
|
|
43
|
+
return NativeClipboard.getImagePNG();
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Get clipboard image as JPG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
47
|
+
* ```javascript
|
|
48
|
+
* async _getContent() {
|
|
49
|
+
* var content = await Clipboard.getImageJPG();
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
getImageJPG(): Promise<string> {
|
|
54
|
+
return NativeClipboard.getImageJPG();
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* (iOS Only)
|
|
58
|
+
* Set content of base64 image type. You can use following code to set clipboard content
|
|
59
|
+
* ```javascript
|
|
60
|
+
* _setContent() {
|
|
61
|
+
* Clipboard.setImage(...);
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
* @param the content to be stored in the clipboard.
|
|
65
|
+
*/
|
|
66
|
+
setImage(content: string) {
|
|
67
|
+
if (Platform.OS !== 'ios') {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
NativeClipboard.setImage(content);
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* (Android Only)
|
|
75
|
+
* Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
76
|
+
* ```javascript
|
|
77
|
+
* async _getContent() {
|
|
78
|
+
* var content = await Clipboard.getImage();
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
getImage(): Promise<string> {
|
|
83
|
+
return NativeClipboard.getImage();
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* Set content of string type. You can use following code to set clipboard content
|
|
87
|
+
* ```javascript
|
|
88
|
+
* _setContent() {
|
|
89
|
+
* Clipboard.setString('hello world');
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
* @param the content to be stored in the clipboard.
|
|
93
|
+
*/
|
|
94
|
+
setString(content: string) {
|
|
95
|
+
NativeClipboard.setString(content);
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Set content of string array type. You can use following code to set clipboard content
|
|
99
|
+
* ```javascript
|
|
100
|
+
* _setContent() {
|
|
101
|
+
* Clipboard.setStrings(['hello world', 'second string']);
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
* @param the content to be stored in the clipboard.
|
|
105
|
+
*/
|
|
106
|
+
setStrings(content: string[]) {
|
|
107
|
+
NativeClipboard.setStrings(content);
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* Returns whether the clipboard has content or is empty.
|
|
111
|
+
* This method returns a `Promise`, so you can use following code to get clipboard content
|
|
112
|
+
* ```javascript
|
|
113
|
+
* async _hasContent() {
|
|
114
|
+
* var hasContent = await Clipboard.hasString();
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
hasString() {
|
|
119
|
+
return NativeClipboard.hasString();
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Returns whether the clipboard has an image or is empty.
|
|
123
|
+
* This method returns a `Promise`, so you can use following code to check clipboard content
|
|
124
|
+
* ```javascript
|
|
125
|
+
* async _hasContent() {
|
|
126
|
+
* var hasContent = await Clipboard.hasImage();
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
hasImage() {
|
|
131
|
+
return NativeClipboard.hasImage();
|
|
132
|
+
},
|
|
133
|
+
/**
|
|
134
|
+
* (iOS Only)
|
|
135
|
+
* Returns whether the clipboard has a URL content. Can check
|
|
136
|
+
* if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+
|
|
137
|
+
* This method returns a `Promise`, so you can use following code to check for url content in clipboard.
|
|
138
|
+
* ```javascript
|
|
139
|
+
* async _hasURL() {
|
|
140
|
+
* var hasURL = await Clipboard.hasURL();
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
hasURL() {
|
|
145
|
+
if (Platform.OS !== 'ios') {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
return NativeClipboard.hasURL();
|
|
149
|
+
},
|
|
150
|
+
/**
|
|
151
|
+
* (iOS 14+ Only)
|
|
152
|
+
* Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
|
|
153
|
+
* if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
|
|
154
|
+
* This method returns a `Promise`, so you can use following code to check for Number content in clipboard.
|
|
155
|
+
* ```javascript
|
|
156
|
+
* async _hasNumber() {
|
|
157
|
+
* var hasNumber = await Clipboard.hasNumber();
|
|
158
|
+
* }
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
hasNumber() {
|
|
162
|
+
if (Platform.OS !== 'ios') {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
return NativeClipboard.hasNumber();
|
|
166
|
+
},
|
|
167
|
+
/**
|
|
168
|
+
* (iOS 14+ Only)
|
|
169
|
+
* Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
|
|
170
|
+
* if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
|
|
171
|
+
* This method returns a `Promise`, so you can use following code to check for WebURL content in clipboard.
|
|
172
|
+
* ```javascript
|
|
173
|
+
* async _hasWebURL() {
|
|
174
|
+
* var hasWebURL = await Clipboard.hasWebURL();
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
hasWebURL() {
|
|
179
|
+
if (Platform.OS !== 'ios') {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
return NativeClipboard.hasWebURL();
|
|
183
|
+
},
|
|
184
|
+
/**
|
|
185
|
+
* (iOS and Android Only)
|
|
186
|
+
* Adds a listener to get notifications when the clipboard has changed.
|
|
187
|
+
* If this is the first listener, turns on clipboard notifications on the native side.
|
|
188
|
+
* It returns EmitterSubscription where you can call "remove" to remove listener
|
|
189
|
+
* ```javascript
|
|
190
|
+
* const listener = () => console.log("changed!");
|
|
191
|
+
* Clipboard.addListener(listener);
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
addListener(callback: () => void): EmitterSubscription {
|
|
195
|
+
return addListener(callback);
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* (iOS and Android Only)
|
|
200
|
+
* Removes all previously registered listeners and turns off notifications on the native side.
|
|
201
|
+
* ```javascript
|
|
202
|
+
* Clipboard.removeAllListeners();
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
removeAllListeners() {
|
|
206
|
+
removeAllListeners();
|
|
207
|
+
},
|
|
208
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
declare var navigator: {
|
|
2
|
+
clipboard: {
|
|
3
|
+
readText(): Promise<string>;
|
|
4
|
+
writeText(data: string): Promise<void>;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
declare var document: any;
|
|
9
|
+
|
|
10
|
+
export const Clipboard = {
|
|
11
|
+
getString(): Promise<string> {
|
|
12
|
+
if (navigator && navigator.clipboard) {
|
|
13
|
+
return navigator.clipboard.readText();
|
|
14
|
+
} else {
|
|
15
|
+
const el = document.createElement('textarea');
|
|
16
|
+
document.body.appendChild(el);
|
|
17
|
+
el.select();
|
|
18
|
+
document.execCommand('paste');
|
|
19
|
+
const value = el.innerText;
|
|
20
|
+
document.body.removeChild(el);
|
|
21
|
+
return Promise.resolve(value);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
setString(content: string) {
|
|
26
|
+
if (navigator && navigator.clipboard) {
|
|
27
|
+
navigator.clipboard.writeText(content);
|
|
28
|
+
} else {
|
|
29
|
+
const el = document.createElement('textarea');
|
|
30
|
+
el.value = content;
|
|
31
|
+
document.body.appendChild(el);
|
|
32
|
+
el.select();
|
|
33
|
+
document.execCommand('copy');
|
|
34
|
+
document.body.removeChild(el);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
3
|
+
TurboModuleRegistry,
|
|
4
|
+
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
5
|
+
TurboModule,
|
|
6
|
+
EmitterSubscription,
|
|
7
|
+
NativeEventEmitter,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
// @ts-ignore - remove this comment when RN in the repo & example app is upgraded
|
|
10
|
+
import type {Int32} from 'react-native/Libraries/Types/CodegenTypes';
|
|
11
|
+
|
|
12
|
+
export interface Spec extends TurboModule {
|
|
13
|
+
/**
|
|
14
|
+
* Get content of string type, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
15
|
+
* ```javascript
|
|
16
|
+
* async _getContent() {
|
|
17
|
+
* var content = await Clipboard.getString();
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
getString(): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* (iOS Only)
|
|
24
|
+
* Get contents of string array type, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
25
|
+
* ```javascript
|
|
26
|
+
* async _getContent() {
|
|
27
|
+
* var content = await Clipboard.getStrings();
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
getStrings(): Promise<string[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Get clipboard image as PNG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
34
|
+
* ```javascript
|
|
35
|
+
* async _getContent() {
|
|
36
|
+
* var content = await Clipboard.getImagePNG();
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
getImagePNG(): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Get clipboard image as JPG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
43
|
+
* ```javascript
|
|
44
|
+
* async _getContent() {
|
|
45
|
+
* var content = await Clipboard.getImageJPG();
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
getImageJPG(): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* (iOS Only)
|
|
52
|
+
* Set content of base64 image type. You can use following code to set clipboard content
|
|
53
|
+
* ```javascript
|
|
54
|
+
* _setContent() {
|
|
55
|
+
* Clipboard.setImage(...);
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
* @param the content to be stored in the clipboard.
|
|
59
|
+
*/
|
|
60
|
+
setImage(content: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* (Android Only)
|
|
63
|
+
* Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
|
|
64
|
+
* ```javascript
|
|
65
|
+
* async _getContent() {
|
|
66
|
+
* var content = await Clipboard.getImage();
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
getImage(): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Set content of string type. You can use following code to set clipboard content
|
|
73
|
+
* ```javascript
|
|
74
|
+
* _setContent() {
|
|
75
|
+
* Clipboard.setString('hello world');
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
* @param the content to be stored in the clipboard.
|
|
79
|
+
*/
|
|
80
|
+
setString(content: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Set content of string array type. You can use following code to set clipboard content
|
|
83
|
+
* ```javascript
|
|
84
|
+
* _setContent() {
|
|
85
|
+
* Clipboard.setStrings(['hello world', 'second string']);
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
* @param the content to be stored in the clipboard.
|
|
89
|
+
*/
|
|
90
|
+
setStrings(content: string[]): void;
|
|
91
|
+
/**
|
|
92
|
+
* Returns whether the clipboard has content or is empty.
|
|
93
|
+
* This method returns a `Promise`, so you can use following code to get clipboard content
|
|
94
|
+
* ```javascript
|
|
95
|
+
* async _hasContent() {
|
|
96
|
+
* var hasContent = await Clipboard.hasString();
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
hasString(): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns whether the clipboard has an image or is empty.
|
|
103
|
+
* This method returns a `Promise`, so you can use following code to check clipboard content
|
|
104
|
+
* ```javascript
|
|
105
|
+
* async _hasContent() {
|
|
106
|
+
* var hasContent = await Clipboard.hasImage();
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
hasImage(): Promise<boolean>;
|
|
111
|
+
/**
|
|
112
|
+
* (iOS Only)
|
|
113
|
+
* Returns whether the clipboard has a URL content. Can check
|
|
114
|
+
* if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+
|
|
115
|
+
* This method returns a `Promise`, so you can use following code to check for url content in clipboard.
|
|
116
|
+
* ```javascript
|
|
117
|
+
* async _hasURL() {
|
|
118
|
+
* var hasURL = await Clipboard.hasURL();
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
hasURL(): Promise<boolean>;
|
|
123
|
+
/**
|
|
124
|
+
* (iOS 14+ Only)
|
|
125
|
+
* Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
|
|
126
|
+
* if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
|
|
127
|
+
* This method returns a `Promise`, so you can use following code to check for Number content in clipboard.
|
|
128
|
+
* ```javascript
|
|
129
|
+
* async _hasNumber() {
|
|
130
|
+
* var hasNumber = await Clipboard.hasNumber();
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
hasNumber(): Promise<boolean>;
|
|
135
|
+
/**
|
|
136
|
+
* (iOS 14+ Only)
|
|
137
|
+
* Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
|
|
138
|
+
* if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
|
|
139
|
+
* This method returns a `Promise`, so you can use following code to check for WebURL content in clipboard.
|
|
140
|
+
* ```javascript
|
|
141
|
+
* async _hasWebURL() {
|
|
142
|
+
* var hasWebURL = await Clipboard.hasWebURL();
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
hasWebURL(): Promise<boolean>;
|
|
147
|
+
setListener(): void;
|
|
148
|
+
removeListener(): void;
|
|
149
|
+
addListener(eventName: string): void;
|
|
150
|
+
removeListeners(count: Int32): void;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const ClipboardTurboModule =
|
|
154
|
+
TurboModuleRegistry.getEnforcing<Spec>('RNCClipboard');
|
|
155
|
+
|
|
156
|
+
export default ClipboardTurboModule;
|
|
157
|
+
|
|
158
|
+
const EVENT_NAME = 'RNCClipboard_TEXT_CHANGED';
|
|
159
|
+
const eventEmitter = new NativeEventEmitter(ClipboardTurboModule);
|
|
160
|
+
|
|
161
|
+
let listenerCount = eventEmitter.listenerCount;
|
|
162
|
+
|
|
163
|
+
// listenerCount is only available from RN 0.64
|
|
164
|
+
// Older versions only have `listeners`
|
|
165
|
+
if (!listenerCount) {
|
|
166
|
+
listenerCount = (eventType: string) => {
|
|
167
|
+
// @ts-ignore
|
|
168
|
+
return eventEmitter.listeners(eventType).length;
|
|
169
|
+
};
|
|
170
|
+
} else {
|
|
171
|
+
listenerCount = eventEmitter.listenerCount.bind(eventEmitter);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const addListener = (callback: () => void): EmitterSubscription => {
|
|
175
|
+
if (listenerCount(EVENT_NAME) === 0) {
|
|
176
|
+
ClipboardTurboModule.setListener();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let res = eventEmitter.addListener(EVENT_NAME, callback);
|
|
180
|
+
|
|
181
|
+
// Path the remove call to also remove the native listener
|
|
182
|
+
// if we no longer have listeners
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
res._remove = res.remove;
|
|
185
|
+
res.remove = function () {
|
|
186
|
+
// @ts-ignore
|
|
187
|
+
this._remove();
|
|
188
|
+
if (listenerCount(EVENT_NAME) === 0) {
|
|
189
|
+
ClipboardTurboModule.removeListener();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
return res;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const removeAllListeners = () => {
|
|
197
|
+
eventEmitter.removeAllListeners(EVENT_NAME);
|
|
198
|
+
ClipboardTurboModule.removeListener();
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export {addListener, removeAllListeners};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useClipboard.ts
|
|
3
|
+
* This code is inspired from the @react-native-community/hooks package
|
|
4
|
+
* All credit goes to author of the useClipboard custom hooks.
|
|
5
|
+
* https://github.com/react-native-community/hooks
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {useEffect, useState} from 'react';
|
|
9
|
+
import {Clipboard} from './Clipboard';
|
|
10
|
+
|
|
11
|
+
type Listener = (content: string) => void;
|
|
12
|
+
const listeners = new Set<Listener>();
|
|
13
|
+
|
|
14
|
+
function setString(content: string) {
|
|
15
|
+
Clipboard.setString(content);
|
|
16
|
+
listeners.forEach((listener) => listener(content));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const useClipboard = (): [string, (content: string) => void] => {
|
|
20
|
+
const [data, updateClipboardData] = useState('');
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
Clipboard.getString().then(updateClipboardData);
|
|
24
|
+
}, []);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
listeners.add(updateClipboardData);
|
|
28
|
+
|
|
29
|
+
return () => {
|
|
30
|
+
listeners.delete(updateClipboardData);
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
|
|
34
|
+
return [data, setString];
|
|
35
|
+
};
|