React native 仅显示图像-反应本机

React native 仅显示图像-反应本机,react-native,React Native,我对图像中的onLayout有问题: 我有一个显示尺寸的函数 measureView(event) { console.log(event.nativeEvent.layout.width); console.log(event.nativeEvent.layout.height); } 这项工作,并向我展示了无反馈的触摸屏的尺寸 <TouchableWithoutFeedback style={styles.touchableWithoutFeedback} onLay

我对图像中的onLayout有问题:

我有一个显示尺寸的函数

measureView(event) {
   console.log(event.nativeEvent.layout.width);
   console.log(event.nativeEvent.layout.height);
}
这项工作,并向我展示了无反馈的触摸屏的尺寸

<TouchableWithoutFeedback
 style={styles.touchableWithoutFeedback}
 onLayout={(event) => this.measureView(event)}>
     <Image style={styles.image} 
     source={require("./../assets/images/photo_1.jpg")}/>
</TouchableWithoutFeedback>
this.measureView(事件)}>
但是在图像中,我什么都没有,只是没有定义

<TouchableWithoutFeedback
 style={styles.touchableWithoutFeedback}>
     <Image style={styles.image} 
     source={require("./../assets/images/photo_1.jpg")}
     onLayout={(event) => this.measureView(event)}/>
</TouchableWithoutFeedback>

this.measureView(event)}/>
你知道为什么吗


谢谢

我最近也有这个问题。它看起来像是
组件在实际映像加载到容器中之前安装的。您可能希望改为使用
onLoad
属性。一旦你这样做了,你就可以像平常一样继续

<Image
  onLoad={event => { console.log(event.nativeEvent.source); }}
  source={require("./../assets/images/photo_1.jpg")}
  style={styles.image}
/>

// Would log { height: 123, url: 'somestring', width: 123 }
{console.log(event.nativeEvent.source);}
source={require(“../../assets/images/photo_1.jpg”)}
style={style.image}
/>
//将记录{height:123,url:'somestring',width:123}
请记住,可能只对静态资源有效,也可能不适用。我不是100%认为网络图像通过该功能提供大小


祝你好运!:)

恩德,我已经完全改变了我的网络图像代码。但你的答案是对的!只是一个警告。如果加载的图像“太大”(约2048像素),图像将自动降采样。这样做是为了避免在某些无法处理大型位图的设备上崩溃。我花了一些时间才明白为什么ImageManipulator.manipleAsync不能正常工作。顺便说一下,Image.getSize也有同样的问题。更多信息:[1][2]