···11+import {useCallback} from 'react'
22+import {msg} from '@lingui/macro'
33+import {useLingui} from '@lingui/react'
44+55+import {isNative} from '#/platform/detection'
66+import * as Toast from '#/components/Toast'
77+import {saveImageToMediaLibrary} from './manip'
88+99+/**
1010+ * Same as `saveImageToMediaLibrary`, but also handles permissions and toasts
1111+ *
1212+ * iOS doesn't not require permissions to save images to the media library,
1313+ * so this file is platform-split as it's much simpler than the Android version.
1414+ */
1515+export function useSaveImageToMediaLibrary() {
1616+ const {_} = useLingui()
1717+ return useCallback(
1818+ async (uri: string) => {
1919+ if (!isNative) {
2020+ throw new Error('useSaveImageToMediaLibrary is native only')
2121+ }
2222+2323+ try {
2424+ await saveImageToMediaLibrary({uri})
2525+ Toast.show(_(msg`Image saved`))
2626+ } catch (e: any) {
2727+ Toast.show(_(msg`Failed to save image: ${String(e)}`), {type: 'error'})
2828+ }
2929+ },
3030+ [_],
3131+ )
3232+}
+18-9
src/lib/media/save-image.ts
···11import {useCallback} from 'react'
22import * as MediaLibrary from 'expo-media-library'
33-import {t} from '@lingui/macro'
33+import {msg} from '@lingui/macro'
44+import {useLingui} from '@lingui/react'
4556import {isNative} from '#/platform/detection'
66-import * as Toast from '#/view/com/util/Toast'
77+import * as Toast from '#/components/Toast'
78import {saveImageToMediaLibrary} from './manip'
89910/**
1011 * Same as `saveImageToMediaLibrary`, but also handles permissions and toasts
1112 */
1213export function useSaveImageToMediaLibrary() {
1414+ const {_} = useLingui()
1315 const [permissionResponse, requestPermission, getPermission] =
1416 MediaLibrary.usePermissions({
1517 granularPermissions: ['photo'],
···2325 async function save() {
2426 try {
2527 await saveImageToMediaLibrary({uri})
2626- Toast.show(t`Image saved`)
2828+2929+ Toast.show(_(msg`Image saved`))
2730 } catch (e: any) {
2828- Toast.show(t`Failed to save image: ${String(e)}`, 'xmark')
3131+ Toast.show(_(msg`Failed to save image: ${String(e)}`), {
3232+ type: 'error',
3333+ })
2934 }
3035 }
3136···4247 } else {
4348 // since we've been explicitly denied, show a toast.
4449 Toast.show(
4545- t`Images cannot be saved unless permission is granted to access your photo library.`,
4646- 'xmark',
5050+ _(
5151+ msg`Images cannot be saved unless permission is granted to access your photo library.`,
5252+ ),
5353+ {type: 'error'},
4754 )
4855 }
4956 } else {
5057 Toast.show(
5151- t`Permission to access your photo library was denied. Please enable it in your system settings.`,
5252- 'xmark',
5858+ _(
5959+ msg`Permission to access your photo library was denied. Please enable it in your system settings.`,
6060+ ),
6161+ {type: 'error'},
5362 )
5463 }
5564 }
5665 },
5757- [permissionResponse, requestPermission, getPermission],
6666+ [permissionResponse, requestPermission, getPermission, _],
5867 )
5968}