Skip to content

Commit 341b29d

Browse files
corbtFacebook Github Bot 8
authored and
Facebook Github Bot 8
committed
Render NavigationHeader correctly with hidden status bar
Summary: Currently, the NavigationExperimental `Header` only renders correctly on iOS when the system status bar is visible. There are legitimate reasons to hide the status bar, especially when displaying in landscape. This PR adds a `statusBarHeight` prop to the header, which defaults to 20 on iOS and 0 (no status bar) on Android. Changing this value causes the extra space at the top of the header reserved for the status bar to change. I've tested this change in my own app on iOS with `statusBarHeight` set to 0, 20, and `undefined`, and ensured that it works correctly. Closes facebook#8983 Differential Revision: D3668637 fbshipit-source-id: 777a0c53e8fd1caa35ce4980ca3118adcf83b62d
1 parent 5d0131d commit 341b29d

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Libraries/CustomComponents/NavigationExperimental/NavigationHeader.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type DefaultProps = {
6262
renderLeftComponent: SubViewRenderer,
6363
renderRightComponent: SubViewRenderer,
6464
renderTitleComponent: SubViewRenderer,
65+
statusBarHeight: number | Animated.Value,
6566
};
6667

6768
type Props = NavigationSceneRendererProps & {
@@ -71,6 +72,7 @@ type Props = NavigationSceneRendererProps & {
7172
renderTitleComponent: SubViewRenderer,
7273
style?: any,
7374
viewProps?: any,
75+
statusBarHeight: number | Animated.Value,
7476
};
7577

7678
type SubViewName = 'left' | 'title' | 'right';
@@ -103,6 +105,8 @@ class NavigationHeader extends React.Component<DefaultProps, Props, any> {
103105
renderRightComponent: (props: SubViewProps) => {
104106
return null;
105107
},
108+
109+
statusBarHeight: STATUSBAR_HEIGHT,
106110
};
107111

108112
static propTypes = {
@@ -112,6 +116,7 @@ class NavigationHeader extends React.Component<DefaultProps, Props, any> {
112116
renderRightComponent: PropTypes.func,
113117
renderTitleComponent: PropTypes.func,
114118
style: View.propTypes.style,
119+
statusBarHeight: PropTypes.number,
115120
viewProps: PropTypes.shape(View.propTypes),
116121
};
117122

@@ -132,12 +137,22 @@ class NavigationHeader extends React.Component<DefaultProps, Props, any> {
132137
return props;
133138
});
134139

140+
const barHeight = (this.props.statusBarHeight instanceof Animated.Value)
141+
? Animated.add(this.props.statusBarHeight, new Animated.Value(APPBAR_HEIGHT))
142+
: APPBAR_HEIGHT + this.props.statusBarHeight;
143+
135144
return (
136-
<View style={[ styles.appbar, style ]} {...viewProps}>
145+
<Animated.View style={[
146+
styles.appbar,
147+
{ height: barHeight },
148+
style
149+
]}
150+
{...viewProps}
151+
>
137152
{scenesProps.map(this._renderLeft, this)}
138153
{scenesProps.map(this._renderTitle, this)}
139154
{scenesProps.map(this._renderRight, this)}
140-
</View>
155+
</Animated.View>
141156
);
142157
}
143158

@@ -206,6 +221,7 @@ class NavigationHeader extends React.Component<DefaultProps, Props, any> {
206221
key={name + '_' + key}
207222
style={[
208223
styles[name],
224+
{ marginTop: this.props.statusBarHeight },
209225
styleInterpolator(props),
210226
]}>
211227
{subView}
@@ -227,7 +243,6 @@ const styles = StyleSheet.create({
227243
borderBottomWidth: Platform.OS === 'ios' ? StyleSheet.hairlineWidth : 0,
228244
elevation: 4,
229245
flexDirection: 'row',
230-
height: APPBAR_HEIGHT + STATUSBAR_HEIGHT,
231246
justifyContent: 'flex-start',
232247
left: 0,
233248
marginBottom: 16, // This is needed for elevation shadow
@@ -239,7 +254,6 @@ const styles = StyleSheet.create({
239254
title: {
240255
bottom: 0,
241256
left: APPBAR_HEIGHT,
242-
marginTop: STATUSBAR_HEIGHT,
243257
position: 'absolute',
244258
right: APPBAR_HEIGHT,
245259
top: 0,
@@ -248,14 +262,12 @@ const styles = StyleSheet.create({
248262
left: {
249263
bottom: 0,
250264
left: 0,
251-
marginTop: STATUSBAR_HEIGHT,
252265
position: 'absolute',
253266
top: 0,
254267
},
255268

256269
right: {
257270
bottom: 0,
258-
marginTop: STATUSBAR_HEIGHT,
259271
position: 'absolute',
260272
right: 0,
261273
top: 0,

0 commit comments

Comments
 (0)