Sto provando a misurare una vista utilizzando un ref
, ma il width
restituito è 0 nonostante il fatto che vedo la vista visualizzata sullo schermo (ed è lontana dall'essere uguale a 0) .React-Native: misura a View
Ho provato a seguire questo: https://github.com/facebook/react-native/issues/953 ma semplicemente non funziona ... Voglio solo ottenere la larghezza effettiva della vista.
Ecco il mio codice:
var Time = React.createClass({
getInitialState: function() {
return({ progressMaxSize: 0 });
},
componentDidMount: function() {
this.measureProgressBar();
},
measureProgressBar: function() {
this.refs.progressBar.measure(this.setWidthProgressMaxSize);
},
setWidthProgressMaxSize: function(ox, oy, width, height, px, py) {
this.setState({ progressMaxSize: width });
},
render: function() {
return(
<View style={listViewStyle.time} ref="progressBar">
<View style={listViewStyle.progressBar} >
<View style={[listViewStyle.progressMax, { width: this.state.progressMaxSize }]}/>
</View>
</View>
);
}
});
Gli stili associati:
time: {
position: 'absolute',
bottom: 5,
left: 5,
right: 5,
backgroundColor: '#325436',
flexDirection: 'row',
},
progressBar: {
flex: 1,
backgroundColor: '#0000AA',
},
progressMax: {
position: 'absolute',
top: 0,
left: 0,
backgroundColor: '#000',
height: 30,
},
È inoltre possibile utilizzare requestAnimationFrame. –
Ottengo 'undefined non è un oggetto (valutando 'this.refs')'. Cosa sta succedendo? – fatuhoku
è necessario associare measureProgressBar, this.measureProgressBar.bind (this) – meteors