React Native: Setting a Status bar background color 🎨 on Android and iOS

Samuel Matias
React Brasil
3 min readJan 27, 2019

--

How do you know, iOS doesn’t have a concept of a Status bar background color, although the React Native has a StatusBar Component but only support backgroundColor for Android. So, to be possible on iOS too, we need to create a component to do this.

Let’s get started with the code!z

Before starting…

To change the Status bar background color on iPhone X, XS, XR +++, you need to use the SafeAreaView component by React Native.
So, on the iOS case, this tutorial works only for Devices below the iPhone X (iPhone 8, 7, 6, 5, etc…).

Now, we really will start with the code!

1- Create React Native App

Creating a new React Native app, from the command line:

2- Create the structure for the component

In your project root, create a structure for your component, like this:

The component structure

3- Starting the stateless component

Open the file GeneralStatusBarColor.js and start it as a stateless component, like this:

4- Setting the component style

Open the file GeneralStatusBarColorStyles.js and setting the file, like this:

5- Encoding the component

Returning to the file GeneralStatusBarColor.js, let’s improve the code, adding the feature to changing the status bar background color on Android and iOS.

6- Importing and Implementing the component to the main file.js

Open the file App.js and import the component, like this:

After import, replace the render method, like this:

7- Testing the GeneralStatusBarColor component

For iOS, open your simulator and in your project root, run this command:

For Android, open your simulator and in your project root, run this command:

Now, you can see that the GeneralStatusBarColor component working:

I hope you enjoyed. Thank’s for your time. CYA ! o/

--

--