|
1 | 1 | /* @flow */
|
2 | 2 |
|
3 | 3 | 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'; |
5 | 11 | import color from 'color';
|
6 | 12 |
|
7 | 13 | import withTheme from '../../core/withTheme';
|
@@ -34,6 +40,19 @@ type Props = {
|
34 | 40 | };
|
35 | 41 |
|
36 | 42 | 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 | +}); |
37 | 56 |
|
38 | 57 | /**
|
39 | 58 | * Toolbar is usually used as a header placed at the top of the screen.
|
@@ -77,10 +96,7 @@ const DEFAULT_TOOLBAR_HEIGHT = 56;
|
77 | 96 | class Toolbar extends React.Component<Props> {
|
78 | 97 | static defaultProps = {
|
79 | 98 | // 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, |
84 | 100 | };
|
85 | 101 |
|
86 | 102 | render() {
|
@@ -155,12 +171,7 @@ class Toolbar extends React.Component<Props> {
|
155 | 171 | style={[{ backgroundColor }, styles.toolbar, restStyle]}
|
156 | 172 | {...rest}
|
157 | 173 | >
|
158 |
| - <View |
159 |
| - style={[ |
160 |
| - { height: height + statusBarHeight, paddingTop: statusBarHeight }, |
161 |
| - styles.wrapper, |
162 |
| - ]} |
163 |
| - > |
| 174 | + <View style={[{ height, marginTop: statusBarHeight }, styles.wrapper]}> |
164 | 175 | {childrenArray.filter(Boolean).map((child: any, i) => {
|
165 | 176 | const props: { dark: ?boolean, style?: any } = {
|
166 | 177 | dark:
|
|
0 commit comments