import React, { Component } from 'react';
import { AppRegistry, Text, View, TouchableOpacity } from 'react-native';
class Check extends Component {
constructor(props){
super(props);
this.pressed = true
}
_callme = () => {
if(!this.pressed){
return ( <View>
<TouchableOpacity onPress={this._callMe}>
Show me TextBox
</TouchableOpacity>
</View>
)
}
else{
return (
<View>
<TextInput />
</View>)
}
}
showText = () => {
return (
<TouchableOpacity on Press={this._callMe}>
<Text>Show me TextBox</Text>
</TouchableOpacity>
)
}
render() {
return(
<View>
{this.pressed ? this._callMe : this.showText}
</View>
)
}
}
AppRegistry.registerComponent('Check', () => Check);
我是新手进入ReactNative,我想要的是当用户点击按钮时,用户应该有一个弹出框进行评论,但我不知道我在哪里做错了?
答案 0 :(得分:0)
由于您要呈现返回的值,因此需要使用()
{this.pressed ? this._callMe() : this.showText()}
此外,showText
函数返回组件<TouchableOpacity on Press={this._callMe}>
的空格在on Press
之间变为onPress
。