154 cached image profile (#167)
* Fixes issue where retrying on image upload fails * Lint, longer test time * Longer waitfor time in tests * even longer timeout * longer timeout * missed file * Fixes image cache error on second try for profile screen * lint * lint * lint
This commit is contained in:
+20
-2
@@ -2,7 +2,7 @@ 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 uuid from 'react-native-uuid'
|
||||
import * as Toast from '../view/com/util/Toast'
|
||||
|
||||
export interface DownloadAndResizeOpts {
|
||||
@@ -109,12 +109,18 @@ export async function compressIfNeeded(
|
||||
if (img.size < maxSize) {
|
||||
return img
|
||||
}
|
||||
return await resize(origUri, {
|
||||
const resizedImage = await resize(origUri, {
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
mode: 'stretch',
|
||||
maxSize,
|
||||
})
|
||||
const finalImageMovedPath = await moveToPremanantPath(resizedImage.path)
|
||||
const finalImg = {
|
||||
...resizedImage,
|
||||
path: finalImageMovedPath,
|
||||
}
|
||||
return finalImg
|
||||
}
|
||||
|
||||
export interface Dim {
|
||||
@@ -150,3 +156,15 @@ export const saveImageModal = async ({uri}: {uri: string}) => {
|
||||
}
|
||||
RNFS.unlink(imagePath)
|
||||
}
|
||||
|
||||
export const moveToPremanantPath = async (path: string) => {
|
||||
/*
|
||||
Since this package stores images in a temp directory, we need to move the file to a permanent location.
|
||||
Relevant: IOS bug when trying to open a second time:
|
||||
https://github.com/ivpusic/react-native-image-crop-picker/issues/1199
|
||||
*/
|
||||
const filename = uuid.v4()
|
||||
const destinationPath = `${RNFS.TemporaryDirectoryPath}/${filename}`
|
||||
RNFS.moveFile(path, destinationPath)
|
||||
return destinationPath
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import React, {useCallback} from 'react'
|
||||
import {Image, StyleSheet, TouchableOpacity, ScrollView} from 'react-native'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import uuid from 'react-native-uuid'
|
||||
import {useAnalytics} from '@segment/analytics-react-native'
|
||||
import {
|
||||
openPicker,
|
||||
openCamera,
|
||||
openCropper,
|
||||
} from 'react-native-image-crop-picker'
|
||||
import RNFS from 'react-native-fs'
|
||||
import {
|
||||
UserLocalPhotosModel,
|
||||
PhotoIdentifier,
|
||||
@@ -16,10 +15,13 @@ import {
|
||||
requestPhotoAccessIfNeeded,
|
||||
requestCameraAccessIfNeeded,
|
||||
} from '../../../lib/permissions'
|
||||
import {compressIfNeeded, scaleDownDimensions} from '../../../lib/images'
|
||||
import {
|
||||
compressIfNeeded,
|
||||
moveToPremanantPath,
|
||||
scaleDownDimensions,
|
||||
} from '../../../lib/images'
|
||||
import {usePalette} from '../../lib/hooks/usePalette'
|
||||
import {useStores} from '../../../state'
|
||||
import {useAnalytics} from '@segment/analytics-react-native'
|
||||
|
||||
const MAX_WIDTH = 2000
|
||||
const MAX_HEIGHT = 2000
|
||||
@@ -33,18 +35,6 @@ const IMAGE_PARAMS = {
|
||||
compressImageQuality: 1.0,
|
||||
}
|
||||
|
||||
const moveToPremanantPath = async (path: string) => {
|
||||
/*
|
||||
Since this package stores images in a temp directory, we need to move the file to a permanent location.
|
||||
Relevant: IOS bug when trying to open a second time:
|
||||
https://github.com/ivpusic/react-native-image-crop-picker/issues/1199
|
||||
*/
|
||||
const filename = uuid.v4()
|
||||
const destinationPath = `${RNFS.TemporaryDirectoryPath}/${filename}`
|
||||
RNFS.moveFile(path, destinationPath)
|
||||
return destinationPath
|
||||
}
|
||||
|
||||
export async function cropPhoto(
|
||||
path: string,
|
||||
imgWidth = MAX_WIDTH,
|
||||
|
||||
Reference in New Issue
Block a user