Hide Show View Text Component in React Native on button Click

Hiding and Showing the any component from the application screen is a easy process if you have a little knowledge about States. We would going to Change the states value on button onPress. Regarding the changed value we have been Hide Show View component using ternary operator in Android and iOS.

Contents in this project Hide Show View Text Component :

1. Start a fresh React Native project. If you don’t know how then read my this tutorial.

2. Add
AppRegistry ,
StyleSheet ,
Text ,
View and
Button  component in import block.

3. Create Constructor in your class with Super method and make a state named as status. Now set the status state value as true. This is the default status value so when the application load at first time it will show us the View or Text component passed in ternary operator syntax.

4. Create function named as ShowHideTextComponentView . We have to call this function on button onPress and it will change the status state value . If the value is true then it changes it to false and if the value is false then it set it to true.

5. Create custom style css class named as MainContainer .

6. Add View as parent view in render’s return block and Call the MainContainer class into View.

7. Add {  } curly bracts inside the View component and inside the curly bracket using Ternary operator set condition. So if the given status state value is true then it shows the first passed view and if the status value is false then it hide the first view.

8. Add Button component, set onPress on button and call the ShowHideTextComponentView function.

9. Complete source code for index.android.js / index.ios.js file.

Screenshots :

Hide Show View