Status Bar is the top above main icon holder bar in android and iOS mobile phones. Status Bar is used to show Mobile device 2G, 3G, 4G Network Icon, WiFi icon, Live time clock, Notifications and Battery icon in both android and iOS mobiles. So in this tutorial we would going to make a react native app with StatusBar Component in both Android iOS Example. We would perform various types of functionality on Mobile’s own Status bar using this component. So let’s get started .
Contents in this project React Native StatusBar Component Android iOS Example Tutorial :
1. Import StyleSheet, View, StatusBar, Text and Platform component in your project.
1
2
3
|
import React, { Component } from ‘react’;
import { StyleSheet, View, StatusBar, Text, Platform } from ‘react-native’;
|
2. Create a Root View in render’s return block. This View is our main View component.
1
2
3
4
5
6
7
8
9
10
11
|
render() {
return (
<View style={styles.MainContainer}>
</View>
);
}
|
3. Create the StatusBar component in Root View.
barStyle : This prop would help us to set the color of StatusBar inside Text and Icons. There are 3 types of value this prop would support :
- light-content
- dark-content
- default
hidden : This prop would hide the StatusBar and make your app full screen. If you set false inside it then it will not hide the StatusBar. If you set true in it then it will hide the StatusBar.
backgroundColor : Used to set the background color of StatusBar.
Note :: Only Android app supports backgroundColor prop and it will not work in iOS application.
translucent : This prop is also works only in Android devices. This would allow our app to draw the app data under the Status bar.
networkActivityIndicatorVisible : To show the Network Activity Indicator in iOS devices. This prop will not work in Android devices.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
render() {
return (
<View style={styles.MainContainer}>
<StatusBar
barStyle = “light-content”
hidden = {false}
backgroundColor = “#00BCD4”
translucent = {true}
networkActivityIndicatorVisible = {true}
/>
</View>
);
}
|
4. Adding a Sample Text component after Status Bar.
1
|
<Text style={{textAlign : ‘center’, fontSize: 25}}> React Native Status Bar Example Tutorial </Text>
|
5. Create Style for Root View.
1
2
3
4
5
6
7
8
9
10
11
|
const styles = StyleSheet.create({
MainContainer :{
justifyContent: ‘center’,
flex:1,
marginTop: (Platform.OS == ‘ios’) ? 20 : 0
}
});
|
6. Complete source code for App.js File :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import React, { Component } from ‘react’;
import { StyleSheet, View, StatusBar, Text, Platform } from ‘react-native’;
export default class Myproject extends Component {
render() {
return (
<View style={styles.MainContainer}>
<StatusBar
barStyle = “light-content”
hidden = {false}
backgroundColor = “#00BCD4”
translucent = {true}
networkActivityIndicatorVisible = {true}
/>
<Text style={{textAlign : ‘center’, fontSize: 25}}> React Native Status Bar Example Tutorial </Text>
</View>
);
}
}
const styles = StyleSheet.create({
MainContainer :{
justifyContent: ‘center’,
flex:1,
marginTop: (Platform.OS == ‘ios’) ? 20 : 0
}
});
|
Screenshot in Android device :
Screenshot in iOS device :