mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-24 09:08:15 +00:00
Handle translucent status bar within Expo automatically.
- Escape hatch of `ReactNavigation.SafeAreaView.setStatusBarHeight()`. - `if (Platform.OS === 'android') { ReactNavigation.SafeAreaView.setStatusBarHeight(0) }` to revert to old behavior.
This commit is contained in:
parent
6ac3bb90ed
commit
7fa0ef3aee
@ -52,7 +52,26 @@ const isIPad = (() => {
|
||||
return true;
|
||||
})();
|
||||
|
||||
let _customStatusBarHeight = null;
|
||||
const statusBarHeight = isLandscape => {
|
||||
if (_customStatusBarHeight !== null) {
|
||||
return _customStatusBarHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a temporary workaround because we don't have a way to detect
|
||||
* if the status bar is translucent or opaque. If opaque, we don't need to
|
||||
* factor in the height here; if translucent (content renders under it) then
|
||||
* we do.
|
||||
*/
|
||||
if (Platform.OS === 'android') {
|
||||
if (global.Expo) {
|
||||
return global.Expo.Constants.statusBarHeight;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (isIPhoneX) {
|
||||
return isLandscape ? 0 : 44;
|
||||
}
|
||||
@ -77,6 +96,10 @@ const doubleFromPercentString = percent => {
|
||||
};
|
||||
|
||||
class SafeView extends Component {
|
||||
static setStatusBarHeight = height => {
|
||||
_customStatusBarHeight = height;
|
||||
};
|
||||
|
||||
state = {
|
||||
touchesTop: true,
|
||||
touchesBottom: true,
|
||||
@ -100,10 +123,6 @@ class SafeView extends Component {
|
||||
render() {
|
||||
const { forceInset = false, isLandscape, children, style } = this.props;
|
||||
|
||||
if (Platform.OS !== 'ios') {
|
||||
return <Animated.View style={style}>{this.props.children}</Animated.View>;
|
||||
}
|
||||
|
||||
const safeAreaStyle = this._getSafeAreaStyle();
|
||||
|
||||
return (
|
||||
|
@ -4,6 +4,7 @@ import * as React from 'react';
|
||||
import { Animated, StyleSheet } from 'react-native';
|
||||
import { TabBar } from 'react-native-tab-view';
|
||||
import TabBarIcon from './TabBarIcon';
|
||||
import SafeAreaView from '../SafeAreaView';
|
||||
|
||||
import type {
|
||||
NavigationAction,
|
||||
@ -24,6 +25,7 @@ type Props = {
|
||||
upperCaseLabel: boolean,
|
||||
allowFontScaling: boolean,
|
||||
position: Animated.Value,
|
||||
tabBarPosition: string,
|
||||
navigation: NavigationScreenProp<NavigationState>,
|
||||
jumpToIndex: (index: number) => void,
|
||||
getLabel: (scene: TabScene) => ?(React.Node | string),
|
||||
@ -53,6 +55,7 @@ export default class TabBarTop extends React.PureComponent<Props> {
|
||||
_renderLabel = (scene: TabScene) => {
|
||||
const {
|
||||
position,
|
||||
tabBarPosition,
|
||||
navigation,
|
||||
activeTintColor,
|
||||
inactiveTintColor,
|
||||
@ -81,12 +84,16 @@ export default class TabBarTop extends React.PureComponent<Props> {
|
||||
const label = this.props.getLabel({ ...scene, tintColor });
|
||||
if (typeof label === 'string') {
|
||||
return (
|
||||
<Animated.Text
|
||||
style={[styles.label, { color }, labelStyle]}
|
||||
allowFontScaling={allowFontScaling}
|
||||
<SafeAreaView
|
||||
forceInset={{ top: tabBarPosition === 'top' ? 'always' : 'never' }}
|
||||
>
|
||||
{upperCaseLabel ? label.toUpperCase() : label}
|
||||
</Animated.Text>
|
||||
<Animated.Text
|
||||
style={[styles.label, { color }, labelStyle]}
|
||||
allowFontScaling={allowFontScaling}
|
||||
>
|
||||
{upperCaseLabel ? label.toUpperCase() : label}
|
||||
</Animated.Text>
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
if (typeof label === 'function') {
|
||||
|
@ -145,10 +145,12 @@ class TabView extends React.PureComponent<Props> {
|
||||
if (typeof TabBarComponent === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<TabBarComponent
|
||||
{...props}
|
||||
{...tabBarOptions}
|
||||
tabBarPosition={this.props.tabBarPosition}
|
||||
screenProps={this.props.screenProps}
|
||||
navigation={this.props.navigation}
|
||||
getLabel={this._getLabel}
|
||||
|
Loading…
x
Reference in New Issue
Block a user