美文网首页React-Native
react-native 在方法里返回视图

react-native 在方法里返回视图

作者: Smallwolf_JS | 来源:发表于2017-02-14 09:59 被阅读149次

    在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();,第二个方法里面的视图是不会显示,我就在这个地方纠结了半天,最后还是灵光一闪发现的,希望帮助大家少走弯路,节省时间!

    相关文章

      网友评论

        本文标题:react-native 在方法里返回视图

        本文链接:https://www.haomeiwen.com/subject/xwkxwttx.html