Handle camera cancellation (#11322)
This commit is contained in:
@@ -17,11 +17,11 @@ export async function openCamera(customOpts: ImagePickerOptions) {
|
|||||||
}
|
}
|
||||||
const res = await launchCameraAsync(opts)
|
const res = await launchCameraAsync(opts)
|
||||||
|
|
||||||
if (!res || !res.assets) {
|
if (res.canceled) {
|
||||||
throw new Error('Camera was closed before taking a photo')
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const asset = res?.assets[0]
|
const asset = res.assets[0]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: asset.uri,
|
path: asset.uri,
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ export function OpenCameraBtn({disabled, onAdd}: OpenCameraBtnProps) {
|
|||||||
const img = await openCamera({
|
const img = await openCamera({
|
||||||
aspect: [1, 1],
|
aspect: [1, 1],
|
||||||
})
|
})
|
||||||
|
if (!img) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// If we don't have permissions it's fine, we just wont save it. The post itself will still have access to
|
// If we don't have permissions it's fine, we just wont save it. The post itself will still have access to
|
||||||
// the image even without these permissions
|
// the image even without these permissions
|
||||||
|
|||||||
@@ -115,6 +115,9 @@ export function ComposerPrompt() {
|
|||||||
const image = await openCamera({
|
const image = await openCamera({
|
||||||
mediaTypes: 'images',
|
mediaTypes: 'images',
|
||||||
})
|
})
|
||||||
|
if (!image) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const imageUris = [
|
const imageUris = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -391,14 +391,14 @@ let EditableUserAvatar = ({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectNewAvatar(
|
const image = await openCamera({
|
||||||
await compressIfNeeded(
|
aspect: [1, 1],
|
||||||
await openCamera({
|
})
|
||||||
aspect: [1, 1],
|
if (!image) {
|
||||||
}),
|
return
|
||||||
IMAGE_SIZE_CONFIG_2K_1MB,
|
}
|
||||||
),
|
|
||||||
)
|
onSelectNewAvatar(await compressIfNeeded(image, IMAGE_SIZE_CONFIG_2K_1MB))
|
||||||
}, [onSelectNewAvatar, requestCameraAccessIfNeeded])
|
}, [onSelectNewAvatar, requestCameraAccessIfNeeded])
|
||||||
|
|
||||||
const onOpenLibrary = useCallback(async () => {
|
const onOpenLibrary = useCallback(async () => {
|
||||||
|
|||||||
@@ -58,14 +58,14 @@ export function UserBanner({
|
|||||||
if (!(await requestCameraAccessIfNeeded())) {
|
if (!(await requestCameraAccessIfNeeded())) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSelectNewBanner?.(
|
const image = await openCamera({
|
||||||
await compressIfNeeded(
|
aspect: [3, 1],
|
||||||
await openCamera({
|
})
|
||||||
aspect: [3, 1],
|
if (!image) {
|
||||||
}),
|
return
|
||||||
IMAGE_SIZE_CONFIG_2K_1MB,
|
}
|
||||||
),
|
|
||||||
)
|
onSelectNewBanner?.(await compressIfNeeded(image, IMAGE_SIZE_CONFIG_2K_1MB))
|
||||||
}, [onSelectNewBanner, requestCameraAccessIfNeeded])
|
}, [onSelectNewBanner, requestCameraAccessIfNeeded])
|
||||||
|
|
||||||
const onOpenLibrary = useCallback(async () => {
|
const onOpenLibrary = useCallback(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user