Skip to content

Commit a28d935

Browse files
satya164ferrannp
authored andcommitted
fix: fix statusbar height on old versions of ios (callstack#281)
1 parent 8a5ccde commit a28d935

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/components/Toolbar/Toolbar.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/* @flow */
22

33
import * as React from 'react';
4-
import { View, Platform, StyleSheet, SafeAreaView } from 'react-native';
4+
import {
5+
View,
6+
Platform,
7+
StyleSheet,
8+
StatusBar,
9+
SafeAreaView,
10+
} from 'react-native';
511
import color from 'color';
612

713
import withTheme from '../../core/withTheme';
@@ -34,6 +40,19 @@ type Props = {
3440
};
3541

3642
const DEFAULT_TOOLBAR_HEIGHT = 56;
43+
const DEFAULT_STATUSBAR_HEIGHT_EXPO =
44+
global.__expo && global.__expo.Constants
45+
? global.__expo.Constants.statusBarHeight
46+
: undefined;
47+
const DEFAULT_STATUSBAR_HEIGHT = Platform.select({
48+
android: DEFAULT_STATUSBAR_HEIGHT_EXPO,
49+
ios:
50+
Platform.Version < 11
51+
? DEFAULT_STATUSBAR_HEIGHT_EXPO === undefined
52+
? StatusBar.currentHeight
53+
: DEFAULT_STATUSBAR_HEIGHT_EXPO
54+
: undefined,
55+
});
3756

3857
/**
3958
* Toolbar is usually used as a header placed at the top of the screen.
@@ -77,10 +96,7 @@ const DEFAULT_TOOLBAR_HEIGHT = 56;
7796
class Toolbar extends React.Component<Props> {
7897
static defaultProps = {
7998
// TODO: handle orientation changes
80-
statusBarHeight:
81-
Platform.OS === 'android' && global.__expo && global.__expo.Constants
82-
? global.__expo.Constants.statusBarHeight
83-
: undefined,
99+
statusBarHeight: DEFAULT_STATUSBAR_HEIGHT,
84100
};
85101

86102
render() {
@@ -155,12 +171,7 @@ class Toolbar extends React.Component<Props> {
155171
style={[{ backgroundColor }, styles.toolbar, restStyle]}
156172
{...rest}
157173
>
158-
<View
159-
style={[
160-
{ height: height + statusBarHeight, paddingTop: statusBarHeight },
161-
styles.wrapper,
162-
]}
163-
>
174+
<View style={[{ height, marginTop: statusBarHeight }, styles.wrapper]}>
164175
{childrenArray.filter(Boolean).map((child: any, i) => {
165176
const props: { dark: ?boolean, style?: any } = {
166177
dark:

0 commit comments

Comments
 (0)