From 05bab5ac2088e82b45189f1ece31c16119ce7cd1 Mon Sep 17 00:00:00 2001 From: Siobhan Bamber Date: Wed, 30 Nov 2022 12:57:33 +0000 Subject: [PATCH] [RNMobile] Prevent error message from unneccesarily firing when uploading to Gallery block (#46175) This PR ensures that any valid image uploaded to the Gallery block within the mobile apps is correctly marked as valid. --- packages/block-library/src/gallery/edit.js | 12 +++++++++++- packages/react-native-editor/CHANGELOG.md | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/gallery/edit.js b/packages/block-library/src/gallery/edit.js index 6d1a4ac5fc404a..30ecdee0f00b58 100644 --- a/packages/block-library/src/gallery/edit.js +++ b/packages/block-library/src/gallery/edit.js @@ -217,9 +217,19 @@ function GalleryEdit( props ) { } function isValidFileType( file ) { + // It's necessary to retrieve the media type from the raw image data for already-uploaded images on native. + const nativeFileData = + Platform.isNative && file.id + ? find( imageData, { id: file.id } ) + : null; + + const mediaTypeSelector = nativeFileData + ? nativeFileData?.media_type + : file.type; + return ( ALLOWED_MEDIA_TYPES.some( - ( mediaType ) => file.type?.indexOf( mediaType ) === 0 + ( mediaType ) => mediaTypeSelector?.indexOf( mediaType ) === 0 ) || file.url?.indexOf( 'blob:' ) === 0 ); } diff --git a/packages/react-native-editor/CHANGELOG.md b/packages/react-native-editor/CHANGELOG.md index 2cd7647c0e0f6f..15d077d642295f 100644 --- a/packages/react-native-editor/CHANGELOG.md +++ b/packages/react-native-editor/CHANGELOG.md @@ -10,6 +10,7 @@ For each user feature we should also add a importance categorization label to i --> ## Unreleased +- [**] Prevent error message from unneccesarily firing when uploading to Gallery block [#46175] ## 1.85.0 - [*] [iOS] Fixed iOS Voice Control support within Image block captions. [#44850]