我最近更新了React native,它引入了一个警告,代码如下:

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

还有警告:

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样式.

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

还有警告:

警告:失败的props 类型:无效的props .样式键"resizeMode"

你应该如何使用图像背景?网上似乎没有关于它的任何文档.

推荐答案

ImageBackground接受两个样式props ——style和imageStyle——它们(显然)分别应用于内部视图和图像.还值得注意的是,容器样式中的高度和宽度值会自动应用于图像样式.

React-native相关问答推荐

如何在API调用期间将本地存储(Expressc存储)中的令牌传递到后台

React Navigation—从标题按钮打开模式

复制__自持props

在向后滑动时执行操作(react-navigation )

React-Native:无法从我的 android 应用程序打开设备设置

PanResponder 在第二次拖动时将 Animated.View 捕捉回原始位置

No component found for view with name "ARTShape"

IntelliSense 在第一项后无法在 React Native 样式表中工作

withNavigation 只能用于导航器的视图层次 struct

ReactJS toLowerCase 不是一个函数

React Native - 如何判断 UI/元素?

redux saga 的delay延迟功能不起作用

Fragment片段内的react-native

在 Android React Native 应用程序中正确使用 Intl

加载远程图像失败后加载本map像

如何在 React Native 中使用 Jest

> 任务 :app:checkDebugAarMetadata 在运行 react-native run-android 时失败

如何将时刻日期转换为字符串并删除时刻对象

React Native如何将this.setState更改传递给父级

如何升级 react-native gradle 版本