Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render react native app under the status bar?

I am learning app development in react native and my app is overlapping with the status bar of my phone. If I add padding to the top then the padding would differ for different phones. I tried using SafeAreaView but it is not working and I read somewhere it only works for iPhones. So is there any way that I can render the app under the status bar? Any suggestions would be appreciated.

The app getting overlapped with the status bar

Screen Shot

like image 865
Kunal Avatar asked Dec 14 '25 18:12

Kunal


2 Answers

I finally solved it by simply adding paddingTop:StatusBar.currentHeight to the root view tag of my component.

like image 120
Kunal Avatar answered Dec 18 '25 11:12

Kunal


You will need to find the statusbar height and set the top margin of your container to be equal to that amount.

Since Expo provides this value as a constant, you can use it to set the style of your parent component such that the content is always under the status bar.

You can follow this pattern from the github issue here

const App = StackNavigator({
  Home: { screen: HomeScreen },
  About: { screen: AboutScreen },
  }, {
    navigationOptions: { headerStyle: { marginTop: Expo.Constants.statusBarHeight } }
  })
like image 41
nipuna777 Avatar answered Dec 18 '25 13:12

nipuna777



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!