如果我在组件安装时在我的app.js中加载图像和字体,然后路由到另一个页面,那么我需要做些特殊的事情来调用那些缓存的图像吗?还是我只使用例如:
<ImageBackground
source={require('../assets/images/backgrounds/sky.jpg')}
style={styles.backgroundContainer}
>
app.js是:
async _loadAssetsAsync() {
try {
await cacheAssetsAsync({
images: [require('./assets/images/backgrounds/sky.jpg')],
fonts: [
FontAwesome.font,
{ 'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf') },
],
});
} catch (e) {
console.warn(
'There was an error caching assets (see: main.js), perhaps due to a ' +
'network timeout, so we skipped caching. Reload the app to try again.'
);
console.log(e.message);
} finally {
this.setState({ appIsReady: true });
}
}
答案 0 :(得分:0)
如果您在assetBundlePatterns
中包含了app.json
,则不需要缓存图像。这些图像将被捆绑到应用程序中。
...
"assetBundlePatterns": [
"**/*"
],
...