331 lines
12 KiB
Diff
331 lines
12 KiB
Diff
diff --git a/node_modules/@react-native-clipboard/clipboard/android/src/main/java/com/reactnativecommunity/clipboard/ClipboardModule.java b/node_modules/@react-native-clipboard/clipboard/android/src/main/java/com/reactnativecommunity/clipboard/ClipboardModule.java
|
|
index 048ebe5..01fa3ad 100644
|
|
--- a/node_modules/@react-native-clipboard/clipboard/android/src/main/java/com/reactnativecommunity/clipboard/ClipboardModule.java
|
|
+++ b/node_modules/@react-native-clipboard/clipboard/android/src/main/java/com/reactnativecommunity/clipboard/ClipboardModule.java
|
|
@@ -24,6 +24,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
import com.facebook.react.bridge.ReactMethod;
|
|
import com.facebook.react.bridge.Promise;
|
|
+import com.facebook.react.bridge.WritableNativeMap;
|
|
import com.facebook.react.module.annotations.ReactModule;
|
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
|
|
@@ -70,9 +71,9 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
|
ClipData clipData = clipboard.getPrimaryClip();
|
|
if (clipData != null && clipData.getItemCount() >= 1) {
|
|
ClipData.Item firstItem = clipboard.getPrimaryClip().getItemAt(0);
|
|
- promise.resolve("" + firstItem.getText());
|
|
+ promise.resolve(firstItem.getText());
|
|
} else {
|
|
- promise.resolve("");
|
|
+ promise.resolve(null);
|
|
}
|
|
} catch (Exception e) {
|
|
promise.reject(e);
|
|
@@ -95,34 +96,37 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
|
try {
|
|
ClipboardManager clipboard = getClipboardService();
|
|
ClipData clipData = clipboard.getPrimaryClip();
|
|
- promise.resolve(clipData != null && clipData.getItemCount() >= 1);
|
|
+ if (clipData != null && clipData.getItemCount() >= 1) {
|
|
+ ClipData.Item firstItem = clipboard.getPrimaryClip().getItemAt(0);
|
|
+ promise.resolve(firstItem.getText() != null);
|
|
+ } else {
|
|
+ promise.resolve(false);
|
|
+ }
|
|
} catch (Exception e) {
|
|
promise.reject(e);
|
|
}
|
|
}
|
|
|
|
@ReactMethod
|
|
- public void getImage(Promise promise){
|
|
+ public void getImage(Promise promise) {
|
|
ClipboardManager clipboardManager = getClipboardService();
|
|
- if (!(clipboardManager.hasPrimaryClip())){
|
|
- promise.resolve("");
|
|
- }
|
|
- else if (clipboardManager.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)){
|
|
- promise.resolve("");
|
|
- }
|
|
- else {
|
|
+ if (!(clipboardManager.hasPrimaryClip())) {
|
|
+ promise.resolve(null);
|
|
+ } else if (clipboardManager.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
|
|
+ promise.resolve(null);
|
|
+ } else {
|
|
ClipData clipData = clipboardManager.getPrimaryClip();
|
|
- if(clipData != null){
|
|
+ if (clipData != null) {
|
|
ClipData.Item item = clipData.getItemAt(0);
|
|
Uri pasteUri = item.getUri();
|
|
- if (pasteUri != null){
|
|
+ if (pasteUri != null) {
|
|
ContentResolver cr = reactContext.getContentResolver();
|
|
String mimeType = cr.getType(pasteUri);
|
|
- if (mimeType != null){
|
|
+ if (mimeType != null) {
|
|
try {
|
|
Bitmap bitmap = MediaStore.Images.Media.getBitmap(cr, pasteUri);
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
- switch(mimeType){
|
|
+ switch (mimeType) {
|
|
case MIMETYPE_JPEG:
|
|
case MIMETYPE_JPG:
|
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
|
@@ -133,7 +137,7 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
|
|
break;
|
|
case MIMETYPE_WEBP:
|
|
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q){
|
|
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
|
|
bitmap.compress(Bitmap.CompressFormat.WEBP_LOSSLESS, 100, outputStream);
|
|
break;
|
|
}
|
|
@@ -156,6 +160,77 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
|
}
|
|
}
|
|
|
|
+ @ReactMethod
|
|
+ public void hasImage(Promise promise) {
|
|
+ try {
|
|
+ ClipboardManager clipboard = getClipboardService();
|
|
+ ClipData clipData = clipboard.getPrimaryClip();
|
|
+ if (clipData != null && clipData.getItemCount() >= 1) {
|
|
+ ClipData.Item firstItem = clipboard.getPrimaryClip().getItemAt(0);
|
|
+ Uri pasteUri = firstItem.getUri();
|
|
+ if (pasteUri != null) {
|
|
+ ContentResolver cr = reactContext.getContentResolver();
|
|
+ String mimeType = cr.getType(pasteUri);
|
|
+ if (mimeType != null) {
|
|
+ promise.resolve(mimeType.startsWith("image/"));
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ promise.resolve(false);
|
|
+ } catch (Exception e) {
|
|
+ promise.reject(e);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @ReactMethod
|
|
+ public void getURI(Promise promise) {
|
|
+ try {
|
|
+ ClipboardManager clipboard = getClipboardService();
|
|
+ ClipData clipData = clipboard.getPrimaryClip();
|
|
+ if (clipData != null && clipData.getItemCount() >= 1) {
|
|
+ ClipData.Item firstItem = clipboard.getPrimaryClip().getItemAt(0);
|
|
+ Uri uri = firstItem.getUri();
|
|
+ if (uri != null) {
|
|
+ promise.resolve(uri.toString());
|
|
+ } else {
|
|
+ promise.resolve(null);
|
|
+ }
|
|
+ }
|
|
+ promise.resolve(null);
|
|
+ } catch (Exception e) {
|
|
+ promise.reject(e);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @ReactMethod
|
|
+ public void setURI(String uri) {
|
|
+ try {
|
|
+ ClipData clipdata = ClipData.newUri(reactContext.getContentResolver(), "URI", Uri.parse(uri));
|
|
+ ClipboardManager clipboard = getClipboardService();
|
|
+ clipboard.setPrimaryClip(clipdata);
|
|
+ } catch (Exception e) {
|
|
+ e.printStackTrace();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @ReactMethod
|
|
+ public void hasURI(Promise promise) {
|
|
+ try {
|
|
+ ClipboardManager clipboard = getClipboardService();
|
|
+ ClipData clipData = clipboard.getPrimaryClip();
|
|
+ if (clipData != null && clipData.getItemCount() >= 1) {
|
|
+ ClipData.Item firstItem = clipboard.getPrimaryClip().getItemAt(0);
|
|
+ Uri pasteUri = firstItem.getUri();
|
|
+ promise.resolve(pasteUri != null);
|
|
+ } else {
|
|
+ promise.resolve(false);
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ promise.reject(e);
|
|
+ }
|
|
+ }
|
|
+
|
|
@ReactMethod
|
|
public void setListener() {
|
|
try {
|
|
@@ -164,8 +239,8 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
|
@Override
|
|
public void onPrimaryClipChanged() {
|
|
reactContext
|
|
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
- .emit(CLIPBOARD_TEXT_CHANGED, null);
|
|
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
+ .emit(CLIPBOARD_TEXT_CHANGED, null);
|
|
}
|
|
};
|
|
clipboard.addPrimaryClipChangedListener(listener);
|
|
@@ -176,8 +251,8 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
|
|
|
@ReactMethod
|
|
public void removeListener() {
|
|
- if(listener != null){
|
|
- try{
|
|
+ if (listener != null) {
|
|
+ try {
|
|
ClipboardManager clipboard = getClipboardService();
|
|
clipboard.removePrimaryClipChangedListener(listener);
|
|
} catch (Exception e) {
|
|
diff --git a/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.d.ts b/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.d.ts
|
|
index a3e4abd..9fc11e6 100644
|
|
--- a/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.d.ts
|
|
+++ b/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.d.ts
|
|
@@ -81,6 +81,38 @@ export declare const Clipboard: {
|
|
* @param the content to be stored in the clipboard.
|
|
*/
|
|
setStrings(content: string[]): void;
|
|
+ /**
|
|
+ * (Android Only)
|
|
+ * Get content of URI type. You can use following code to get clipboard content
|
|
+ * ```javascript
|
|
+ * async _getContent() {
|
|
+ * var content = await Clipboard.getURI();
|
|
+ * }
|
|
+ * ```
|
|
+ */
|
|
+ getURI(): Promise<string>;
|
|
+ /**
|
|
+ * (Android Only)
|
|
+ * Set content of URI type. You can use following code to set clipboard content
|
|
+ * ```javascript
|
|
+ * _setContent() {
|
|
+ * Clipboard.setURI('file://com.example.app/files/image.png');
|
|
+ * }
|
|
+ * ```
|
|
+ * @param the content to be stored in the clipboard.
|
|
+ */
|
|
+ setURI(content: string): void;
|
|
+ /**
|
|
+ * (Android Only)
|
|
+ * Returns whether the clipboard has a URI or is empty.
|
|
+ * This method returns a `Promise`, so you can use following code to check clipboard content
|
|
+ * ```javascript
|
|
+ * async _hasContent() {
|
|
+ * var hasContent = await Clipboard.hasURI();
|
|
+ * }
|
|
+ * ```
|
|
+ */
|
|
+ hasURI(): Promise<boolean>;
|
|
/**
|
|
* Returns whether the clipboard has content or is empty.
|
|
* This method returns a `Promise`, so you can use following code to get clipboard content
|
|
@@ -90,7 +122,7 @@ export declare const Clipboard: {
|
|
* }
|
|
* ```
|
|
*/
|
|
- hasString(): any;
|
|
+ hasString(): Promise<boolean>;
|
|
/**
|
|
* Returns whether the clipboard has an image or is empty.
|
|
* This method returns a `Promise`, so you can use following code to check clipboard content
|
|
@@ -100,7 +132,7 @@ export declare const Clipboard: {
|
|
* }
|
|
* ```
|
|
*/
|
|
- hasImage(): any;
|
|
+ hasImage(): Promise<boolean>;
|
|
/**
|
|
* (iOS Only)
|
|
* Returns whether the clipboard has a URL content. Can check
|
|
@@ -112,7 +144,7 @@ export declare const Clipboard: {
|
|
* }
|
|
* ```
|
|
*/
|
|
- hasURL(): any;
|
|
+ hasURL(): Promise<boolean>;
|
|
/**
|
|
* (iOS 14+ Only)
|
|
* Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
|
|
@@ -124,7 +156,7 @@ export declare const Clipboard: {
|
|
* }
|
|
* ```
|
|
*/
|
|
- hasNumber(): any;
|
|
+ hasNumber(): Promise<boolean>;
|
|
/**
|
|
* (iOS 14+ Only)
|
|
* Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
|
|
@@ -136,7 +168,7 @@ export declare const Clipboard: {
|
|
* }
|
|
* ```
|
|
*/
|
|
- hasWebURL(): any;
|
|
+ hasWebURL(): Promise<boolean>;
|
|
/**
|
|
* (iOS and Android Only)
|
|
* Adds a listener to get notifications when the clipboard has changed.
|
|
diff --git a/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js b/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js
|
|
index 67b7237..df3bff6 100644
|
|
--- a/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js
|
|
+++ b/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js
|
|
@@ -123,6 +123,53 @@ exports.Clipboard = {
|
|
setStrings: function (content) {
|
|
NativeClipboard_1.default.setStrings(content);
|
|
},
|
|
+ /**
|
|
+ * (Android Only)
|
|
+ * Get content of URI type. You can use following code to get clipboard content
|
|
+ * ```javascript
|
|
+ * async _getContent() {
|
|
+ * var content = await Clipboard.getURI();
|
|
+ * }
|
|
+ * ```
|
|
+ */
|
|
+ getURI: function () {
|
|
+ if (react_native_1.Platform.OS !== 'android') {
|
|
+ return;
|
|
+ }
|
|
+ return NativeClipboard_1.default.getURI();
|
|
+ },
|
|
+ /**
|
|
+ * (Android Only)
|
|
+ * Set content of URI type. You can use following code to set clipboard content
|
|
+ * ```javascript
|
|
+ * _setContent() {
|
|
+ * Clipboard.setURI('file://com.example.app/files/image.png');
|
|
+ * }
|
|
+ * ```
|
|
+ * @param the content to be stored in the clipboard.
|
|
+ */
|
|
+ setURI: function (content) {
|
|
+ if (react_native_1.Platform.OS !== 'android') {
|
|
+ return;
|
|
+ }
|
|
+ return NativeClipboard_1.default.setURI(content);
|
|
+ },
|
|
+ /**
|
|
+ * (Android Only)
|
|
+ * Returns whether the clipboard has a URI or is empty.
|
|
+ * This method returns a `Promise`, so you can use following code to check clipboard content
|
|
+ * ```javascript
|
|
+ * async _hasContent() {
|
|
+ * var hasContent = await Clipboard.hasURI();
|
|
+ * }
|
|
+ * ```
|
|
+ */
|
|
+ hasURI: function () {
|
|
+ if (react_native_1.Platform.OS !== 'android') {
|
|
+ return;
|
|
+ }
|
|
+ return NativeClipboard_1.default.hasURI();
|
|
+ },
|
|
/**
|
|
* Returns whether the clipboard has content or is empty.
|
|
* This method returns a `Promise`, so you can use following code to get clipboard content
|