对于第一次加载我的应用程序 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>
答案 0 :(得分:1)
可能您需要在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') ;
}
}