React Native Notes 23: How to Translucent StatusBar?
The absolute way to make our StatusBar Translucent for both iOS and Android
This is what we want to achieve right? It looks elegant, simple and it should be easy to do. However, set the translucent to StatusBar prop sometimes does not work and makes us crazy.
And again, fortunately the solution is simple.
Code:
import { Platform, StatusBar } from 'react-native';
StatusBar.setBarStyle("light-content");
if (Platform.OS === "android") {
StatusBar.setBackgroundColor("rgba(0,0,0,0)");
StatusBar.setTranslucent(true);
}
Gist:
You need to check the operating system here because .setBackgroundColor
and .setTranslucent
methods only works on Android. iOS handles itself by default (Thank you Apple Engineers 😇)
After that, we got what we need for both iOS and Android.
Of course, you do not need to set bar style as light-content
, you can change it depends on your design.
If you need an example for guidance, here you go:
All you need to do is;
- Clone the repo
- npm i
- react-native run-ios/android
- Check the code 😋