Skip to main content

React Native StatusBar

React Native StatusBar is a component which is used to decorate status bar of the app. It is used by importing the StatusBar component from the react-native library. We can use multiple StatusBar at the same time.
  1. <View>  
  2.    <StatusBar  
  3.      backgroundColor = "#b3e6ff"  
  4.      barStyle = "dark-content"   
  5.    />  
  6. </View>  
  1. <View>  
  2.   <StatusBar   
  3.      backgroundColor = "#b3e6ff"  
  4.      barStyle = "dark-content"   
  5.   />  
  6.   <View>  
  7.     <StatusBar   
  8.        hidden={route.statusBarHidden} />  
  9.   </View>  
  10. </View>  

React Native StatusBar Props

PropsDescription
animatedA status bar is animated if its property is changed. It supports backgrondColor, hidden, and barStyle.
barStyleIt sets the color of status bar text.
hiddenIt is used to hide and show the status bar. By default, it is false. If hidden = {false} it is visible, if hidden = {true}, it hide the status bar.
backgroundColorIt sets the background color of the status bar.
translucentWhen it is set of true, the app is built under the status bar.
showHideTransitionIt displays the transition effect when showing and hiding the status bar. The default is 'fade'.
networkActivityIndicatorVisibleIt checks the network activity indicator is visible or not. It supports in iOS.

React Native StatusBar Methods

setHiddensetBarStylesetBackgroundColor
setNetworkActivityIndicatorVisiblesetTranslucent

React Native StatusBar Example 1

Let's create a simple StatusBar example in which we change its background color.

App.js


  1. import
     React, { Component } from 'react'  
  2. import {  
  3.     View,StyleSheet,AppRegistry,StatusBar  
  4. } from 'react-native'  
  5.   
  6. export default class ActivityIndicatorDemo extends Component {  
  7.     render() {  
  8.         return (  
  9.             <View style = {styles.container}>  
  10.                 <StatusBar  
  11.                     backgroundColor = "#b3e6ff"  
  12.                     barStyle = "dark-content"   
  13.                     hidden = {false}    
  14.                     translucent = {true}  
  15.                 />  
  16.             </View>  
  17.         )  
  18.     }  
  19. }  
  20. const styles = StyleSheet.create({  
  21.     container: {  
  22.         flex: 1,  
  23.     }  
  24. })  
  25. AppRegistry.registerComponent('App', () => ActivityIndicatorDemo)  

Output:

React Native StatusBar

React Native StatusBar Example 2 (hiding status bar, full screen)

In this example, we hide the StatusBar by using its property hidden = true. Hiding the StatusBar makes the display as full-screen.
  1. import React, { Component } from 'react'  
  2. import {  
  3.     View,StyleSheet,AppRegistry,StatusBar  
  4. } from 'react-native'  
  5.   
  6. export default class ActivityIndicatorDemo extends Component {  
  7.     render() {  
  8.         return (  
  9.             <View>  
  10.                 <StatusBar backgroundColor="#b3e6ff" barStyle="light-content" />  
  11.                 <View>  
  12.                     <StatusBar hidden={true} />  
  13.                 </View>  
  14.             </View>  
  15.         )  
  16.     }  
  17. }  
  18. const styles = StyleSheet.create({  
  19.     container: {  
  20.         flex: 1,  
  21.     }  
  22. })  
  23.   
  24. AppRegistry.registerComponent('App', () => ActivityIndicatorDemo)  

Output:

React Native StatusBar

Comments

Popular Posts

Reloading UITableView while Animating Scroll in iOS 11

Reloading UITableView while Animating Scroll Calling  reloadData  on  UITableView  may not be the most efficient way to update your cells, but sometimes it’s easier to ensure the data you are storing is in sync with what your  UITableView  is showing. In iOS 10  reloadData  could be called at any time and it would not affect the scrolling UI of  UITableView . However, in iOS 11 calling  reloadData  while your  UITableView  is animating scrolling causes the  UITableView  to stop its scroll animation and not complete. We noticed this is only true for scroll animations triggered via one of the  UITableView  methods (such as  scrollToRow(at:at:animated:) ) and not for scroll animations caused by user interaction. This can be an issue when server responses trigger a  reloadData  call since they can happen at any moment, possibly when scroll animation is occurring. Example of s...

What are the Alternatives of device UDID in iOS? - iOS7 / iOS 6 / iOS 5 – Get Device Unique Identifier UDID

Get Device Unique Identifier UDID Following code will help you to get the unique-device-identifier known as UDID. No matter what iOS user is using, you can get the UDID of the current iOS device by following code. - ( NSString *)UDID { NSString *uuidString = nil ; // get os version NSUInteger currentOSVersion = [[[[[UIDevice currentDevice ] systemVersion ] componentsSeparatedByString: @" . " ] objectAtIndex: 0 ] integerValue ]; if (currentOSVersion <= 5 ) { if ([[ NSUserDefaults standardUserDefaults ] valueForKey: @" udid " ]) { uuidString = [[ NSUserDefaults standardDefaults ] valueForKey: @" udid " ]; } else { CFUUIDRef uuidRef = CFUUIDCreate ( kCFAllocatorDefault ); uuidString = ( NSString *) CFBridgingRelease ( CFUUIDCreateString ( NULL ,uuidRef)); CFRelease (uuidRef); [[ NSUserDefaults standardUserDefaults ] setObject: uuidString ForKey: @" udid " ]; [[ NSUserDefaults standardUserDefaults ] synchro...

Xcode & Instruments: Measuring Launch time, CPU Usage, Memory Leaks, Energy Impact and Frame Rate

When you’re developing applications for modern mobile devices, it’s vital that you consider the performance footprint that it has on older devices and in less than ideal network conditions. Fortunately Apple provides several powerful tools that enable Engineers to measure, investigate and understand the different performance characteristics of an application running on an iOS device. Recently I spent some time with these tools working to better understand the performance characteristics of an eCommerce application and finding ways that we can optimise the experience for our users. We realised that applications that are increasingly performance intensive, consume excessive amounts of memory, drain battery life and feel uncomfortably slow are less likely to retain users. With the release of iOS 12.0 it’s easier than ever for users to find applications that are consuming the most of their device’s finite amount of resources. Users can now make informed decisions abou...