2020-12-15 22:25:08 -05:00
|
|
|
import { useAsyncStorage } from '@react-native-async-storage/async-storage';
|
2021-02-28 00:13:37 -05:00
|
|
|
import Clipboard from '@react-native-clipboard/clipboard';
|
2020-10-10 15:19:42 -04:00
|
|
|
|
|
|
|
function BlueClipboard() {
|
|
|
|
BlueClipboard.STORAGE_KEY = 'ClipboardReadAllowed';
|
|
|
|
const isClipboardAccessAllowed = useAsyncStorage(BlueClipboard.STORAGE_KEY).getItem;
|
|
|
|
const setIsClipboardAccessAllowed = useAsyncStorage(BlueClipboard.STORAGE_KEY).setItem;
|
|
|
|
|
|
|
|
BlueClipboard.isReadClipboardAllowed = async () => {
|
|
|
|
try {
|
|
|
|
const clipboardAccessAllowed = await isClipboardAccessAllowed();
|
|
|
|
if (clipboardAccessAllowed === null) {
|
|
|
|
await setIsClipboardAccessAllowed(JSON.stringify(true));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return !!JSON.parse(clipboardAccessAllowed);
|
|
|
|
} catch {
|
|
|
|
await setIsClipboardAccessAllowed(JSON.stringify(true));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
BlueClipboard.setReadClipboardAllowed = value => {
|
|
|
|
setIsClipboardAccessAllowed(JSON.stringify(!!value));
|
|
|
|
};
|
|
|
|
|
|
|
|
BlueClipboard.getClipboardContent = async () => {
|
|
|
|
const isAllowed = await BlueClipboard.isReadClipboardAllowed();
|
|
|
|
if (isAllowed) {
|
|
|
|
return Clipboard.getString();
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
BlueClipboard.default = new BlueClipboard();
|
|
|
|
export default BlueClipboard;
|