be more permissive about allowed pfp types in onboarding
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {Image as ExpoImage} from 'expo-image'
|
import {Image as ExpoImage} from 'expo-image'
|
||||||
|
import {ImageManipulator, SaveFormat} from 'expo-image-manipulator'
|
||||||
import {
|
import {
|
||||||
type ImagePickerOptions,
|
type ImagePickerOptions,
|
||||||
launchImageLibraryAsync,
|
launchImageLibraryAsync,
|
||||||
@@ -107,28 +108,33 @@ export function StepProfile() {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
return (response.assets ?? [])
|
const asset = (response.assets ?? [])[0]
|
||||||
.slice(0, 1)
|
if (!asset) return []
|
||||||
.filter(asset => {
|
|
||||||
if (
|
try {
|
||||||
!asset.mimeType?.startsWith('image/') ||
|
const context = ImageManipulator.manipulate(asset.uri)
|
||||||
(!asset.mimeType?.endsWith('jpeg') &&
|
const rendered = await context.renderAsync()
|
||||||
!asset.mimeType?.endsWith('jpg') &&
|
const result = await rendered.saveAsync({
|
||||||
!asset.mimeType?.endsWith('png') &&
|
format: SaveFormat.JPEG,
|
||||||
!asset.mimeType?.endsWith('webp'))
|
compress: 1.0,
|
||||||
) {
|
|
||||||
setError(_(msg`Only .jpg, .png, and .webp files are supported`))
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
})
|
||||||
.map(image => ({
|
return [
|
||||||
mime: image.mimeType || 'image/jpeg',
|
{
|
||||||
height: image.height,
|
mime: 'image/jpeg',
|
||||||
width: image.width,
|
height: rendered.height,
|
||||||
path: image.uri,
|
width: rendered.width,
|
||||||
size: getDataUriSize(image.uri),
|
path: result.uri,
|
||||||
}))
|
size: getDataUriSize(result.uri),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
} catch {
|
||||||
|
setError(
|
||||||
|
_(
|
||||||
|
msg`This image could not be used. Try a different format like .jpg or .png.`,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return []
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[_, setError, sheetWrapper],
|
[_, setError, sheetWrapper],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user