I'm really new to React Native and I'm wondering how can I hide/show a component.
Here's my test case:
<TextInput onFocus={this.showCancel()} onChangeText={(text) => this.doSearch({input: text})} /> <TouchableHighlight onPress={this.hideCancel()}> <View> <Text style={styles.cancelButtonText}>Cancel</Text> </View> </TouchableHighlight>
I have a TextInput
component, what I want is to show the TouchableHighlight
when the input gets the focus, then hide the TouchableHighlight
when the user press the cancel button.
I don´t know how to "access" the TouchableHighlight
component in order to hide/show it inside of my functions showCancel/hideCancel
.
Also, how can I hide the button from the very beginning?
to display 'show' if show is true and 'hide' otherwise. We control the value of show with the toggle button. To change it, we set onPress to a function that calls setShow with a callback to toggle the show value. Therefore, when we press the button, we see the text toggle between 'show' and 'hide'.
You can wrap whatever component you are trying to hide with a View with style={{width:0, height:0}}.
In your render function:
{ this.state.showTheThing && <TextInput/> }
Then just do:
this.setState({showTheThing: true}) // to show it this.setState({showTheThing: false}) // to hide it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With