Skip to content

Instantly share code, notes, and snippets.

@dantman
Created April 25, 2017 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dantman/235833869dab844340ee530c1643a208 to your computer and use it in GitHub Desktop.
Save dantman/235833869dab844340ee530c1643a208 to your computer and use it in GitHub Desktop.
react-navigation statusbar height example
export default class App extends PureComponent {
state = {
statusBarHeight: Platform.OS === 'android'
? StatusBar.currentHeight || (Platform.Version < 23 ? 25 : 24)
: 0,
};
render() {
const {styles} = this;
const {statusBarHeight} = this.state;
return (
<View style={styles.root}>
<StatusBar
backgroundColor='rgba(0, 0, 0, 0.2)'
translucent />
<Navigator screenProps={{statusBarHeight}} />
</View>
);
}
}
const Navigator = StackNavigator({
// ...
}, {
navigationOptions: ({screenProps: {statusBarHeight}, navigationOptions}) => ({
...navigationOptions,
headerStyle: {
paddingTop: statusBarHeight,
height: Header.HEIGHT + statusBarHeight,
...navigationOptions.headerStyle,
},
}),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment