React Native Tutorial – Style Text in React Native

In this React Native Tutorial we want to learn Style Text in React Native,  as you know with React Native you can build beautiful and powerful native applications for Android and IOS with just one code base.

 

 

OK first we want to create our React Native Project, there are two ways that you can create React Native Project, the first way is using React Native CLI, and the second way is using Expo CLI, now the main difference between these two is this that React Native CLI setup is little bit tough and it needs a lot of works to create Project, but if you have created your React Native Project using React Native CLI, you can customize your application, because you have access to native codes of Android and IOS. on the other hand with Expo CLI you can easily create your project, but the main problem with Expo Cli is this that you don’t have access to Android and IOS Native codes and you can not bring changes to those codes if you need. also when you want to build APK using Expo CLI it will be much larger than React Native CLI.

 

 

 

We are going to create our React Native Project using Expo CLI.

 

 

So now first install expo cli.

 

 

After that create your React Native Project with Expo CLI. you can give the name  of your project as you want.

 

 

 

There will be different files in your React Native Project, but we are interested in the App.js file, so open your App.js file, you will see that we have a simple Text component in our file. there are two ways that you can style your text or components in React Native. the first way is inline style. in here we have given inline styles for the two Text that we have.

 

 

 

And this is the complete code for App.js file.

 

 

 

Run your React Native Project from Expo Metro Bundler and this will be the result.

React Native Tutorial - Style Text in React Native
React Native Tutorial – Style Text in React Native

 

 

 

If you don’t want to use inline styling in React Native, than you can create your styles separately using StyleSheet.create() function and after that you can connect those styles with your components.

 

 

 

So you can see that we have names for every style, now we can add these names to the specific Text components that we want to change the color.

 

 

 

This is the complete code for App.js.

 

 

If you run the project the result will be the same.

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×