2017-04-17 5 views
-1
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の初心者です。ユーザーがボタンをクリックしたときにユーザーがコメント用のポップアップボックスを表示する必要がありますが、どこが間違っているのかわかりません。テキストボックスonPressを表示している状態で反応しますか?

答えて

0

あなたが返された値をレンダリングしたいので、あなたはonPressからon Press変化との間のスペースがあり<TouchableOpacity on Press={this._callMe}>()

{this.pressed ? this._callMe() : this.showText()} 

またshowText関数の戻り値のコンポーネントで関数を呼び出す必要があります。

関連する問題