function cacheImages(images) {
return images.map(image => {
if (typeof image === 'string') {
return Image.prefetch(image);
} else {
return Asset.fromModule(image).downloadAsync();
}
});
}
function cacheFonts(fonts) {
return fonts.map(font => Font.loadAsync(font));
}
export default class App extends React.Component {
constructor (props) {
super(props);
this.state = { isReady : false };
}
async _loadAssetsAsync () {
const imageAssets = cacheImages(require('./assets/icon.png'));//['https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png']);
const fontAssets = cacheFonts([FontAwesome.font]);
await Promise.all([...imageAssets, ...fontAssets]);
}
render() {
if (!this.state.isReady) {
return (
<AppLoading
startAsync={this._loadAssetsAsync}
onFinish={() => this.setState({ isReady: true })}
onError={alert('Error loading assets')}/>
);
}
return (
<Provider store={Store}>
<View style={{ flex:1, width: '100%', height: '100%' }}>
<Navigator></Navigator>
<LoadingModal></LoadingModal>
</View>
</Provider>
);
我尝试在他们的网站上使用 expo 提供的代码在应用程序加载之前预取 Assets 和其他相关图像。
我在呈现 Apploading 元素后收到错误。该异常未显示任何有意义的特定错误。
AppLoading threw an unexpected error when loading:
cacheImages@http://localhost:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false&assetPlugin=%2FUsers%2Fsimonlam%2FDesktop%2Freact_native%2F
最佳答案
移除 AppLoading onError
方法中的警报并使用 console.error
代替,
该行存在解析错误。
关于react-native - react native : Loading Assets before app is ready threw an exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53348973/