[APP-716] Add 'save image' button to the lightbox (#926)
* Add 'save image' button to the lightbox * Fix types * Fix types
This commit is contained in:
parent
5fcca17129
commit
c72e24f841
4 changed files with 60 additions and 4 deletions
|
@ -5,6 +5,7 @@ import {Image} from 'react-native-image-crop-picker'
|
|||
import * as RNFS from 'react-native-fs'
|
||||
import uuid from 'react-native-uuid'
|
||||
import * as Sharing from 'expo-sharing'
|
||||
import * as MediaLibrary from 'expo-media-library'
|
||||
import {Dimensions} from './types'
|
||||
import {isAndroid, isIOS} from 'platform/detection'
|
||||
|
||||
|
@ -75,7 +76,7 @@ export async function downloadAndResize(opts: DownloadAndResizeOpts) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function saveImageModal({uri}: {uri: string}) {
|
||||
export async function shareImageModal({uri}: {uri: string}) {
|
||||
if (!(await Sharing.isAvailableAsync())) {
|
||||
// TODO might need to give an error to the user in this case -prf
|
||||
return
|
||||
|
@ -107,6 +108,34 @@ export async function saveImageModal({uri}: {uri: string}) {
|
|||
RNFS.unlink(imagePath)
|
||||
}
|
||||
|
||||
export async function saveImageToAlbum({
|
||||
uri,
|
||||
album,
|
||||
}: {
|
||||
uri: string
|
||||
album: string
|
||||
}) {
|
||||
// download the file to cache
|
||||
// NOTE
|
||||
// assuming PNG
|
||||
// we're currently relying on the fact our CDN only serves pngs
|
||||
// -prf
|
||||
const downloadResponse = await RNFetchBlob.config({
|
||||
fileCache: true,
|
||||
}).fetch('GET', uri)
|
||||
let imagePath = downloadResponse.path()
|
||||
imagePath = normalizePath(await moveToPermanentPath(imagePath, '.png'), true)
|
||||
|
||||
// save to the album (creating as needed)
|
||||
const assetRef = await MediaLibrary.createAssetAsync(imagePath)
|
||||
const albumRef = await MediaLibrary.getAlbumAsync(album)
|
||||
if (albumRef) {
|
||||
await MediaLibrary.addAssetsToAlbumAsync(assetRef, albumRef)
|
||||
} else {
|
||||
await MediaLibrary.createAlbumAsync(album, assetRef)
|
||||
}
|
||||
}
|
||||
|
||||
export function getImageDim(path: string): Promise<Dimensions> {
|
||||
return new Promise((resolve, reject) => {
|
||||
RNImage.getSize(
|
||||
|
|
|
@ -37,7 +37,12 @@ export async function downloadAndResize(opts: DownloadAndResizeOpts) {
|
|||
return await doResize(dataUri, opts)
|
||||
}
|
||||
|
||||
export async function saveImageModal(_opts: {uri: string}) {
|
||||
export async function shareImageModal(_opts: {uri: string}) {
|
||||
// TODO
|
||||
throw new Error('TODO')
|
||||
}
|
||||
|
||||
export async function saveImageToAlbum(_opts: {uri: string; album: string}) {
|
||||
// TODO
|
||||
throw new Error('TODO')
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue