Created
April 25, 2017 17:36
-
-
Save dantman/235833869dab844340ee530c1643a208 to your computer and use it in GitHub Desktop.
react-navigation statusbar height example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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