简体   繁体   English

如何使用React Native处理无显示并阻止View组件

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

In my scenario there are two Views. 在我的场景中,有两个视图。 While load the component i need to none second view after while click on TextInput need to open the second view after selecting the value from the second view selected value should be populate in the first view TextInput after that secondView should be closed.I can acheieve the same effect using react.js but the same effect i am unable to do 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