Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NativeBase + Exponent Header

I'm using NativeBase with Exponent. The Header goes beneath the phone's StatusBar. You can see this in the NativeBase demo that Exponent released.

enter image description here

Does anyone have a fix for this?

like image 965
Molly Harper Avatar asked Feb 07 '17 19:02

Molly Harper


3 Answers

Since this issue only comes up in Android, the recommended way to fix this would be to target Android specifically using Platform :

import {Platform, StatusBar} from 'react-native'

const styles = StyleSheet.create({
    container: {
            flex: 1,
            ...Platform.select({
                android: {
                    marginTop: StatusBar.currentHeight
                }
            })

        }
})

Where container is the main container in the app.

<View style={styles.container}>
 // rest of the code here
</View>
like image 72
Varun Nath Avatar answered Nov 05 '22 22:11

Varun Nath


I ended up adding a marginTop with the value of the device's StatusBar.

import {
  StatusBar,
} from 'react-native'

In my global stylesheet:

header: {
  marginTop: StatusBar.currentHeight,
}
like image 33
Molly Harper Avatar answered Nov 05 '22 23:11

Molly Harper


Old post but recently I've faced same issue with Expo. And I overcome this issue by adding this line to app.json file.

"androidStatusBar": { "backgroundColor": "#000000" }

app.json file

{
  "expo": {
    "name": "You App Name",    
    "androidStatusBar": {
      "backgroundColor": "#000000"
    }
  }
}

That solved my issue. I think this may help to others.

like image 44
Shahriar Hasan Sayeed Avatar answered Nov 06 '22 00:11

Shahriar Hasan Sayeed