@react-native-clipboard/clipboard 1.8.4 → 1.8.5

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/README.md CHANGED
@@ -200,6 +200,28 @@ static hasURL()
200
200
  Returns whether the clipboard has a URL content.
201
201
  Can check if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+
202
202
 
203
+ #### `hasNumber()`
204
+
205
+ ```jsx
206
+ static hasNumber()
207
+ ```
208
+
209
+ (iOS 14+ only)
210
+ Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content.
211
+ Can check if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
212
+
213
+ #### `hasWebURL()`
214
+
215
+ ```jsx
216
+ static hasWebURL()
217
+ ```
218
+
219
+ (iOS 14+ only)
220
+ Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content.
221
+ Can check if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
222
+
223
+
224
+
203
225
  ### useClipboard
204
226
 
205
227
  `useClipboard` is a utility hooks for the `Clipboard` module. `data` contains the content stored in the clipboard.
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <classpath>
3
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
3
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14/"/>
4
4
  <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
5
5
  <classpathentry kind="output" path="bin/default"/>
6
6
  </classpath>
package/android/.project CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <projectDescription>
3
- <name>android</name>
3
+ <name>@react-native-community_clipboard</name>
4
4
  <comment>Project android created by Buildship.</comment>
5
5
  <projects>
6
6
  </projects>
@@ -20,4 +20,15 @@
20
20
  <nature>org.eclipse.jdt.core.javanature</nature>
21
21
  <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22
22
  </natures>
23
+ <filteredResources>
24
+ <filter>
25
+ <id>0</id>
26
+ <name></name>
27
+ <type>30</type>
28
+ <matcher>
29
+ <id>org.eclipse.core.resources.regexFilterMatcher</id>
30
+ <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
31
+ </matcher>
32
+ </filter>
33
+ </filteredResources>
23
34
  </projectDescription>
@@ -1,11 +1,11 @@
1
1
  arguments=
2
2
  auto.sync=false
3
3
  build.scans.enabled=false
4
- connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3))
5
- connection.project.dir=
4
+ connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.0-rc-1))
5
+ connection.project.dir=../example/android
6
6
  eclipse.preferences.version=1
7
7
  gradle.user.home=
8
- java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
8
+ java.home=/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home
9
9
  jvm.arguments=
10
10
  offline.mode=false
11
11
  override.workspace.settings=true
@@ -1,7 +1,7 @@
1
1
  buildscript {
2
2
  repositories {
3
3
  google()
4
- jcenter()
4
+ mavenCentral()
5
5
  }
6
6
 
7
7
  dependencies {
@@ -30,7 +30,6 @@ android {
30
30
 
31
31
  repositories {
32
32
  google()
33
- jcenter()
34
33
  mavenCentral()
35
34
  }
36
35
 
@@ -7,9 +7,16 @@
7
7
 
8
8
  package com.reactnativecommunity.clipboard;
9
9
 
10
+ import android.content.ClipDescription;
10
11
  import android.content.ClipboardManager;
11
12
  import android.content.ClipData;
13
+ import android.content.ContentResolver;
12
14
  import android.content.Context;
15
+ import android.graphics.Bitmap;
16
+ import android.net.Uri;
17
+ import android.provider.MediaStore;
18
+ import android.util.Base64;
19
+ import android.util.Log;
13
20
 
14
21
  import com.facebook.react.bridge.ReactApplicationContext;
15
22
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
@@ -19,6 +26,9 @@ import com.facebook.react.bridge.Promise;
19
26
  import com.facebook.react.module.annotations.ReactModule;
20
27
  import com.facebook.react.modules.core.DeviceEventManagerModule;
21
28
 
29
+ import java.io.ByteArrayOutputStream;
30
+ import java.io.IOException;
31
+
22
32
  /**
23
33
  * A module that allows JS to get/set clipboard contents.
24
34
  */
@@ -83,6 +93,51 @@ public class ClipboardModule extends ContextBaseJavaModule {
83
93
  }
84
94
  }
85
95
 
96
+ @ReactMethod
97
+ public void getImage(Promise promise){
98
+ ClipboardManager clipboardManager = getClipboardService();
99
+ if (!(clipboardManager.hasPrimaryClip())){
100
+ promise.resolve("");
101
+ }
102
+ else if (clipboardManager.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)){
103
+ promise.resolve("");
104
+ }
105
+ else {
106
+ ClipData clipData = clipboardManager.getPrimaryClip();
107
+ if(clipData != null){
108
+ ClipData.Item item = clipData.getItemAt(0);
109
+ Uri pasteUri = item.getUri();
110
+ if (pasteUri != null){
111
+ ContentResolver cr = reactContext.getContentResolver();
112
+ String mimeType = cr.getType(pasteUri);
113
+ if (mimeType != null){
114
+ if (mimeType.equals("image/jpeg") || mimeType.equals("image/png") || mimeType.equals("image/jpg")){
115
+ String imgPath = pasteUri.getPath();
116
+ try {
117
+ Bitmap bitmap = MediaStore.Images.Media.getBitmap(cr, pasteUri);
118
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
119
+ if (mimeType.equals("image/jpeg") || mimeType.equals("image/jpg")){
120
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
121
+ }
122
+ if (mimeType.equals("image/png")){
123
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
124
+ }
125
+ byte[] byteArray = outputStream.toByteArray();
126
+ String encodedString = Base64.encodeToString(byteArray, Base64.DEFAULT);
127
+ StringBuilder builder = new StringBuilder("data:" + mimeType + ";base64,").append(encodedString);
128
+ promise.resolve(builder.toString());
129
+ } catch (IOException e) {
130
+ promise.reject(e);
131
+ e.printStackTrace();
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ promise.resolve("");
138
+ }
139
+ }
140
+
86
141
  @ReactMethod
87
142
  public void setListener() {
88
143
  try {
@@ -102,7 +157,7 @@ public class ClipboardModule extends ContextBaseJavaModule {
102
157
  }
103
158
 
104
159
  @ReactMethod
105
- void removeListener() {
160
+ public void removeListener() {
106
161
  if(listener != null){
107
162
  try{
108
163
  ClipboardManager clipboard = getClipboardService();
@@ -112,4 +167,14 @@ public class ClipboardModule extends ContextBaseJavaModule {
112
167
  }
113
168
  }
114
169
  }
170
+
171
+ @ReactMethod
172
+ public void addListener(String eventName) {
173
+ // Keep: Required for RN built in Event Emitter Calls.
174
+ }
175
+
176
+ @ReactMethod
177
+ public void removeListeners(Integer count) {
178
+ // Keep: Required for RN built in Event Emitter Calls.
179
+ }
115
180
  }
@@ -30,6 +30,19 @@ export declare const Clipboard: {
30
30
  * ```
31
31
  */
32
32
  getImageJPG(): Promise<string>;
33
+ /**
34
+ * Set content of base64 image type. You can use following code to set clipboard content
35
+ * ```javascript
36
+ * _setContent() {
37
+ * Clipboard.setImage(...);
38
+ * }
39
+ *
40
+ * iOS only
41
+ * ```
42
+ * @param the content to be stored in the clipboard.
43
+ */
44
+ setImage(content: string): void;
45
+ getImage(): Promise<string>;
33
46
  /**
34
47
  * Set content of string type. You can use following code to set clipboard content
35
48
  * ```javascript
@@ -72,6 +85,30 @@ export declare const Clipboard: {
72
85
  * ```
73
86
  */
74
87
  hasURL(): any;
88
+ /**
89
+ * (IOS 14+ Only)
90
+ * Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
91
+ * if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
92
+ * This method returns a `Promise`, so you can use following code to check for Number content in clipboard.
93
+ * ```javascript
94
+ * async _hasNumber() {
95
+ * var hasNumber = await Clipboard.hasNumber();
96
+ * }
97
+ * ```
98
+ */
99
+ hasNumber(): any;
100
+ /**
101
+ * (IOS 14+ Only)
102
+ * Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
103
+ * if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
104
+ * This method returns a `Promise`, so you can use following code to check for WebURL content in clipboard.
105
+ * ```javascript
106
+ * async _hasWebURL() {
107
+ * var hasWebURL = await Clipboard.hasWebURL();
108
+ * }
109
+ * ```
110
+ */
111
+ hasWebURL(): any;
75
112
  /**
76
113
  * (iOS and Android Only)
77
114
  * Adds a listener to get notifications when the clipboard has changed.
package/dist/Clipboard.js CHANGED
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
14
14
  var __importStar = (this && this.__importStar) || function (mod) {
15
15
  if (mod && mod.__esModule) return mod;
16
16
  var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
@@ -59,6 +59,35 @@ exports.Clipboard = {
59
59
  getImageJPG: function () {
60
60
  return NativeClipboard_1.default.getImageJPG();
61
61
  },
62
+ /**
63
+ * Set content of base64 image type. You can use following code to set clipboard content
64
+ * ```javascript
65
+ * _setContent() {
66
+ * Clipboard.setImage(...);
67
+ * }
68
+ *
69
+ * iOS only
70
+ * ```
71
+ * @param the content to be stored in the clipboard.
72
+ */
73
+ setImage: function (content) {
74
+ if (react_native_1.Platform.OS !== 'ios') {
75
+ return;
76
+ }
77
+ NativeClipboard_1.default.setImage(content);
78
+ },
79
+ /*
80
+ * (Android Only)
81
+ * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
82
+ * ```javascript
83
+ * async _getContent() {
84
+ * var content = await Clipboard.getImage();
85
+ * }
86
+ * ```
87
+ */
88
+ getImage: function () {
89
+ return NativeClipboard_1.default.getImage();
90
+ },
62
91
  /**
63
92
  * Set content of string type. You can use following code to set clipboard content
64
93
  * ```javascript
@@ -112,6 +141,40 @@ exports.Clipboard = {
112
141
  }
113
142
  return NativeClipboard_1.default.hasURL();
114
143
  },
144
+ /**
145
+ * (IOS 14+ Only)
146
+ * Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
147
+ * if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
148
+ * This method returns a `Promise`, so you can use following code to check for Number content in clipboard.
149
+ * ```javascript
150
+ * async _hasNumber() {
151
+ * var hasNumber = await Clipboard.hasNumber();
152
+ * }
153
+ * ```
154
+ */
155
+ hasNumber: function () {
156
+ if (react_native_1.Platform.OS !== 'ios') {
157
+ return;
158
+ }
159
+ return NativeClipboard_1.default.hasNumber();
160
+ },
161
+ /**
162
+ * (IOS 14+ Only)
163
+ * Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
164
+ * if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
165
+ * This method returns a `Promise`, so you can use following code to check for WebURL content in clipboard.
166
+ * ```javascript
167
+ * async _hasWebURL() {
168
+ * var hasWebURL = await Clipboard.hasWebURL();
169
+ * }
170
+ * ```
171
+ */
172
+ hasWebURL: function () {
173
+ if (react_native_1.Platform.OS !== 'ios') {
174
+ return;
175
+ }
176
+ return NativeClipboard_1.default.hasWebURL();
177
+ },
115
178
  /**
116
179
  * (iOS and Android Only)
117
180
  * Adds a listener to get notifications when the clipboard has changed.
@@ -123,7 +186,7 @@ exports.Clipboard = {
123
186
  * ```
124
187
  */
125
188
  addListener: function (callback) {
126
- return NativeClipboard_1.addListener(callback);
189
+ return (0, NativeClipboard_1.addListener)(callback);
127
190
  },
128
191
  /**
129
192
  * (iOS and Android Only)
@@ -133,6 +196,6 @@ exports.Clipboard = {
133
196
  * ```
134
197
  */
135
198
  removeAllListeners: function () {
136
- NativeClipboard_1.removeAllListeners();
199
+ (0, NativeClipboard_1.removeAllListeners)();
137
200
  },
138
201
  };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useClipboard = void 0;
3
4
  var Clipboard_1 = require("./Clipboard");
4
5
  var useClipboard_1 = require("./useClipboard");
5
6
  Object.defineProperty(exports, "useClipboard", { enumerable: true, get: function () { return useClipboard_1.useClipboard; } });
@@ -14,12 +14,12 @@ function setString(content) {
14
14
  Clipboard_1.Clipboard.setString(content);
15
15
  listeners.forEach(function (listener) { return listener(content); });
16
16
  }
17
- exports.useClipboard = function () {
18
- var _a = react_1.useState(''), data = _a[0], updateClipboardData = _a[1];
19
- react_1.useEffect(function () {
17
+ var useClipboard = function () {
18
+ var _a = (0, react_1.useState)(''), data = _a[0], updateClipboardData = _a[1];
19
+ (0, react_1.useEffect)(function () {
20
20
  Clipboard_1.Clipboard.getString().then(updateClipboardData);
21
21
  }, []);
22
- react_1.useEffect(function () {
22
+ (0, react_1.useEffect)(function () {
23
23
  listeners.add(updateClipboardData);
24
24
  return function () {
25
25
  listeners.delete(updateClipboardData);
@@ -27,3 +27,4 @@ exports.useClipboard = function () {
27
27
  }, []);
28
28
  return [data, setString];
29
29
  };
30
+ exports.useClipboard = useClipboard;
@@ -73,6 +73,22 @@ RCT_EXPORT_METHOD(getString:(RCTPromiseResolveBlock)resolve
73
73
  resolve((clipboard.string ? : @""));
74
74
  }
75
75
 
76
+ RCT_EXPORT_METHOD(setImage:(NSString *)content
77
+ resolve:(RCTPromiseResolveBlock) resolve
78
+ reject:(RCTPromiseRejectBlock) reject
79
+ ) {
80
+ @try {
81
+ UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
82
+ NSData *imageData = [[NSData alloc]initWithBase64EncodedString:content options:NSDataBase64DecodingIgnoreUnknownCharacters];
83
+ [pasteboard setImage:[UIImage imageWithData:imageData]];
84
+ resolve(nil);
85
+ }
86
+ @catch (NSException *exception) {
87
+ reject(@"Clipboard:setImage", exception.reason, nil);
88
+ }
89
+ }
90
+
91
+
76
92
  RCT_EXPORT_METHOD(getImagePNG:(RCTPromiseResolveBlock)resolve
77
93
  reject:(__unused RCTPromiseRejectBlock)reject)
78
94
  {
@@ -143,4 +159,48 @@ RCT_EXPORT_METHOD(hasURL:(RCTPromiseResolveBlock)resolve
143
159
  resolve([NSNumber numberWithBool: urlPresent]);
144
160
  }
145
161
 
162
+ RCT_EXPORT_METHOD(hasNumber:(RCTPromiseResolveBlock)resolve
163
+ reject:(__unused RCTPromiseRejectBlock)reject)
164
+ {
165
+ if (@available(iOS 14, *)) {
166
+ UIPasteboard *board = [UIPasteboard generalPasteboard];
167
+ [board detectPatternsForPatterns:[NSSet setWithObjects:UIPasteboardDetectionPatternProbableWebURL, UIPasteboardDetectionPatternNumber, UIPasteboardDetectionPatternProbableWebSearch, nil]
168
+ completionHandler:^(NSSet<UIPasteboardDetectionPattern> * _Nullable set, NSError * _Nullable error) {
169
+ BOOL numberPresent = NO;
170
+ for (NSString *type in set) {
171
+ if ([type isEqualToString:UIPasteboardDetectionPatternNumber]) {
172
+ numberPresent = YES;
173
+ }
174
+ }
175
+ resolve([NSNumber numberWithBool: numberPresent]);
176
+ }];
177
+ } else {
178
+ resolve([NSNumber numberWithBool: NO]);
179
+ }
180
+ }
181
+
182
+ RCT_EXPORT_METHOD(hasWebURL:(RCTPromiseResolveBlock)resolve
183
+ reject:(__unused RCTPromiseRejectBlock)reject)
184
+ {
185
+ if (@available(iOS 14, *)) {
186
+ UIPasteboard *board = [UIPasteboard generalPasteboard];
187
+ [board detectPatternsForPatterns:[NSSet setWithObjects:UIPasteboardDetectionPatternProbableWebURL, UIPasteboardDetectionPatternNumber, UIPasteboardDetectionPatternProbableWebSearch, nil]
188
+ completionHandler:^(NSSet<UIPasteboardDetectionPattern> * _Nullable set, NSError * _Nullable error) {
189
+ BOOL webURLPresent = NO;
190
+ for (NSString *type in set) {
191
+ if ([type isEqualToString:UIPasteboardDetectionPatternProbableWebURL]) {
192
+ webURLPresent = YES;
193
+ }
194
+ }
195
+ resolve([NSNumber numberWithBool: webURLPresent]);
196
+ }];
197
+ } else {
198
+ resolve([NSNumber numberWithBool: NO]);
199
+ }
200
+
201
+ }
202
+
203
+
204
+
205
+
146
206
  @end
@@ -7,6 +7,7 @@ const ClipboardMock = {
7
7
  getString: jest.fn().mockResolvedValue('mockString'),
8
8
  getImagePNG: jest.fn(),
9
9
  getImageJPG: jest.fn(),
10
+ setImage: jest.fn(),
10
11
  setString: jest.fn(),
11
12
  hasString: jest.fn().mockResolvedValue(true),
12
13
  hasImage: jest.fn().mockResolvedValue(true),
@@ -15,9 +16,11 @@ const ClipboardMock = {
15
16
  removeAllListeners: jest.fn(),
16
17
  };
17
18
 
18
- const RNCClipboardMock = {};
19
+ const useClipboard = jest.fn(() => ['mockString', jest.fn()]);
19
20
 
20
- RNCClipboardMock.Clipboard = ClipboardMock;
21
- RNCClipboardMock.useClipboard = jest.fn(() => ['mockString', jest.fn()]);
21
+ const RNCClipboardMock = {
22
+ ...ClipboardMock,
23
+ useClipboard,
24
+ };
22
25
 
23
26
  module.exports = RNCClipboardMock;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-clipboard/clipboard",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "description": "React Native Clipboard API for macOS, iOS, Android, and Windows",
5
5
  "keywords": [
6
6
  "Clipboard",
@@ -27,7 +27,8 @@
27
27
  "macos",
28
28
  "android",
29
29
  "windows",
30
- "jest"
30
+ "jest",
31
+ "!android/**/build/*"
31
32
  ],
32
33
  "scripts": {
33
34
  "ios": "react-native run-ios --project-path \"./example/ios\"",
@@ -36,7 +37,7 @@
36
37
  "start": "react-native start",
37
38
  "build": "tsc",
38
39
  "lint": "eslint src --ext .ts,.tsx --cache",
39
- "prepare": "yarn build",
40
+ "prepare": "npm run build",
40
41
  "test": "jest",
41
42
  "type-check": "tsc --noEmit"
42
43
  },
@@ -48,16 +49,16 @@
48
49
  "@react-native-community/eslint-config": "^2.0.0",
49
50
  "@types/react-native": "^0.64.8",
50
51
  "babel-jest": "^26.1.0",
51
- "eslint": "^6.8.0",
52
+ "eslint": "^7.32.0",
52
53
  "eslint-plugin-prettier": "^3.1.2",
53
54
  "jest": "^26.1.0",
54
55
  "metro-react-native-babel-preset": "^0.64.0",
55
- "prettier": "^2.0.2",
56
+ "prettier": "^2.4.1",
56
57
  "react": "17.0.1",
57
58
  "react-native": "0.64.1",
58
59
  "react-native-macos": "^0.62.0-0",
59
60
  "react-test-renderer": "16.9.0",
60
- "typescript": "^3.8.3"
61
+ "typescript": "^4.4.3"
61
62
  },
62
63
  "peerDependencies": {
63
64
  "react": ">=16.0",