React-Native : measure a View

后端 未结 3 1168
醉酒成梦
醉酒成梦 2020-12-31 05:05

I\'m trying to measure a view using a ref, but the width returned is 0 despite the fact that I see the view displayed on the screen (and it\'s far

3条回答
  •  耶瑟儿~
    2020-12-31 05:26

    You want to measure the progress bar onLayout.

    var Time = React.createClass({
      getInitialState: function() {
        return({ progressMaxSize: 0 }); 
      },
      measureProgressBar: function() {
        this.progressBar.measure(this.setWidthProgressMaxSize);
      },
      setWidthProgressMaxSize: function(ox, oy, width, height, px, py) {
        this.setState({ progressMaxSize: width });
      },
      render: function() {
        return(
           { this.progressBar = c; } onLayout={this.measureProgressBar}>
            
              
            
          
        );
      }
    });
    

提交回复
热议问题