我想创建自定义按钮。对于这一点,我包裹着我的存在的观点为TouchableHighlight(写信给我请的另一种方式,如果它不适合在这里)React本机错误:undefined不是一个对象(评估'_this._root.setNativeProps')
<TouchableHighlight onPress={this.freeTimeTapped} underlayColor="white">
<LabelsView data={this.freeTimeData}
containerStyle={{ backgroundColor: '#3A65FF' }} />
</TouchableHighlight>
此代码抛出错误可触摸的孩子必须是本地,描述here,为例。所以,我说
setNativeProps = (nativeProps) => {
this._root.setNativeProps(nativeProps);
}
错误消失了,但现在我收到一个错误
React Native Error: undefined is not an object (evaluating '_this._root.setNativeProps')
触摸后。我究竟做错了什么?
约LabelsView更多代码:
export default class LabelsView extends Component {
// Make TouchableHighlight wrapper work
setNativeProps = (nativeProps) => {
this._root.setNativeProps(nativeProps);
}
render() {
return (
<View style={[styles.container, this.props.containerStyle]}>
<View style={styles.leftContainer}>
<Text style={[styles.nameText, styles.textColor]}> {this.props.data.leftText} </Text>
</View>
<View style={styles.rightContainer}>
<Text style={[styles.durationText, styles.textColor]}> {this.props.data.rightTopText + ' hrs'} </Text>
<Text style={[styles.rangeText, styles.textColor]}> {this.props.data.rightBottomText} </Text>
</View>
</View>
);
}
}
你在“LabelsView”中做什么?请显示它的代码? –
@AkshayRao,完成 –