Add pasting from clipboard
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -1,11 +1,134 @@
|
|||||||
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
|
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..8afa5b2 100644
|
index 048ebe5..01fa3ad 100644
|
||||||
--- a/node_modules/@react-native-clipboard/clipboard/android/src/main/java/com/reactnativecommunity/clipboard/ClipboardModule.java
|
--- 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
|
+++ b/node_modules/@react-native-clipboard/clipboard/android/src/main/java/com/reactnativecommunity/clipboard/ClipboardModule.java
|
||||||
@@ -156,6 +156,17 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
|
@@ -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
|
+ @ReactMethod
|
||||||
+ public void setURI(String uri) {
|
+ public void setURI(String uri) {
|
||||||
+ try {
|
+ try {
|
||||||
@@ -16,20 +139,69 @@ index 048ebe5..8afa5b2 100644
|
|||||||
+ e.printStackTrace();
|
+ 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
|
@ReactMethod
|
||||||
public void setListener() {
|
public void setListener() {
|
||||||
try {
|
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
|
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..904a199 100644
|
index a3e4abd..9fc11e6 100644
|
||||||
--- a/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.d.ts
|
--- a/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.d.ts
|
||||||
+++ b/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.d.ts
|
+++ b/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.d.ts
|
||||||
@@ -81,6 +81,17 @@ export declare const Clipboard: {
|
@@ -81,6 +81,38 @@ export declare const Clipboard: {
|
||||||
* @param the content to be stored in the clipboard.
|
* @param the content to be stored in the clipboard.
|
||||||
*/
|
*/
|
||||||
setStrings(content: string[]): void;
|
setStrings(content: string[]): void;
|
||||||
+ /**
|
+ /**
|
||||||
+ * (Android Only)
|
+ * (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
|
+ * Set content of URI type. You can use following code to set clipboard content
|
||||||
+ * ```javascript
|
+ * ```javascript
|
||||||
+ * _setContent() {
|
+ * _setContent() {
|
||||||
@@ -39,19 +211,90 @@ index a3e4abd..904a199 100644
|
|||||||
+ * @param the content to be stored in the clipboard.
|
+ * @param the content to be stored in the clipboard.
|
||||||
+ */
|
+ */
|
||||||
+ setURI(content: string): void;
|
+ 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.
|
* Returns whether the clipboard has content or is empty.
|
||||||
* This method returns a `Promise`, so you can use following code to get clipboard content
|
* 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
|
diff --git a/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js b/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js
|
||||||
index 67b7237..0a74329 100644
|
index 67b7237..df3bff6 100644
|
||||||
--- a/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js
|
--- a/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js
|
||||||
+++ b/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js
|
+++ b/node_modules/@react-native-clipboard/clipboard/dist/Clipboard.js
|
||||||
@@ -123,6 +123,22 @@ exports.Clipboard = {
|
@@ -123,6 +123,53 @@ exports.Clipboard = {
|
||||||
setStrings: function (content) {
|
setStrings: function (content) {
|
||||||
NativeClipboard_1.default.setStrings(content);
|
NativeClipboard_1.default.setStrings(content);
|
||||||
},
|
},
|
||||||
+ /**
|
+ /**
|
||||||
+ * (Android Only)
|
+ * (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
|
+ * Set content of URI type. You can use following code to set clipboard content
|
||||||
+ * ```javascript
|
+ * ```javascript
|
||||||
+ * _setContent() {
|
+ * _setContent() {
|
||||||
@@ -65,6 +308,22 @@ index 67b7237..0a74329 100644
|
|||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+ return NativeClipboard_1.default.setURI(content);
|
+ 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.
|
* Returns whether the clipboard has content or is empty.
|
||||||
|
@@ -1,12 +1,18 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { Keyboard, StyleSheet } from 'react-native';
|
import { Keyboard, StyleSheet } from 'react-native';
|
||||||
import { FAB } from 'react-native-paper';
|
import { FAB, Snackbar } from 'react-native-paper';
|
||||||
import { ParamListBase, useNavigation } from '@react-navigation/native';
|
import { ParamListBase, useNavigation } from '@react-navigation/native';
|
||||||
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||||
import { pick } from 'react-native-document-picker';
|
import { pick } from 'react-native-document-picker';
|
||||||
import { useDeviceOrientation } from '@react-native-community/hooks';
|
import { useDeviceOrientation } from '@react-native-community/hooks';
|
||||||
|
import Clipboard from '@react-native-clipboard/clipboard';
|
||||||
import { documentPickerResponseToAddMemeFile, ROUTE } from '../types';
|
import { documentPickerResponseToAddMemeFile, ROUTE } from '../types';
|
||||||
import { allowedMimeTypes, noOp } from '../utilities';
|
import {
|
||||||
|
allowedMimeTypes,
|
||||||
|
getFilenameFromUri,
|
||||||
|
guessMimeType,
|
||||||
|
noOp,
|
||||||
|
} from '../utilities';
|
||||||
|
|
||||||
const floatingActionButtonStyles = StyleSheet.create({
|
const floatingActionButtonStyles = StyleSheet.create({
|
||||||
fab: {
|
fab: {
|
||||||
@@ -17,6 +23,9 @@ const floatingActionButtonStyles = StyleSheet.create({
|
|||||||
paddingBottom: 40,
|
paddingBottom: 40,
|
||||||
paddingRight: 12,
|
paddingRight: 12,
|
||||||
},
|
},
|
||||||
|
snackbar: {
|
||||||
|
marginBottom: 90,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const FloatingActionButton = ({ visible = true }: { visible?: boolean }) => {
|
const FloatingActionButton = ({ visible = true }: { visible?: boolean }) => {
|
||||||
@@ -27,6 +36,8 @@ const FloatingActionButton = ({ visible = true }: { visible?: boolean }) => {
|
|||||||
const [state, setState] = useState(false);
|
const [state, setState] = useState(false);
|
||||||
const [keyboardOpen, setKeyboardOpen] = useState(false);
|
const [keyboardOpen, setKeyboardOpen] = useState(false);
|
||||||
|
|
||||||
|
const [snackbarMessage, setSnackbarMessage] = useState<string>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const keyboardDidShowListener = Keyboard.addListener(
|
const keyboardDidShowListener = Keyboard.addListener(
|
||||||
'keyboardDidShow',
|
'keyboardDidShow',
|
||||||
@@ -43,35 +54,85 @@ const FloatingActionButton = ({ visible = true }: { visible?: boolean }) => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
const handleAddMeme = useCallback(async () => {
|
||||||
<FAB.Group
|
const response = await pick({
|
||||||
open={state}
|
type: allowedMimeTypes,
|
||||||
visible={visible && !keyboardOpen}
|
allowMultiSelection: true,
|
||||||
icon={state ? 'image' : 'plus'}
|
}).catch(noOp);
|
||||||
actions={[
|
if (!response) return;
|
||||||
|
const files = documentPickerResponseToAddMemeFile(response);
|
||||||
|
navigate(ROUTE.ADD_MEME, { files });
|
||||||
|
}, [navigate]);
|
||||||
|
|
||||||
|
const handleAddTag = useCallback(() => {
|
||||||
|
navigate(ROUTE.ADD_TAG);
|
||||||
|
}, [navigate]);
|
||||||
|
|
||||||
|
const handlePaste = useCallback(async () => {
|
||||||
|
const uri = await Clipboard.getURI();
|
||||||
|
if (!uri) {
|
||||||
|
setSnackbarMessage('Clipboard does not contain a URI.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const mimeType = guessMimeType(uri);
|
||||||
|
if (!mimeType) {
|
||||||
|
setSnackbarMessage('Unsupported MIME type.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigate(ROUTE.ADD_MEME, {
|
||||||
|
files: [
|
||||||
{
|
{
|
||||||
icon: 'tag',
|
uri: uri,
|
||||||
label: 'Tag',
|
filename: getFilenameFromUri(uri),
|
||||||
onPress: () => navigate(ROUTE.ADD_TAG),
|
type: mimeType,
|
||||||
},
|
},
|
||||||
]}
|
],
|
||||||
onStateChange={({ open }) => setState(open)}
|
});
|
||||||
onPress={async () => {
|
}, [navigate]);
|
||||||
if (!state) return;
|
|
||||||
const response = await pick({
|
return (
|
||||||
type: allowedMimeTypes,
|
<>
|
||||||
allowMultiSelection: true,
|
<FAB.Group
|
||||||
}).catch(noOp);
|
open={state}
|
||||||
if (!response) return;
|
visible={visible && !keyboardOpen}
|
||||||
const files = documentPickerResponseToAddMemeFile(response);
|
icon={state ? 'close' : 'plus'}
|
||||||
navigate(ROUTE.ADD_MEME, { files });
|
actions={[
|
||||||
}}
|
{
|
||||||
style={
|
icon: 'content-paste',
|
||||||
orientation === 'portrait'
|
label: 'Paste',
|
||||||
? floatingActionButtonStyles.fab
|
onPress: handlePaste,
|
||||||
: floatingActionButtonStyles.fabLandscape
|
},
|
||||||
}
|
{
|
||||||
/>
|
icon: 'tag',
|
||||||
|
label: 'Tag',
|
||||||
|
onPress: handleAddTag,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'image',
|
||||||
|
label: 'Meme',
|
||||||
|
onPress: handleAddMeme,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
onStateChange={({ open }) => setState(open)}
|
||||||
|
style={
|
||||||
|
orientation === 'portrait'
|
||||||
|
? floatingActionButtonStyles.fab
|
||||||
|
: floatingActionButtonStyles.fabLandscape
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Snackbar
|
||||||
|
visible={!!snackbarMessage}
|
||||||
|
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||||
|
onDismiss={() => setSnackbarMessage(undefined)}
|
||||||
|
style={floatingActionButtonStyles.snackbar}
|
||||||
|
action={{
|
||||||
|
label: 'Dismiss',
|
||||||
|
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||||
|
onPress: () => setSnackbarMessage(undefined),
|
||||||
|
}}>
|
||||||
|
{snackbarMessage}
|
||||||
|
</Snackbar>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -16,12 +16,10 @@ const storageLocationChangeDialogStyles = StyleSheet.create({
|
|||||||
const StorageLocationChangeDialog = ({
|
const StorageLocationChangeDialog = ({
|
||||||
visible,
|
visible,
|
||||||
setVisible,
|
setVisible,
|
||||||
setSnackbarVisible,
|
|
||||||
setSnackbarMessage,
|
setSnackbarMessage,
|
||||||
}: {
|
}: {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
setVisible: (visible: boolean) => void;
|
setVisible: (visible: boolean) => void;
|
||||||
setSnackbarVisible: (visible: boolean) => void;
|
|
||||||
setSnackbarMessage: (message: string) => void;
|
setSnackbarMessage: (message: string) => void;
|
||||||
}) => {
|
}) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
@@ -45,7 +43,6 @@ const StorageLocationChangeDialog = ({
|
|||||||
|
|
||||||
if (isPermissionForPath(storageUri, newStorageUri)) {
|
if (isPermissionForPath(storageUri, newStorageUri)) {
|
||||||
setSnackbarMessage('Folder already selected.');
|
setSnackbarMessage('Folder already selected.');
|
||||||
setSnackbarVisible(true);
|
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -59,8 +59,7 @@ const MemeView = ({
|
|||||||
const { ids } = route.params;
|
const { ids } = route.params;
|
||||||
const [index, setIndex] = useState(route.params.index);
|
const [index, setIndex] = useState(route.params.index);
|
||||||
|
|
||||||
const [snackbarVisible, setSnackbarVisible] = useState(false);
|
const [snackbarMessage, setSnackbarMessage] = useState<string>();
|
||||||
const [snackbarMessage, setSnackbarMessage] = useState('');
|
|
||||||
|
|
||||||
const flashListRef = useRef<FlashList<Meme>>(null);
|
const flashListRef = useRef<FlashList<Meme>>(null);
|
||||||
|
|
||||||
@@ -101,24 +100,17 @@ const MemeView = ({
|
|||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon="share"
|
icon="share"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
shareMeme(realm, storageUri, memes[index]).catch(() => {
|
shareMeme(realm, storageUri, memes[index]).catch(() =>
|
||||||
setSnackbarMessage('Failed to share meme!');
|
setSnackbarMessage('Failed to share meme!'),
|
||||||
setSnackbarVisible(true);
|
);
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon="content-copy"
|
icon="content-copy"
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
await copyMeme(realm, storageUri, memes[index])
|
await copyMeme(realm, storageUri, memes[index])
|
||||||
.then(() => {
|
.then(() => setSnackbarMessage('Meme copied!'))
|
||||||
setSnackbarMessage('Meme copied!');
|
.catch(() => setSnackbarMessage('Failed to copy meme!'));
|
||||||
setSnackbarVisible(true);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setSnackbarMessage('Failed to copy meme!');
|
|
||||||
setSnackbarVisible(true);
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
@@ -143,12 +135,14 @@ const MemeView = ({
|
|||||||
</Appbar>
|
</Appbar>
|
||||||
<Portal>
|
<Portal>
|
||||||
<Snackbar
|
<Snackbar
|
||||||
visible={snackbarVisible}
|
visible={!!snackbarMessage}
|
||||||
onDismiss={() => setSnackbarVisible(false)}
|
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||||
|
onDismiss={() => setSnackbarMessage(undefined)}
|
||||||
style={memeViewStyles.snackbar}
|
style={memeViewStyles.snackbar}
|
||||||
action={{
|
action={{
|
||||||
label: 'Dismiss',
|
label: 'Dismiss',
|
||||||
onPress: () => setSnackbarVisible(false),
|
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||||
|
onPress: () => setSnackbarMessage(undefined),
|
||||||
}}>
|
}}>
|
||||||
{snackbarMessage}
|
{snackbarMessage}
|
||||||
</Snackbar>
|
</Snackbar>
|
||||||
|
@@ -60,8 +60,7 @@ const Settings = () => {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const realm = useRealm();
|
const realm = useRealm();
|
||||||
|
|
||||||
const [snackbarVisible, setSnackbarVisible] = useState(false);
|
const [snackbarMessage, setSnackbarMessage] = useState<string>();
|
||||||
const [snackbarMessage, setSnackbarMessage] = useState('');
|
|
||||||
|
|
||||||
const [
|
const [
|
||||||
storageLocationChangeDialogVisible,
|
storageLocationChangeDialogVisible,
|
||||||
@@ -84,7 +83,6 @@ const Settings = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setSnackbarMessage('Meme metadata refreshed.');
|
setSnackbarMessage('Meme metadata refreshed.');
|
||||||
setSnackbarVisible(true);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -162,17 +160,18 @@ const Settings = () => {
|
|||||||
<StorageLocationChangeDialog
|
<StorageLocationChangeDialog
|
||||||
visible={storageLocationChangeDialogVisible}
|
visible={storageLocationChangeDialogVisible}
|
||||||
setVisible={setStorageLocationChangeDialogVisible}
|
setVisible={setStorageLocationChangeDialogVisible}
|
||||||
setSnackbarVisible={setSnackbarVisible}
|
|
||||||
setSnackbarMessage={setSnackbarMessage}
|
setSnackbarMessage={setSnackbarMessage}
|
||||||
/>
|
/>
|
||||||
</Portal>
|
</Portal>
|
||||||
<Snackbar
|
<Snackbar
|
||||||
visible={snackbarVisible}
|
visible={!!snackbarMessage}
|
||||||
onDismiss={() => setSnackbarVisible(false)}
|
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||||
|
onDismiss={() => setSnackbarMessage(undefined)}
|
||||||
style={settingsStyles.snackbar}
|
style={settingsStyles.snackbar}
|
||||||
action={{
|
action={{
|
||||||
label: 'Dismiss',
|
label: 'Dismiss',
|
||||||
onPress: () => setSnackbarVisible(false),
|
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||||
|
onPress: () => setSnackbarMessage(undefined),
|
||||||
}}>
|
}}>
|
||||||
{snackbarMessage}
|
{snackbarMessage}
|
||||||
</Snackbar>
|
</Snackbar>
|
||||||
|
11
src/utilities/clipboard.ts
Normal file
11
src/utilities/clipboard.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import Clipboard from '@react-native-clipboard/clipboard';
|
||||||
|
|
||||||
|
const clipboardHasContent = () => {
|
||||||
|
return Promise.all([Clipboard.hasString(), Clipboard.hasURI()]).then(
|
||||||
|
([hasString, hasURI]) => {
|
||||||
|
return hasString || hasURI;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { clipboardHasContent };
|
@@ -2,6 +2,7 @@ import { MEME_TYPE } from '../database';
|
|||||||
|
|
||||||
const allowedImageMimeTypes = [
|
const allowedImageMimeTypes = [
|
||||||
'image/bmp',
|
'image/bmp',
|
||||||
|
'image/jpg',
|
||||||
'image/jpeg',
|
'image/jpeg',
|
||||||
'image/png',
|
'image/png',
|
||||||
'image/webp',
|
'image/webp',
|
||||||
@@ -14,6 +15,7 @@ const allowedMimeTypes = [...allowedImageMimeTypes, ...allowedGifMimeTypes];
|
|||||||
const getMemeType = (mimeType: string): MEME_TYPE | undefined => {
|
const getMemeType = (mimeType: string): MEME_TYPE | undefined => {
|
||||||
switch (mimeType) {
|
switch (mimeType) {
|
||||||
case 'image/bmp':
|
case 'image/bmp':
|
||||||
|
case 'image/jpg':
|
||||||
case 'image/jpeg':
|
case 'image/jpeg':
|
||||||
case 'image/png':
|
case 'image/png':
|
||||||
case 'image/webp': {
|
case 'image/webp': {
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
export { clipboardHasContent } from './clipboard';
|
||||||
export {
|
export {
|
||||||
getContrastColor,
|
getContrastColor,
|
||||||
isHexColor,
|
isHexColor,
|
||||||
|
Reference in New Issue
Block a user