Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function _getAssetForSource(source: FontSource): Asset {
if (source instanceof Asset) {
return source;
}
if (!isWeb && typeof source === 'string') {
return Asset.fromURI(source);
}
if (isWeb || typeof source === 'number') {
return Asset.fromModule(source);
}
// @ts-ignore Error: Type 'string' is not assignable to type 'Asset'
// We can't have a string here, we would have thrown an error if !isWeb
// or returned Asset.fromModule if isWeb.
return source;
}
export function getAssetForSource(source: FontSource): Asset | FontResource {
if (source instanceof Asset) {
return source;
}
if (typeof source === 'string') {
return Asset.fromURI(source);
} else if (typeof source === 'number') {
return Asset.fromModule(source);
} else if (typeof source === 'object' && typeof source.uri !== 'undefined') {
return getAssetForSource(source.uri);
}
// @ts-ignore Error: Type 'string' is not assignable to type 'Asset'
// We can't have a string here, we would have thrown an error if !isWeb
// or returned Asset.fromModule if isWeb.
return source;
}
it('should passes when used properly', () => {
Asset.fromModule('uri').downloadAsync();
Asset.fromModule(1).downloadAsync();
});
function _getAssetFromPlaybackSource(source?: PlaybackSource | null): Asset | null {
if (source == null) {
return null;
}
let asset: Asset | null = null;
if (typeof source === 'number') {
asset = Asset.fromModule(source);
} else if (source instanceof Asset) {
asset = source;
}
return asset;
}
return Object.values(images).map(image => {
if (typeof image === 'string') {
return Image.prefetch(image);
}
return Asset.fromModule(image).downloadAsync();
});
};
async componentDidMount() {
const image = Asset.fromModule(
require('../../assets/images/example2.jpg')
);
await image.downloadAsync();
this.setState({
ready: true,
image,
original: image,
});
}
return files.map(file => Asset.fromModule(file).downloadAsync());
}