ImageBackground ResizeMode [英] ImageBackground ResizeMode

查看:37
本文介绍了ImageBackground ResizeMode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新了React-native,并使用以下代码引入了警告:

I recently updated React-native and it introduced a warning, with the following code:

 <Image
      source={require('../../assets/icons/heart.png')}
      style={{
        resizeMode: 'contain',
        height: 25,
        width: 25
      }}
    >
      <Text>foobar</Text>
    </Image>

警告:

index.ios.bundle:50435不建议将< Image>与孩子一起使用,并且在不久的将来将是一个错误.请重新考虑布局或改用< ImageBackground>.

index.ios.bundle:50435 Using <Image> with children is deprecated and will be an error in the near future. Please reconsider the layout or use <ImageBackground> instead.

问题是当我使用ImageBackground组件时,它警告我不能将ResizeMode样式与其一起使用.

Trouble is when I use ImageBackground component instead it gives me a warning that you can't use ResizeMode style with it.

 <ImageBackground
      source={require('../../assets/icons/heart.png')}
      style={{
        resizeMode: 'contain',
        height: 25,
        width: 25
      }}
    >
      <Text>foobar</Text>
    </ImageBackground>

警告:

警告:失败的道具类型:无效的道具.样式键"resizeMode"提供给查看".错误的对象:{ResizeMode:'包含,高度:25,宽度:25}

Warning: Failed prop type: Invalid props.style key 'resizeMode' supplied to 'View'. Bad object: { ResizeMode: 'contain, height: 25, width: 25}

您应该如何使用ImageBackgrounds?似乎没有关于它的任何在线文档.

How are you supposed to use ImageBackgrounds? There doens't seem to be any documentation about it online.

推荐答案

ImageBackground接受两个样式道具– style和imageStyle –(显然)分别应用于内部View和Image.还值得注意的是,容器样式中的高度和宽度值会自动应用于图像样式.有关详细信息,请访问.

ImageBackground accepts two style props – style and imageStyle – which are (obviously) applied to the internal View and Image respectively. It's also worth noting that height and width values from the container style are applied to the image style automatically. For details visit this.

这篇关于ImageBackground ResizeMode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆