如何使用Image React-Native组件的getImage处理错误?

时间:2019-01-04 13:44:23

标签: react-native

我无法根据react native image上的文档来实现。有人可以帮我吗?

Image.getSize(this.props.data.thumbnail, (width,height) =>{
        const win = Dimensions.get('window')
        const ratio = win.width/width
        this.setState( {
            width: style.width,
            height: height * ratio
        })
    })

1 个答案:

答案 0 :(得分:1)

有一个错误回调,可用于处理错误。

 Image.getSize(this.props.data.thumbnail, (width, height) =>
    {
        const win = Dimensions.get('window')
        const ratio = win.width/width
        this.setState({
          width: style.width,
          height: height * ratio
        })
    }, (error) =>
    {
        this.setState({ loading: false });
        console.log( error );
    });