Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set iOS status bar background color in React Native?

Is there a single place in the react native iOS native code that I could modify to set iOS statusbar backgroundColor? RCTRootView.m ?

The react native StatusBar component only support backgroundColor for Android only.

The iOS operating system seems to allow setting status bar backgroundColor

My goal is to have a darker status bar color. Example

like image 805
Ed of the Mountain Avatar asked Sep 02 '16 16:09

Ed of the Mountain


People also ask

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

If you use expo-status-bar to control your status bar style, the style="auto" configuration will automatically pick the appropriate default style depending on the color scheme currently used by the app (this is the default behavior, if you leave out the style prop entirely then auto will be used).

How does react-native handle status bar?

The Status bar is easy to use and all you need to do is set properties to change it. The hidden property can be used to hide the status bar. In our example it is set to false. This is default value.


1 Answers

iOS doesn't have a concept of a status bar bg. Here's how you'd achieve this in a cross-platform way:

import React, {   Component, } from 'react'; import {   AppRegistry,   StyleSheet,   View,   StatusBar,   Platform,   SafeAreaView } from 'react-native';  const MyStatusBar = ({backgroundColor, ...props}) => (   <View style={[styles.statusBar, { backgroundColor }]}>     <SafeAreaView>       <StatusBar translucent backgroundColor={backgroundColor} {...props} />     </SafeAreaView>   </View> );  class DarkTheme extends Component {   render() {     return (       <View style={styles.container}>         <MyStatusBar backgroundColor="#5E8D48" barStyle="light-content" />         <View style={styles.appBar} />         <View style={styles.content} />       </View>     );   } }  const STATUSBAR_HEIGHT = StatusBar.currentHeight; const APPBAR_HEIGHT = Platform.OS === 'ios' ? 44 : 56;  const styles = StyleSheet.create({   container: {     flex: 1,   },   statusBar: {     height: STATUSBAR_HEIGHT,   },   appBar: {     backgroundColor:'#79B45D',     height: APPBAR_HEIGHT,   },   content: {     flex: 1,     backgroundColor: '#33373B',   }, });  AppRegistry.registerComponent('App', () => DarkTheme); 

simulator

like image 119
jmurzy Avatar answered Sep 28 '22 02:09

jmurzy