tweak saving image on android
This commit is contained in:
@@ -1,16 +1,14 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import ViewShot from 'react-native-view-shot'
|
import ViewShot from 'react-native-view-shot'
|
||||||
import * as FS from 'expo-file-system'
|
|
||||||
import {requestMediaLibraryPermissionsAsync} from 'expo-image-picker'
|
import {requestMediaLibraryPermissionsAsync} from 'expo-image-picker'
|
||||||
|
import {createAssetAsync} from 'expo-media-library'
|
||||||
import * as Sharing from 'expo-sharing'
|
import * as Sharing from 'expo-sharing'
|
||||||
import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api'
|
import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {nanoid} from 'nanoid/non-secure'
|
|
||||||
|
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {saveImageToMediaLibrary} from 'lib/media/manip'
|
|
||||||
import {logEvent} from 'lib/statsig/statsig'
|
import {logEvent} from 'lib/statsig/statsig'
|
||||||
import {isNative, isWeb} from 'platform/detection'
|
import {isNative, isWeb} from 'platform/detection'
|
||||||
import * as Toast from '#/view/com/util/Toast'
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
@@ -65,13 +63,9 @@ export function QrCodeDialog({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const filename = `${FS.documentDirectory}/${nanoid(12)}.png`
|
|
||||||
|
|
||||||
// Incase of a FS failure, don't crash the app
|
// Incase of a FS failure, don't crash the app
|
||||||
try {
|
try {
|
||||||
await FS.copyAsync({from: uri, to: filename})
|
await createAssetAsync(`file://${uri}`)
|
||||||
await saveImageToMediaLibrary({uri: filename})
|
|
||||||
await FS.deleteAsync(filename)
|
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
Toast.show(_(msg`An error occurred while saving the QR code!`))
|
Toast.show(_(msg`An error occurred while saving the QR code!`))
|
||||||
logger.error('Failed to save QR code', {error: e})
|
logger.error('Failed to save QR code', {error: e})
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import * as FS from 'expo-file-system'
|
|
||||||
import {Image} from 'expo-image'
|
import {Image} from 'expo-image'
|
||||||
import {requestMediaLibraryPermissionsAsync} from 'expo-image-picker'
|
import {requestMediaLibraryPermissionsAsync} from 'expo-image-picker'
|
||||||
import {AppBskyGraphDefs} from '@atproto/api'
|
import {AppBskyGraphDefs} from '@atproto/api'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {nanoid} from 'nanoid/non-secure'
|
|
||||||
|
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
@@ -72,19 +70,8 @@ function ShareDialogInner({
|
|||||||
return
|
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 {
|
try {
|
||||||
await FS.copyAsync({from: cachePath, to: filename})
|
await saveImageToMediaLibrary({uri: imageUrl})
|
||||||
await saveImageToMediaLibrary({uri: filename})
|
|
||||||
await FS.deleteAsync(filename)
|
|
||||||
|
|
||||||
Toast.show(_(msg`Image saved to your camera roll!`))
|
Toast.show(_(msg`Image saved to your camera roll!`))
|
||||||
control.close()
|
control.close()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
|
|||||||
Reference in New Issue
Block a user