【发布时间】:2021-11-13 20:04:39
【问题描述】:
我正在尝试在我的 react 本机应用程序中使用图像。
此时我的代码很少
这就是我现在拥有的所有代码
import React from 'react';
import { ScrollView, View, Text } from 'react-native';
import Image from '@src/assests/images/avatars/Allan Munger.png';
import { ImageCircle } from '@src/components/elements';
const App = () => {
const [active, setActive] = React.useState(0);
return (
<View>
<ImageCircle uri={Image} active={false} />
</View>
);
};
export default App;
ImageCircle 在哪里
import React from 'react';
import { View, Text, Image, ImageSourcePropType } from 'react-native';
import Styles from './styles';
const ImageCircle = ({ active, uri }) => {
console.log('uri', uri);
return (
<View
style={{
width: 60,
height: 60,
borderRadius: 30,
borderColor: 'red',
borderWidth: 1,
}}>
<Image source={uri} width={60} height={60} />
</View>
);
};
export default ImageCircle;
我在圆圈中(或任何地方)看不到我的图像。
在控制台中,有这样一条日志
Asset not found: /Users/varunb/Desktop/project-emma/src/assests/images/avatars/Allan%20Munger@2x.png for platform: ios
谁能告诉我为什么我在 iPhone 上看不到图片以及为什么会出现此错误?以及如何解决?
Ps:如果我从图像导入中删除空间(并重命名图像),那么一切正常,即
import Image from '@src/assests/images/avatars/AllanMunger.png';
【问题讨论】:
-
看起来这可能是一个错误。有什么阻止您使用
Allan_Munger.png作为文件名吗?除此之外,我建议查看 react-native 的库代码并在 GitHub repository 上打开一个问题。 -
@Elias 它更像是一个编码任务。我不确定,但这可能是故意的,我的目标是找到解决此问题的方法
-
我会去和分配者谈谈。我刚刚在本地环境中测试了带有空格的路径,并面临与您完全相同的问题。
标签: javascript reactjs typescript react-native