React-native basics Text, Textinput with Styles

In this article, we learn React-native basics Text, Textinput with styles like Flex, JustifyContent, aliginItems, that will help you to create basics UI with proper alignment, before this, you must install react-native successfully so I request you to go through this tutorial 

Overview:

  1. React-native Text
  2. React-native Textinput

1. React-native create project

To create a new project run following command in terminal

The new project will create

React-native Text

This is used to simply display text on the screen before moving forward you need to know that all components will work inside react-native View component as follows

I have made a project to introduce you more about this Text component so that you can understand easily

  1. firstly import the following component Text

2. Now you can use Text inside View component in return method inside the render method as given below

1. Flex:

As you see above style Flex: 1 given to the main view that mains it will spread to the whole screen as see below screenshots:

With Flex:

With Flex

Without Flex:

Without Flex

To know more about Flex please visit to this link

2. justifyContent:

justifyContent used to align data vertically as below:

With justifyContent:

With justifyContent

Without justifyContent:

Without justifyContent

There are 4 types of

1. justify-content: start Which aligns item at the beginning or start

2. justify-content: center Which aligns item at center position

3. justify-content: space-between Which add vertical space between two items

4. justify-content: space-around Which add equally space in all direction

5. justify-content: space-evenly Which add same space in all direction

alignItems align child view in cross direction that means, it parent view align vertically than alignItems align horizontally

2. Textinput:

To undestand Textinput see following code:

1st import TextInput as follows

We are going to display enter data on screen for that we use onChangeText listener on TextInput which save data in the state make sure your state is defined in the constructor otherwise it will give an error

Output:

Thank you.. enjoy coding 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *