From 84bb910d10e3e3d70f9e92b57c17de829d73218a Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:19:18 +0200 Subject: [PATCH] fix(JS): safety check on resolve uri (#3915) --- src/utils.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 0200ffc0..4d5e29c8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -15,17 +15,28 @@ type Source = ImageSourcePropType | ReactVideoSource; export function resolveAssetSourceForVideo( source: Source, ): ReactVideoSourceProperties { + // will convert source id to uri + const convertToUri = (sourceItem: number): string | undefined => { + const resolveItem = Image.resolveAssetSource(sourceItem); + if (resolveItem) { + return resolveItem.uri; + } else { + console.warn('cannot resolve item ', sourceItem); + return undefined; + } + }; + // This is deprecated, but we need to support it for backward compatibility if (typeof source === 'number') { return { - uri: Image.resolveAssetSource(source).uri, + uri: convertToUri(source), }; } if ('uri' in source && typeof source.uri === 'number') { return { ...source, - uri: Image.resolveAssetSource(source.uri).uri, + uri: convertToUri(source.uri), }; }