React Native:第一次加载时未显示背景图片

React Native : Background Image not being shown in first load

首次加载我的应用程序 BackgroundImage 未在 首次加载.

中显示

真的,我正在使用地图,这些是集群的背景

componentWillMount(){
    if (this.props.pointCount < 10) {
        this.cluster_image = require('../assets/cluster1_mobile.png') ;
    }else if (this.props.pointCount < 100) {
        this.cluster_image = require('../assets/cluster2_mobile.png') ;
    }else{
        this.cluster_image = require('../assets/cluster3_mobile.png') ;
    }
}

并在渲染中

<ImageBackground source={ this.cluster_image }>
   <Text>
      {this.props.pointCount}
   </Text>
</ImageBackground>

可能您需要在 constructor

中进行设置
constructor(props){
super(props)
if (props.pointCount < 10) {
        this.cluster_image = require('../assets/cluster1_mobile.png') ;
    }else if (props.pointCount < 100) {
        this.cluster_image = require('../assets/cluster2_mobile.png') ;
    }else{
        this.cluster_image = require('../assets/cluster3_mobile.png') ;
    }
}