React Natve显示文本框onPress?

时间:2017-04-17 05:28:17

标签: reactjs react-native

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,我想要的是当用户点击按钮时,用户应该有一个弹出框进行评论,但我不知道我在哪里做错了?

1 个答案:

答案 0 :(得分:0)

由于您要呈现返回的值,因此需要使用()

调用该函数
{this.pressed ? this._callMe() : this.showText()}

此外,showText函数返回组件<TouchableOpacity on Press={this._callMe}>的空格在on Press之间变为onPress