Я новый, чтобы реагировать-родной. Я пытаюсь прочитать x, y координаты представления внутри своего родителя. Использование ниже кода
componentDidMount: function() {
setTimeout(this.measureView);
},
measureView: function() {
this.refs.completeView.measure((ox, oy, width, height) => {
this.setState({headerHeight: height});
});
},
render : function(){
return (
<TouchableHighlight onPress={() => this.props._pressRow(this.props.currentRowID)}>
<View style={styles.container}
ref="completeView">
<View style={styles.colorView}>
</View>
<View style={styles.textWrapper}>
<Text style={styles.text}>{this.props.text}</Text>
</View>
</View>
</TouchableHighlight>
);
},
Внутри measureView
this.refs
всегда undefined
. Зачем?
Я пытаюсь прочитать последние координаты представления в ListView
, потому что по какой-то причине я хочу отобразить последнюю строку. Так есть ли другое решение для этого?
Также обратите внимание, что этот класс экспортируется в его родительский класс.
set ref, используя функцию вместо строки:
var myComponent = null;
...
componentDidMount: function() {
setTimeout(this.measureView);
},
measureView: function() {
this.myComponent.completeView.measure((ox, oy, width, height) => {
this.setState({headerHeight: height});
});
},
render : function(){
return (
<TouchableHighlight onPress={() => this.props._pressRow(this.props.currentRowID)}>
<View style={styles.container}
ref={((component)=>this.myComponent = component)}>
<View style={styles.colorView}>
</View>
<View style={styles.textWrapper}>
<Text style={styles.text}>{this.props.text}</Text>
</View>
</View>
</TouchableHighlight>
);
},
Попробуйте использовать лямбда ES2015, чтобы получить правильное лексическое значение этого метода.
measureView = () => {
this.refs.completeView.measure((ox, oy, width, height) => {
this.setState({headerHeight: height});
});
},
View
пожалуйста?