【发布时间】:2020-05-16 07:23:56
【问题描述】:
我正在尝试在资产中使用 Unable 图像,然后是 expo 预加载和缓存资产,但它显示此错误:
无法解析 ../assets/image.png
我已经在我的项目中安装了 expo-asset,并且我的图像已经以 JPG 和 PNG 的形式保留在资产中,但它仍然没有任何作用。
import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import firebase from 'firebase'
import { Asset } from 'expo-asset';
import { AppLoading } from 'expo';
import MusicApp from './App/index';
function cacheImages(images) {
return images.map(image => {
if (typeof image === 'string') {
return Image.prefetch(image);
} else {
return Asset.fromModule(image).downloadAsync();
}
}); } export default class RegisterScreen extends Component {
static navigationOptions = {
header: null
}
constructor() {
super();
this.state = {
isReady: false
};
}
async _loadAssetsAsync() {
const imageAssets = cacheImages([require('./assets/LUMO-logo.jpg')]);
await Promise.all([...imageAssets]);
}
render(){
if(!this.state.isReady){
return(
<AppLoading
startAsync={this._loadAssetsAsync}
onFinish={() => this.setState({ isReady: true })}
onError={console.warn}
/>
);
}
return <MusicApp />;
} } const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
谁能帮帮我。
【问题讨论】:
标签: react-native png jpeg expo assets