React native 使用Flex时图像消失

React native 使用Flex时图像消失,react-native,flexbox,React Native,Flexbox,问题很简单:每当我在图片上使用flex时,在expo上预览我的应用程序时,它就不会显示出来 我就是这样做的: <Image style = {{flex: 1, height: undefined, width: undefined}} source = {require('./img/anyImage.png')} /> 如果我只定义高度和宽度,没有弯曲,它们就

问题很简单:每当我在图片上使用flex时,在expo上预览我的应用程序时,它就不会显示出来

我就是这样做的:

            <Image 
                style = {{flex: 1, height: undefined, width: undefined}}
                source = {require('./img/anyImage.png')}
            /> 

如果我只定义高度和宽度,没有弯曲,它们就会显示出来。我的照片没有出现有什么特别的原因吗

注意:我已经尝试给高度和宽度都设置了值


非常感谢

传递null而不是undefined应该对您有帮助

 <Image 
                    style = {{flex: 1, height: null, width: null}}
                    source = {require('./img/anyImage.png')}
                /> 

嘿,尝试使用null,但仍然不起作用。我刚刚注意到,如果我尝试将flex添加到文本组件中,这也不起作用。我需要导入一些东西吗?或者这只是一个奇怪的问题?如果你把代码推到github并在这里留下一个链接,那就太好了,那就是到回购协议的链接。谢谢!注意:我上传的代码目前没有使用flex。我把它改成了固定的宽度和高度,这样我就可以继续工作了。另一个突然出现的问题是,当我将图像包装在TouchableOpacity组件中时,它们也会消失。我正在根据您发送的代码编辑我的答案
{/* THIS IS THE FIRST OPTION YOU CAN USE  */}
        <View>
          <View style={{ width: 100, height: 100 }}>
            <Image
              style={{ flex: 1, width: null }}
              source={require("./img/cervecerias.png")}
            />
          </View>
        </View>



    {/* THIS IS THE SECOND OPTION YOU CAN USE  */}
    <View style={{ width: 200, height: 100 }}>
      <Image
        style={{ flex: 1 }}
        source={require("./img/Cocktails.png")}
        resizeMode="contain"
      />
      <Text style={styles.categoriesText}> Cocktails</Text>
    </View>