@react-native-clipboard/clipboard 1.14.3 → 1.15.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/README.md CHANGED
@@ -215,7 +215,6 @@ _setContent() {
215
215
  | ------- | -------- | -------- | ----------------------------------------- |
216
216
  | content | string[] | Yes | The content to be stored in the clipboard |
217
217
 
218
-
219
218
  #### `hasString()`
220
219
 
221
220
  ```jsx
@@ -255,8 +254,6 @@ static hasWebURL()
255
254
  Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content.
256
255
  Can check if there is a WebURL content in clipboard without triggering PasteBoard notification for iOS 14+
257
256
 
258
-
259
-
260
257
  ### useClipboard
261
258
 
262
259
  `useClipboard` is a utility hooks for the `Clipboard` module. `data` contains the content stored in the clipboard.
@@ -283,7 +280,7 @@ export const HooksSample = () => {
283
280
  static getImage()
284
281
  ```
285
282
 
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)
283
+ 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)
287
284
 
288
285
  ```jsx
289
286
  async _getContent() {
@@ -52,7 +52,7 @@ export declare const Clipboard: {
52
52
  */
53
53
  setImage(content: string): void;
54
54
  /**
55
- * (Android Only)
55
+ * (iOS and Android Only)
56
56
  * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
57
57
  * ```javascript
58
58
  * async _getContent() {
package/dist/Clipboard.js CHANGED
@@ -88,7 +88,7 @@ exports.Clipboard = {
88
88
  NativeClipboardModule_1.default.setImage(content);
89
89
  },
90
90
  /**
91
- * (Android Only)
91
+ * (iOS and Android Only)
92
92
  * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
93
93
  * ```javascript
94
94
  * async _getContent() {
@@ -50,7 +50,7 @@ export interface Spec extends TurboModule {
50
50
  */
51
51
  setImage(content: string): Promise<void>;
52
52
  /**
53
- * (Android Only)
53
+ * (iOS and Android Only)
54
54
  * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
55
55
  * ```javascript
56
56
  * async _getContent() {
@@ -1,6 +1,7 @@
1
1
  #import "RNCClipboard.h"
2
2
 
3
-
3
+ #import <MobileCoreServices/MobileCoreServices.h>
4
+ #import <MobileCoreServices/UTType.h>
4
5
  #import <UIKit/UIKit.h>
5
6
  #import <React/RCTBridge.h>
6
7
  #import <React/RCTEventDispatcher.h>
@@ -215,7 +216,22 @@ RCT_EXPORT_METHOD(hasWebURL:(RCTPromiseResolveBlock)resolve
215
216
 
216
217
  RCT_EXPORT_METHOD(getImage:(RCTPromiseResolveBlock)resolve
217
218
  reject:(__unused RCTPromiseRejectBlock)reject){
218
- reject(@"Clipboard:getImage", @"getImage is not supported on iOS", nil);
219
+ UIPasteboard *clipboard = [UIPasteboard generalPasteboard];
220
+ NSString *withPrefix;
221
+ for (NSItemProvider *itemProvider in clipboard.itemProviders) {
222
+ if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeImage]) {
223
+ for (NSString *identifier in itemProvider.registeredTypeIdentifiers) {
224
+ if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeImage)) {
225
+ NSString *MIMEType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)identifier, kUTTagClassMIMEType);
226
+ NSString *imageDataBase64 = [[clipboard dataForPasteboardType:identifier] base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
227
+ withPrefix = [NSString stringWithFormat:@"data:%@;base64,%@", MIMEType, imageDataBase64];
228
+ break;
229
+ }
230
+ }
231
+ break;
232
+ }
233
+ }
234
+ resolve((withPrefix ? : NULL));
219
235
  }
220
236
 
221
237
  RCT_EXPORT_METHOD(addListener : (NSString *)eventName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-clipboard/clipboard",
3
- "version": "1.14.3",
3
+ "version": "1.15.0",
4
4
  "description": "React Native Clipboard API for macOS, iOS, Android, and Windows",
5
5
  "keywords": [
6
6
  "Clipboard",
@@ -32,7 +32,7 @@
32
32
  "!android/**/build/*"
33
33
  ],
34
34
  "scripts": {
35
- "ios": "react-native run-ios --project-path \"./example/ios\"",
35
+ "ios": "react-native run-ios",
36
36
  "android": "react-native run-android --root example",
37
37
  "windows": "cd example && react-native run-windows",
38
38
  "start": "react-native start",
package/src/Clipboard.ts CHANGED
@@ -71,7 +71,7 @@ export const Clipboard = {
71
71
  NativeClipboard.setImage(content);
72
72
  },
73
73
  /**
74
- * (Android Only)
74
+ * (iOS and Android Only)
75
75
  * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
76
76
  * ```javascript
77
77
  * async _getContent() {
@@ -59,7 +59,7 @@ export interface Spec extends TurboModule {
59
59
  */
60
60
  setImage(content: string): Promise<void>;
61
61
  /**
62
- * (Android Only)
62
+ * (iOS and Android Only)
63
63
  * Get clipboard image in base64, this method returns a `Promise`, so you can use following code to get clipboard content
64
64
  * ```javascript
65
65
  * async _getContent() {