@react-native-clipboard/clipboard 1.10.0 → 1.11.1

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
@@ -159,7 +159,20 @@ async _getContent() {
159
159
  }
160
160
  ```
161
161
 
162
- ---
162
+ #### `getStrings()`
163
+
164
+ ```jsx
165
+ static getStrings()
166
+ ```
167
+
168
+ (iOS only)
169
+ Get contents of string array type, this method returns a `Promise`, so you can use following code to get clipboard content
170
+
171
+ ```jsx
172
+ async _getContent() {
173
+ var content = await Clipboard.getStrings();
174
+ }
175
+ ```
163
176
 
164
177
  #### `setString()`
165
178
 
@@ -181,6 +194,28 @@ _setContent() {
181
194
  | ------- | ------ | -------- | ----------------------------------------- |
182
195
  | content | string | Yes | The content to be stored in the clipboard |
183
196
 
197
+ #### `setStrings()`
198
+
199
+ ```jsx
200
+ static setStrings(content)
201
+ ```
202
+
203
+ (iOS only)
204
+ Set content of string array type. You can use following code to set clipboard content
205
+
206
+ ```jsx
207
+ _setContent() {
208
+ Clipboard.setStrings(['hello world', 'second string']);
209
+ }
210
+ ```
211
+
212
+ #### Parameters
213
+
214
+ | Name | Type | Required | Description |
215
+ | ------- | -------- | -------- | ----------------------------------------- |
216
+ | content | string[] | Yes | The content to be stored in the clipboard |
217
+
218
+
184
219
  #### `hasString()`
185
220
 
186
221
  ```jsx
@@ -242,6 +277,20 @@ export const HooksSample = () => {
242
277
  };
243
278
  ```
244
279
 
280
+ ### `getImage()`
281
+
282
+ ```jsx
283
+ static getImage()
284
+ ```
285
+
286
+ Get content of image in base64 string type, this method returns a `Promise`, so you can use following code to get clipboard content (ANDROID only)
287
+
288
+ ```jsx
289
+ async _getContent() {
290
+ var content = await Clipboard.getImage();
291
+ }
292
+ ```
293
+
245
294
  ## Mocking Clipboard
246
295
 
247
296
  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.
@@ -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-14/"/>
3
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
4
4
  <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
5
5
  <classpathentry kind="output" path="bin/default"/>
6
6
  </classpath>
@@ -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(7.0-rc-1))
4
+ connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.4.2))
5
5
  connection.project.dir=../example/android
6
6
  eclipse.preferences.version=1
7
7
  gradle.user.home=
8
- java.home=/Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home
8
+ java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
9
9
  jvm.arguments=
10
10
  offline.mode=false
11
11
  override.workspace.settings=true
@@ -1,4 +1,4 @@
1
- ReactNativeClipBoard_compileSdkVersion=28
2
- ReactNativeClipBoard_buildToolsVersion=28.0.3
3
- ReactNativeClipBoard_targetSdkVersion=27
1
+ ReactNativeClipBoard_compileSdkVersion=30
2
+ ReactNativeClipBoard_buildToolsVersion=30.0.2
3
+ ReactNativeClipBoard_targetSdkVersion=30
4
4
  ReactNativeClipBoard_minSdkVersion=16
@@ -7,6 +7,7 @@
7
7
 
8
8
  package com.reactnativecommunity.clipboard;
9
9
 
10
+ import android.annotation.TargetApi;
10
11
  import android.content.ClipDescription;
11
12
  import android.content.ClipboardManager;
12
13
  import android.content.ClipData;
@@ -14,13 +15,13 @@ import android.content.ContentResolver;
14
15
  import android.content.Context;
15
16
  import android.graphics.Bitmap;
16
17
  import android.net.Uri;
18
+ import android.os.Build;
17
19
  import android.provider.MediaStore;
18
20
  import android.util.Base64;
19
21
  import android.util.Log;
20
22
 
21
23
  import com.facebook.react.bridge.ReactApplicationContext;
22
24
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
23
- import com.facebook.react.bridge.ContextBaseJavaModule;
24
25
  import com.facebook.react.bridge.ReactMethod;
25
26
  import com.facebook.react.bridge.Promise;
26
27
  import com.facebook.react.module.annotations.ReactModule;
@@ -28,12 +29,13 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
28
29
 
29
30
  import java.io.ByteArrayOutputStream;
30
31
  import java.io.IOException;
32
+ import java.nio.ByteBuffer;
31
33
 
32
34
  /**
33
35
  * A module that allows JS to get/set clipboard contents.
34
36
  */
35
37
  @ReactModule(name = ClipboardModule.NAME)
36
- public class ClipboardModule extends ContextBaseJavaModule {
38
+ public class ClipboardModule extends ReactContextBaseJavaModule {
37
39
 
38
40
  public static final String CLIPBOARD_TEXT_CHANGED = "RNCClipboard_TEXT_CHANGED";
39
41
  private ReactApplicationContext reactContext;
@@ -45,6 +47,12 @@ public class ClipboardModule extends ContextBaseJavaModule {
45
47
  }
46
48
 
47
49
  public static final String NAME = "RNCClipboard";
50
+ public static final String MIMETYPE_JPEG = "image/jpeg";
51
+ public static final String MIMETYPE_JPG = "image/jpg";
52
+ public static final String MIMETYPE_PNG = "image/png";
53
+ public static final String MIMETYPE_WEBP = "image/webp";
54
+ public static final String MIMETYPE_HEIC = "image/heic";
55
+ public static final String MIMETYPE_HEIF = "image/heif";
48
56
 
49
57
  @Override
50
58
  public String getName() {
@@ -52,7 +60,7 @@ public class ClipboardModule extends ContextBaseJavaModule {
52
60
  }
53
61
 
54
62
  private ClipboardManager getClipboardService() {
55
- return (ClipboardManager) getContext().getSystemService(getContext().CLIPBOARD_SERVICE);
63
+ return (ClipboardManager) reactContext.getSystemService(Context.CLIPBOARD_SERVICE);
56
64
  }
57
65
 
58
66
  @ReactMethod
@@ -111,25 +119,35 @@ public class ClipboardModule extends ContextBaseJavaModule {
111
119
  ContentResolver cr = reactContext.getContentResolver();
112
120
  String mimeType = cr.getType(pasteUri);
113
121
  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")){
122
+ try {
123
+ Bitmap bitmap = MediaStore.Images.Media.getBitmap(cr, pasteUri);
124
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
125
+ switch(mimeType){
126
+ case MIMETYPE_JPEG:
127
+ case MIMETYPE_JPG:
120
128
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
121
- }
122
- if (mimeType.equals("image/png")){
129
+ break;
130
+ case MIMETYPE_PNG:
131
+ case MIMETYPE_HEIC:
132
+ case MIMETYPE_HEIF:
123
133
  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();
134
+ break;
135
+ case MIMETYPE_WEBP:
136
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q){
137
+ bitmap.compress(Bitmap.CompressFormat.WEBP_LOSSLESS, 100, outputStream);
138
+ break;
139
+ }
140
+ bitmap.compress(Bitmap.CompressFormat.WEBP, 100, outputStream);
141
+ break;
142
+ default:
143
+ return;
132
144
  }
145
+ byte[] byteArray = outputStream.toByteArray();
146
+ String encodedString = Base64.encodeToString(byteArray, Base64.DEFAULT);
147
+ promise.resolve("data:" + mimeType + ";base64," + encodedString);
148
+ } catch (IOException e) {
149
+ promise.reject(e);
150
+ e.printStackTrace();
133
151
  }
134
152
  }
135
153
  }
@@ -12,6 +12,16 @@ export declare const Clipboard: {
12
12
  * ```
13
13
  */
14
14
  getString(): Promise<string>;
15
+ /**
16
+ * (iOS Only)
17
+ * Get contents of string array type, this method returns a `Promise`, so you can use following code to get clipboard content
18
+ * ```javascript
19
+ * async _getContent() {
20
+ * var content = await Clipboard.getStrings();
21
+ * }
22
+ * ```
23
+ */
24
+ getStrings(): Promise<string[]>;
15
25
  /**
16
26
  * Get clipboard image as PNG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
17
27
  * ```javascript
@@ -31,17 +41,25 @@ export declare const Clipboard: {
31
41
  */
32
42
  getImageJPG(): Promise<string>;
33
43
  /**
44
+ * (iOS Only)
34
45
  * Set content of base64 image type. You can use following code to set clipboard content
35
46
  * ```javascript
36
47
  * _setContent() {
37
48
  * Clipboard.setImage(...);
38
49
  * }
39
- *
40
- * iOS only
41
50
  * ```
42
51
  * @param the content to be stored in the clipboard.
43
52
  */
44
53
  setImage(content: string): void;
54
+ /**
55
+ * (Android Only)
56
+ * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
57
+ * ```javascript
58
+ * async _getContent() {
59
+ * var content = await Clipboard.getImage();
60
+ * }
61
+ * ```
62
+ */
45
63
  getImage(): Promise<string>;
46
64
  /**
47
65
  * Set content of string type. You can use following code to set clipboard content
@@ -53,6 +71,16 @@ export declare const Clipboard: {
53
71
  * @param the content to be stored in the clipboard.
54
72
  */
55
73
  setString(content: string): void;
74
+ /**
75
+ * Set content of string array type. You can use following code to set clipboard content
76
+ * ```javascript
77
+ * _setContent() {
78
+ * Clipboard.setStrings(['hello world', 'second string']);
79
+ * }
80
+ * ```
81
+ * @param the content to be stored in the clipboard.
82
+ */
83
+ setStrings(content: string[]): void;
56
84
  /**
57
85
  * Returns whether the clipboard has content or is empty.
58
86
  * This method returns a `Promise`, so you can use following code to get clipboard content
@@ -74,7 +102,7 @@ export declare const Clipboard: {
74
102
  */
75
103
  hasImage(): any;
76
104
  /**
77
- * (IOS Only)
105
+ * (iOS Only)
78
106
  * Returns whether the clipboard has a URL content. Can check
79
107
  * if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+
80
108
  * This method returns a `Promise`, so you can use following code to check for url content in clipboard.
@@ -86,7 +114,7 @@ export declare const Clipboard: {
86
114
  */
87
115
  hasURL(): any;
88
116
  /**
89
- * (IOS 14+ Only)
117
+ * (iOS 14+ Only)
90
118
  * Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
91
119
  * if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
92
120
  * This method returns a `Promise`, so you can use following code to check for Number content in clipboard.
@@ -98,7 +126,7 @@ export declare const Clipboard: {
98
126
  */
99
127
  hasNumber(): any;
100
128
  /**
101
- * (IOS 14+ Only)
129
+ * (iOS 14+ Only)
102
130
  * Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
103
131
  * if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
104
132
  * This method returns a `Promise`, so you can use following code to check for WebURL content in clipboard.
package/dist/Clipboard.js CHANGED
@@ -37,6 +37,18 @@ exports.Clipboard = {
37
37
  getString: function () {
38
38
  return NativeClipboard_1.default.getString();
39
39
  },
40
+ /**
41
+ * (iOS Only)
42
+ * Get contents of string array type, 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.getStrings();
46
+ * }
47
+ * ```
48
+ */
49
+ getStrings: function () {
50
+ return NativeClipboard_1.default.getStrings();
51
+ },
40
52
  /**
41
53
  * Get clipboard image as PNG in base64, this method returns a `Promise`, so you can use following code to get clipboard content
42
54
  * ```javascript
@@ -60,13 +72,12 @@ exports.Clipboard = {
60
72
  return NativeClipboard_1.default.getImageJPG();
61
73
  },
62
74
  /**
75
+ * (iOS Only)
63
76
  * Set content of base64 image type. You can use following code to set clipboard content
64
77
  * ```javascript
65
78
  * _setContent() {
66
79
  * Clipboard.setImage(...);
67
80
  * }
68
- *
69
- * iOS only
70
81
  * ```
71
82
  * @param the content to be stored in the clipboard.
72
83
  */
@@ -76,7 +87,7 @@ exports.Clipboard = {
76
87
  }
77
88
  NativeClipboard_1.default.setImage(content);
78
89
  },
79
- /*
90
+ /**
80
91
  * (Android Only)
81
92
  * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
82
93
  * ```javascript
@@ -100,6 +111,18 @@ exports.Clipboard = {
100
111
  setString: function (content) {
101
112
  NativeClipboard_1.default.setString(content);
102
113
  },
114
+ /**
115
+ * Set content of string array type. You can use following code to set clipboard content
116
+ * ```javascript
117
+ * _setContent() {
118
+ * Clipboard.setStrings(['hello world', 'second string']);
119
+ * }
120
+ * ```
121
+ * @param the content to be stored in the clipboard.
122
+ */
123
+ setStrings: function (content) {
124
+ NativeClipboard_1.default.setStrings(content);
125
+ },
103
126
  /**
104
127
  * Returns whether the clipboard has content or is empty.
105
128
  * This method returns a `Promise`, so you can use following code to get clipboard content
@@ -125,7 +148,7 @@ exports.Clipboard = {
125
148
  return NativeClipboard_1.default.hasImage();
126
149
  },
127
150
  /**
128
- * (IOS Only)
151
+ * (iOS Only)
129
152
  * Returns whether the clipboard has a URL content. Can check
130
153
  * if there is a URL content in clipboard without triggering PasteBoard notification for iOS 14+
131
154
  * This method returns a `Promise`, so you can use following code to check for url content in clipboard.
@@ -142,7 +165,7 @@ exports.Clipboard = {
142
165
  return NativeClipboard_1.default.hasURL();
143
166
  },
144
167
  /**
145
- * (IOS 14+ Only)
168
+ * (iOS 14+ Only)
146
169
  * Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
147
170
  * if there is a Number content in clipboard without triggering PasteBoard notification for iOS 14+
148
171
  * This method returns a `Promise`, so you can use following code to check for Number content in clipboard.
@@ -159,7 +182,7 @@ exports.Clipboard = {
159
182
  return NativeClipboard_1.default.hasNumber();
160
183
  },
161
184
  /**
162
- * (IOS 14+ Only)
185
+ * (iOS 14+ Only)
163
186
  * Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
164
187
  * if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
165
188
  * This method returns a `Promise`, so you can use following code to check for WebURL content in clipboard.
@@ -73,6 +73,19 @@ RCT_EXPORT_METHOD(getString:(RCTPromiseResolveBlock)resolve
73
73
  resolve((clipboard.string ? : @""));
74
74
  }
75
75
 
76
+ RCT_EXPORT_METHOD(setStrings:(NSArray<NSString *> *)array)
77
+ {
78
+ UIPasteboard *clipboard = [UIPasteboard generalPasteboard];
79
+ clipboard.strings = (array ? : @[]);
80
+ }
81
+
82
+ RCT_EXPORT_METHOD(getStrings:(RCTPromiseResolveBlock)resolve
83
+ reject:(__unused RCTPromiseRejectBlock)reject)
84
+ {
85
+ UIPasteboard *clipboard = [UIPasteboard generalPasteboard];
86
+ resolve((clipboard.strings ? : @[]));
87
+ }
88
+
76
89
  RCT_EXPORT_METHOD(setImage:(NSString *)content
77
90
  resolve:(RCTPromiseResolveBlock) resolve
78
91
  reject:(RCTPromiseRejectBlock) reject
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-clipboard/clipboard",
3
- "version": "1.10.0",
3
+ "version": "1.11.1",
4
4
  "description": "React Native Clipboard API for macOS, iOS, Android, and Windows",
5
5
  "keywords": [
6
6
  "Clipboard",