React-Native

react-native 在方法里返回视图

2017-02-14  本文已影响149人  Smallwolf_JS

在react-native中我们经常要进行判断,然后决定视图的显示方式,所以就会经常出现下面这样的代码:

renderChanged(){
    return(
       this.showPro()
   );
}
showPro(){//进度条
      return(
          <View style={{marginTop: 200,flexDirection:'row'}}>
              <View style={{marginRight:10,height:16,width:ScreenWidth - 120}}>
                  <View style={styles.progressLabel}>
                      <Text style={{textAlign:'center',}}>{this.state.progress}</Text>
                  </View>
                  <View style={[styles.progressView,{width:(ScreenWidth - 150) * this.state.progress }]}></View>
              </View>
              <TouchableOpacity style={styles.cancleButton}
                                onPress={this.cancleClick.bind(this)}
              ></TouchableOpacity>
          </View>
      );
    }```

如果第一个方法里面不加入return();,第二个方法里面的视图是不会显示,我就在这个地方纠结了半天,最后还是灵光一闪发现的,希望帮助大家少走弯路,节省时间!
上一篇 下一篇

猜你喜欢

热点阅读