Bluesky app fork with some witchin' additions 馃挮
at main 32 lines 943 B view raw
1import {useCallback} from 'react' 2import {msg} from '@lingui/core/macro' 3import {useLingui} from '@lingui/react' 4 5import * as Toast from '#/components/Toast' 6import {IS_NATIVE} from '#/env' 7import {saveImageToMediaLibrary} from './manip' 8 9/** 10 * Same as `saveImageToMediaLibrary`, but also handles permissions and toasts 11 * 12 * iOS doesn't not require permissions to save images to the media library, 13 * so this file is platform-split as it's much simpler than the Android version. 14 */ 15export function useSaveImageToMediaLibrary() { 16 const {_} = useLingui() 17 return useCallback( 18 async (uri: string) => { 19 if (!IS_NATIVE) { 20 throw new Error('useSaveImageToMediaLibrary is native only') 21 } 22 23 try { 24 await saveImageToMediaLibrary({uri}) 25 Toast.show(_(msg`Image saved`)) 26 } catch (e: any) { 27 Toast.show(_(msg`Failed to save image: ${String(e)}`), {type: 'error'}) 28 } 29 }, 30 [_], 31 ) 32}