Saves image on long press (#83)

* Saves image on long press

* Adds save on long press

* Forking lightbox

* move to wrapper only to the bottom sheet to reduce impact of this change

* lint

* lint

* lint

* Use official `share` API

* Clean up cache after download

* comment

* comment

* Reduce swipe close velocity

* Updates per feedback

* lint

* bugfix

* Adds delayed press-in for TouchableOpacity
This commit is contained in:
Aryan Goharzad 2023-01-25 18:25:34 -05:00 committed by GitHub
parent adf328b50c
commit eb33c3fa81
23 changed files with 1568 additions and 46 deletions

View file

@ -1,5 +1,9 @@
import RNFetchBlob from 'rn-fetch-blob'
import ImageResizer from '@bam.tech/react-native-image-resizer'
import {Share} from 'react-native'
import RNFS from 'react-native-fs'
import * as Toast from '../view/com/util/Toast'
export interface DownloadAndResizeOpts {
uri: string
@ -128,3 +132,21 @@ export function scaleDownDimensions(dim: Dim, max: Dim): Dim {
}
return {width: dim.width * hScale, height: dim.height * hScale}
}
export const saveImageModal = async ({uri}: {uri: string}) => {
const downloadResponse = await RNFetchBlob.config({
fileCache: true,
}).fetch('GET', uri)
const imagePath = downloadResponse.path()
const base64Data = await downloadResponse.readFile('base64')
const result = await Share.share({
url: 'data:image/png;base64,' + base64Data,
})
if (result.action === Share.sharedAction) {
Toast.show('Image saved to gallery')
} else if (result.action === Share.dismissedAction) {
// dismissed
}
RNFS.unlink(imagePath)
}