React Native不显示Android图像

时间:2016-06-22 16:10:48

标签: android react-native

我最近开始使用React Native,但在Android模拟器(Pepperoni starter kit)上显示本地和外部图片时出现问题。在示例中,我有简单组件:

class SomeView extends React.Component {
    render() {
        const a = require("image!somepic")
        console.log(a)
        return (
            <View >
             <Image source={require("image!somepic")} style={styles.img}>
                 <Text>?</Text>
             </Image>

             <Image source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}} style={[styles.img, { width: 50, height: 50 }]}>
                 <Text>?</Text>
             </Image>
            </View>
        )
    }
}

我得到了什么:

虽然,在实际设备中,外部图像已加载,但本地也未加载;

我在控制台中获得了什么(是本地图像的对象):

    {
"__packager_asset":true,
"path":"D:\\Dev\\pepperoni-app-kit\\images\\somepic@3x.png",
"uri":"somepic",
"width":15.333333333333334,
"height":45.333333333333336,
"deprecated":true
}

我在Windows 10上使用React Native,ReactNative版本为“0.28.0”。位于文件夹./images/的本地图像(我包括几种尺寸:somepic.png,somepic @ 2x.png,somepic @ 3.png)

1 个答案:

答案 0 :(得分:1)

用于导入图像的语法是旧语法。新语法是

<Image source={require("./images/somepic.png")}/>

有关详细信息,请参阅Image guide