fix(JS): safety check on resolve uri (#3915)
This commit is contained in:
parent
3d6bc9409c
commit
84bb910d10
15
src/utils.ts
15
src/utils.ts
@ -15,17 +15,28 @@ type Source = ImageSourcePropType | ReactVideoSource;
|
|||||||
export function resolveAssetSourceForVideo(
|
export function resolveAssetSourceForVideo(
|
||||||
source: Source,
|
source: Source,
|
||||||
): ReactVideoSourceProperties {
|
): 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
|
// This is deprecated, but we need to support it for backward compatibility
|
||||||
if (typeof source === 'number') {
|
if (typeof source === 'number') {
|
||||||
return {
|
return {
|
||||||
uri: Image.resolveAssetSource(source).uri,
|
uri: convertToUri(source),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('uri' in source && typeof source.uri === 'number') {
|
if ('uri' in source && typeof source.uri === 'number') {
|
||||||
return {
|
return {
|
||||||
...source,
|
...source,
|
||||||
uri: Image.resolveAssetSource(source.uri).uri,
|
uri: convertToUri(source.uri),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user