React Native 警告:Prop `resizeMode = contain` 不应直接在图像上设置

React Native Warning: Prop `resizeMode = contain` should not be set directly on Image

我在 React Native 中收到以下警告:

Prop resizeMode = contain should not be set directly on Image.

这是导致警告的代码:

<Image style={imageStyle} resizeMode={'contain'} source={require('image!elephant')} />

此代码有效,但我不清楚将图像设置为包含、覆盖或拉伸的正确方法。我做错了什么?

我认为应该在 imageStyle 中设置 resizeMode。图像支持 resizeMode 样式键。不确定为什么还有 属性。

Facebook 自己的 documentation 给出了在 Image 组件中设置 resizeMode 的示例:

<Image
  style={styles.resizeMode}
  resizeMode={Image.resizeMode.cover}
  source={fullImage}
/>

这看起来是错误的,将在 0.7.0-rc 中修复:

My understanding is that it should be used as a prop, and that using it in the style was slated to be deprecated - @brentvatne

并且:

this is fixed in 0.7.0-rc actually: 4750856 I'd wait until we merge in a fix for #1750 before using that version though - @brentvatne

https://github.com/facebook/react-native/pull/1673