首页 > react-native图片加载的问题

react-native图片加载的问题

android下怎么动态获取图片高宽呢?我在onload里没有办法获取到图片对象本身,以下做法失败了

<Image source={{uri: this.state.movie.img}} 
style={{width:this.state.movie.imgW, height:this.state.movie.imgH}} 
onProgress={(e) =>this._handleProgress(e)}
onLoad={(e) =>this._handleLoad(e)}
>{loader}</Image>

e是个对象,但是没有包含图片对象信息,另外onProgress是ios专用的么,在安卓下并没有触发这个事件


看Image的官方文档,我copy了一部分如下:

Methods
static getSize(uri: string, success: (width: number, height: number) => void, failure: (error: any) => void)

Retrieve the width and height (in pixels) of an image prior to displaying it. This method can fail if the image cannot be found, or fails to download.

In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images, however it is not optimized for that purpose, and may in future be implemented in a way that does not fully load/download the image data. A proper, supported way to preload images will be provided as a separate API.


这个方法我已经试过,使用这个方法Image.getSize会报undefined错误,这个框架在android下坑太多了。

【热门文章】
【热门文章】