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 ImageResizer from '@bam.tech/react-native-image-resizer'
|
||||||
import {Share} from 'react-native'
|
import {Share} from 'react-native'
|
||||||
import RNFS from 'react-native-fs'
|
import RNFS from 'react-native-fs'
|
||||||
|
import uuid from 'react-native-uuid'
|
||||||
import * as Toast from '../view/com/util/Toast'
|
import * as Toast from '../view/com/util/Toast'
|
||||||
|
|
||||||
export interface DownloadAndResizeOpts {
|
export interface DownloadAndResizeOpts {
|
||||||
@@ -109,12 +109,18 @@ export async function compressIfNeeded(
|
|||||||
if (img.size < maxSize) {
|
if (img.size < maxSize) {
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
return await resize(origUri, {
|
const resizedImage = await resize(origUri, {
|
||||||
width: img.width,
|
width: img.width,
|
||||||
height: img.height,
|
height: img.height,
|
||||||
mode: 'stretch',
|
mode: 'stretch',
|
||||||
maxSize,
|
maxSize,
|
||||||
})
|
})
|
||||||
|
const finalImageMovedPath = await moveToPremanantPath(resizedImage.path)
|
||||||
|
const finalImg = {
|
||||||
|
...resizedImage,
|
||||||
|
path: finalImageMovedPath,
|
||||||
|
}
|
||||||
|
return finalImg
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Dim {
|
export interface Dim {
|
||||||
@@ -150,3 +156,15 @@ export const saveImageModal = async ({uri}: {uri: string}) => {
|
|||||||
}
|
}
|
||||||
RNFS.unlink(imagePath)
|
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 React, {useCallback} from 'react'
|
||||||
import {Image, StyleSheet, TouchableOpacity, ScrollView} from 'react-native'
|
import {Image, StyleSheet, TouchableOpacity, ScrollView} from 'react-native'
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import uuid from 'react-native-uuid'
|
import {useAnalytics} from '@segment/analytics-react-native'
|
||||||
import {
|
import {
|
||||||
openPicker,
|
openPicker,
|
||||||
openCamera,
|
openCamera,
|
||||||
openCropper,
|
openCropper,
|
||||||
} from 'react-native-image-crop-picker'
|
} from 'react-native-image-crop-picker'
|
||||||
import RNFS from 'react-native-fs'
|
|
||||||
import {
|
import {
|
||||||
UserLocalPhotosModel,
|
UserLocalPhotosModel,
|
||||||
PhotoIdentifier,
|
PhotoIdentifier,
|
||||||
@@ -16,10 +15,13 @@ import {
|
|||||||
requestPhotoAccessIfNeeded,
|
requestPhotoAccessIfNeeded,
|
||||||
requestCameraAccessIfNeeded,
|
requestCameraAccessIfNeeded,
|
||||||
} from '../../../lib/permissions'
|
} from '../../../lib/permissions'
|
||||||
import {compressIfNeeded, scaleDownDimensions} from '../../../lib/images'
|
import {
|
||||||
|
compressIfNeeded,
|
||||||
|
moveToPremanantPath,
|
||||||
|
scaleDownDimensions,
|
||||||
|
} from '../../../lib/images'
|
||||||
import {usePalette} from '../../lib/hooks/usePalette'
|
import {usePalette} from '../../lib/hooks/usePalette'
|
||||||
import {useStores} from '../../../state'
|
import {useStores} from '../../../state'
|
||||||
import {useAnalytics} from '@segment/analytics-react-native'
|
|
||||||
|
|
||||||
const MAX_WIDTH = 2000
|
const MAX_WIDTH = 2000
|
||||||
const MAX_HEIGHT = 2000
|
const MAX_HEIGHT = 2000
|
||||||
@@ -33,18 +35,6 @@ const IMAGE_PARAMS = {
|
|||||||
compressImageQuality: 1.0,
|
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(
|
export async function cropPhoto(
|
||||||
path: string,
|
path: string,
|
||||||
imgWidth = MAX_WIDTH,
|
imgWidth = MAX_WIDTH,
|
||||||
|
|||||||
Reference in New Issue
Block a user