Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit a134c55

Browse files
committed
Fix usage of status bar height
1 parent 123dbcd commit a134c55

File tree

2 files changed

+83
-70
lines changed

2 files changed

+83
-70
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-navigation-addon-search-layout",
3-
"version": "0.13.0",
3+
"version": "0.13.1",
44
"main": "index.js",
55
"license": "MIT",
66
"types": "react-navigation-search-layout.d.ts",

src/Header.js

Lines changed: 82 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,95 @@
11
import React from 'react';
2-
import { Animated, Dimensions, Platform, StatusBar, StyleSheet, View } from 'react-native';
2+
import {
3+
Animated,
4+
Dimensions,
5+
Platform,
6+
StatusBar,
7+
StyleSheet,
8+
View,
9+
} from 'react-native';
310
import { withNavigation, HeaderBackButton } from 'react-navigation';
4-
import { getStatusBarHeight } from 'react-native-safe-area-view';
5-
import { isIphoneX } from 'react-native-iphone-x-helper'
11+
import { getInset, getStatusBarHeight } from 'react-native-safe-area-view';
12+
import { isIphoneX } from 'react-native-iphone-x-helper';
613

714
// @todo: make this work properly when in landscape
815
const hasNotch = isIphoneX();
916

1017
const APPBAR_HEIGHT = Platform.OS === 'ios' ? 50 : 56;
1118
const TITLE_OFFSET = Platform.OS === 'ios' ? 70 : 56;
1219

13-
// @todo: this is static and we don't know if it's visible or not on iOS.
14-
// need to use a more reliable and cross-platform API when one exists, like
15-
// LayoutContext. We also don't know if it's translucent or not on Android
16-
// and depend on react-native-safe-area-view to tell us.
17-
const ANDROID_STATUS_BAR_HEIGHT = getStatusBarHeight ? getStatusBarHeight() : StatusBar.currentHeight;
18-
const STATUSBAR_HEIGHT = Platform.OS === 'ios' ? (hasNotch ? 40 : 25) : ANDROID_STATUS_BAR_HEIGHT;
19-
2020
@withNavigation
2121
export default class Header extends React.PureComponent {
22-
static HEIGHT = APPBAR_HEIGHT + STATUSBAR_HEIGHT;
22+
constructor(props) {
23+
super(props);
24+
25+
// @todo: this is static and we don't know if it's visible or not on iOS.
26+
// need to use a more reliable and cross-platform API when one exists, like
27+
// LayoutContext. We also don't know if it's translucent or not on Android
28+
// and depend on react-native-safe-area-view to tell us.
29+
const ANDROID_STATUS_BAR_HEIGHT = getStatusBarHeight
30+
? getStatusBarHeight()
31+
: StatusBar.currentHeight;
32+
const STATUSBAR_HEIGHT =
33+
Platform.OS === 'ios' ? (hasNotch ? 40 : 25) : ANDROID_STATUS_BAR_HEIGHT;
34+
35+
let platformContainerStyles;
36+
if (Platform.OS === 'ios') {
37+
platformContainerStyles = {
38+
borderBottomWidth: StyleSheet.hairlineWidth,
39+
borderBottomColor: '#A7A7AA',
40+
};
41+
} else {
42+
platformContainerStyles = {
43+
shadowColor: 'black',
44+
shadowOpacity: 0.1,
45+
shadowRadius: StyleSheet.hairlineWidth,
46+
shadowOffset: {
47+
height: StyleSheet.hairlineWidth,
48+
},
49+
elevation: 4,
50+
};
51+
}
52+
53+
this.styles = {
54+
container: {
55+
backgroundColor: '#fff',
56+
paddingTop: STATUSBAR_HEIGHT,
57+
height: STATUSBAR_HEIGHT + APPBAR_HEIGHT,
58+
...platformContainerStyles,
59+
},
60+
appBar: {
61+
flex: 1,
62+
},
63+
header: {
64+
flexDirection: 'row',
65+
},
66+
item: {
67+
justifyContent: 'center',
68+
alignItems: 'center',
69+
backgroundColor: 'transparent',
70+
},
71+
title: {
72+
bottom: 0,
73+
left: TITLE_OFFSET,
74+
right: TITLE_OFFSET,
75+
top: 0,
76+
position: 'absolute',
77+
alignItems: Platform.OS === 'ios' ? 'center' : 'flex-start',
78+
},
79+
left: {
80+
left: 0,
81+
bottom: 0,
82+
top: 0,
83+
position: 'absolute',
84+
},
85+
right: {
86+
right: 0,
87+
bottom: 0,
88+
top: 0,
89+
position: 'absolute',
90+
},
91+
};
92+
}
2393

2494
_navigateBack = () => {
2595
this.props.navigation.goBack(null);
@@ -43,6 +113,7 @@ export default class Header extends React.PureComponent {
43113
};
44114

45115
render() {
116+
let { styles } = this;
46117
let headerStyle = {};
47118
if (this.props.backgroundColor) {
48119
headerStyle.backgroundColor = this.props.backgroundColor;
@@ -60,61 +131,3 @@ export default class Header extends React.PureComponent {
60131
);
61132
}
62133
}
63-
64-
let platformContainerStyles;
65-
if (Platform.OS === 'ios') {
66-
platformContainerStyles = {
67-
borderBottomWidth: StyleSheet.hairlineWidth,
68-
borderBottomColor: '#A7A7AA',
69-
};
70-
} else {
71-
platformContainerStyles = {
72-
shadowColor: 'black',
73-
shadowOpacity: 0.1,
74-
shadowRadius: StyleSheet.hairlineWidth,
75-
shadowOffset: {
76-
height: StyleSheet.hairlineWidth,
77-
},
78-
elevation: 4,
79-
};
80-
}
81-
82-
const styles = StyleSheet.create({
83-
container: {
84-
backgroundColor: '#fff',
85-
paddingTop: STATUSBAR_HEIGHT,
86-
height: STATUSBAR_HEIGHT + APPBAR_HEIGHT,
87-
...platformContainerStyles,
88-
},
89-
appBar: {
90-
flex: 1,
91-
},
92-
header: {
93-
flexDirection: 'row',
94-
},
95-
item: {
96-
justifyContent: 'center',
97-
alignItems: 'center',
98-
backgroundColor: 'transparent',
99-
},
100-
title: {
101-
bottom: 0,
102-
left: TITLE_OFFSET,
103-
right: TITLE_OFFSET,
104-
top: 0,
105-
position: 'absolute',
106-
alignItems: Platform.OS === 'ios' ? 'center' : 'flex-start',
107-
},
108-
left: {
109-
left: 0,
110-
bottom: 0,
111-
top: 0,
112-
position: 'absolute',
113-
},
114-
right: {
115-
right: 0,
116-
bottom: 0,
117-
top: 0,
118-
position: 'absolute',
119-
},
120-
});

0 commit comments

Comments
 (0)