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(
|
||||
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),
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user