簡體   English   中英

如何使用React Native處理無顯示並阻止View組件

[英]How to handle display none and block for a View component using react native

在我的場景中,有兩個視圖。 當加載組件時,我需要沒有第二個視圖,而單擊TextInput之后需要從第二個視圖中選擇值后打開第二個視圖。在關閉第二個視圖之后,應該在第一個視圖TextInput中填充所選值。我可以實現使用react.js具有相同的效果,但是使用react native無法實現相同的效果。

var ViewDisplay = React.createClass({
   componentDidMount(){
       this.refs.secondView.getDOMNode().style.display="none";
   },
   clickHandler:function(){
         this.refs.secondView.getDOMNode().style.display="block";
   },
   populateValue:function(){
        this.refs.secondView.getDOMNode().style.display="none"; 
   },
   render:function(){
     return(<View>           
             <View  ref={firstView}>
                      <TextInput style={styles.textInput} placeholder=  {enter value} onEndEditing={this.clickHandler}/>
             </View>
            <View ref={secondView}>
               <TouchableHighlight underlayColor="#ffa456" onPress={this.populateValue}> 
                    <Text ref={key}>first</Text>
              </TouchableHighlight>
              <TouchableHighlight  underlayColor="#ffa456" onPress={this.populatevalue}>   
                 <Text>Second</Text>
              </TouchableHighlight>
              <TouchableHighlight  underlayColor="#ffa456" onPress={this.populatevalue}>  
                 <Text>third</Text>
             </TouchableHighlight>
           </View>
       </View>)
    }
})

嘗試使用點擊處理程序在組件狀態中設置一個標志,然后使用該標志確定應呈現哪個視圖

render() !this.state.clicked ? <View ref={firstView}> ... </View> : <View ref={secondView}> ... </View>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM