Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: how to change status bar icon colors

Tags:

I can't seem to find a way to change the colors of the status bar icons to white - at the top of the screen, e.g time & battery.

iPhone 6 screenshot

I've tried adding the following in info.plist

  • Status bar style: UIStatusBarStyleLightContent
  • View controller-based status bar appearance: NO

But only seems to work in previous versions of IOS. Any help much appreciated.

like image 945
londonfed Avatar asked Dec 03 '15 14:12

londonfed


People also ask

How do I change the color of my status bar in react-native app?

Open the file App. import GeneralStatusBarColor from './src/components/GeneralStatusBarColor';... barStyle="light-content"/><View style={styles. container}><Text style={styles. welcome}>Welcome to React Native!

How do I change the color of my status bar in react-native Expo?

You can't change the color of the iOS status bar. You can use the React Native StatusBar module to either hide it, or set the text color to light (white) or dark (black).

How do I change the notification color in react-native?

Add the following code in your android/app/src/main/res/value/colors. xml file. If the file is not there then you can create a new file and add the following code in that particular file. Your icon file should be in a drawable folder with ic_notification name.

How do I change the color of my notification bar?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar. Step 3: In your MainActivity, add this code in your onCreate method.


2 Answers

You need to use StatusBarIOS inside your React Native component:

StatusBarIOS.setStyle('light-content')

Docs here: http://facebook.github.io/react-native/docs/statusbarios.html#content

Edit: As of RN 0.22, StatusBarIOS has been deprecated and the cross-platform StatusBar should be used. It has still be used imperatively as is mentioned above:

StatusBar.setBarStyle('light-content', true);

However, the recommended way to use this component is declaratively. For example:

 <View>
   <StatusBar
     backgroundColor="blue"
     barStyle="light-content"
   />
   <Navigator
     initialRoute={{statusBarHidden: true}}
     renderScene={(route, navigator) =>
       <View>
         <StatusBar hidden={route.statusBarHidden} />
         ...
       </View>
     }
   />
 </View>

See the new docs here: http://facebook.github.io/react-native/docs/statusbar.html

like image 154
Dave Sibiski Avatar answered Sep 21 '22 00:09

Dave Sibiski


I faced the same problem. Following docs (https://reactnative.dev/docs/statusbar#barstyle) didn't help.

So, I just did a Opt+Click on StatusBar component to found what props you can change, and what methods it provides.

Snippet of props I found:

export declare type StatusBarStyle = 'auto' | 'inverted' | 'light' | 'dark';
export declare type StatusBarAnimation = 'none' | 'fade' | 'slide';
export declare type StatusBarProps = {
    /**
     * Sets the color of the status bar text. Default value is "auto" which
     * picks the appropriate value according to the active color scheme, eg:
     * if your app is dark mode, the style will be "light".
     */
    style?: StatusBarStyle;

I used this information and updated the StatusBar component like so:

<StatusBar style="light" />

And voilla, I changed the icons and text color to white!

like image 37
Deepak Avatar answered Sep 25 '22 00:09

Deepak