我正在尝试在资产中使用Unable图像,然后进行expo预加载和缓存资产,但显示“无法解析../assets/image.png”,但是我已经在项目中安装了expo-asset,并且图像已经存在在资源JPG和PNG中,但还是没有。
** enter image description here
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',
},
});
请某人帮助我
我不知道您在哪个文件中,因此您应仔细检查图像是否与require(...)
的路径匹配。
请注意'../../some/path/img.png'
或'../some/path/img.png'