From f86d25552b6b25912026ec5601899fcc928f18ba Mon Sep 17 00:00:00 2001 From: Hailey Date: Sat, 22 Jun 2024 15:23:00 -0700 Subject: [PATCH] tweak saving image on android --- src/components/StarterPack/QrCodeDialog.tsx | 10 ++-------- src/components/StarterPack/ShareDialog.tsx | 15 +-------------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/src/components/StarterPack/QrCodeDialog.tsx b/src/components/StarterPack/QrCodeDialog.tsx index 580c6cc7c8..39eb3076d8 100644 --- a/src/components/StarterPack/QrCodeDialog.tsx +++ b/src/components/StarterPack/QrCodeDialog.tsx @@ -1,16 +1,14 @@ import React from 'react' import {View} from 'react-native' import ViewShot from 'react-native-view-shot' -import * as FS from 'expo-file-system' import {requestMediaLibraryPermissionsAsync} from 'expo-image-picker' +import {createAssetAsync} from 'expo-media-library' import * as Sharing from 'expo-sharing' import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {nanoid} from 'nanoid/non-secure' import {logger} from '#/logger' -import {saveImageToMediaLibrary} from 'lib/media/manip' import {logEvent} from 'lib/statsig/statsig' import {isNative, isWeb} from 'platform/detection' import * as Toast from '#/view/com/util/Toast' @@ -65,13 +63,9 @@ export function QrCodeDialog({ return } - const filename = `${FS.documentDirectory}/${nanoid(12)}.png` - // Incase of a FS failure, don't crash the app try { - await FS.copyAsync({from: uri, to: filename}) - await saveImageToMediaLibrary({uri: filename}) - await FS.deleteAsync(filename) + await createAssetAsync(`file://${uri}`) } catch (e: unknown) { Toast.show(_(msg`An error occurred while saving the QR code!`)) logger.error('Failed to save QR code', {error: e}) diff --git a/src/components/StarterPack/ShareDialog.tsx b/src/components/StarterPack/ShareDialog.tsx index 23fa10fb39..fba79bbae9 100644 --- a/src/components/StarterPack/ShareDialog.tsx +++ b/src/components/StarterPack/ShareDialog.tsx @@ -1,12 +1,10 @@ import React from 'react' import {View} from 'react-native' -import * as FS from 'expo-file-system' import {Image} from 'expo-image' import {requestMediaLibraryPermissionsAsync} from 'expo-image-picker' import {AppBskyGraphDefs} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {nanoid} from 'nanoid/non-secure' import {logger} from '#/logger' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' @@ -72,19 +70,8 @@ function ShareDialogInner({ return } - const cachePath = await Image.getCachePathAsync(imageUrl) - const filename = `${FS.documentDirectory}/${nanoid(12)}.png` - - if (!cachePath) { - Toast.show(_(msg`An error occurred while saving the image.`)) - return - } - try { - await FS.copyAsync({from: cachePath, to: filename}) - await saveImageToMediaLibrary({uri: filename}) - await FS.deleteAsync(filename) - + await saveImageToMediaLibrary({uri: imageUrl}) Toast.show(_(msg`Image saved to your camera roll!`)) control.close() } catch (e: unknown) {