Skip to content
This repository has been archived by the owner on Feb 15, 2019. It is now read-only.

Commit

Permalink
Sync changes from expo monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne committed Dec 19, 2017
2 parents 98b1c01 + f787f89 commit 47ab675
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expo/ex-navigation",
"version": "3.1.0",
"version": "4.1.0",
"description": "Route-centric navigation library for React Native.",
"main": "./src/ExNavigation.js",
"files": [
Expand Down
39 changes: 25 additions & 14 deletions src/ExNavigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import PureComponent from './utils/PureComponent';
import { unsupportedNativeView } from './ExUnsupportedNativeView';
import { withNavigation } from './ExNavigationComponents';

import isIPhoneX from './utils/isIPhoneX';

let BlurView;
let expoModule = global.__exponent || global.__expo;
if (expoModule) {
Expand All @@ -27,18 +29,19 @@ if (expoModule) {
// Exponent draws under the status bar on Android, but vanilla React Native does not.
// So we need to factor the status bar height in with Exponent but can ignore it with
// vanilla React Native
const STATUSBAR_HEIGHT = Platform.OS === 'ios'
? 20
: global.__exponent ? 24 : 0;
const STATUSBAR_HEIGHT =
Platform.OS === 'ios' ? 20 : global.__exponent ? 24 : 0;

const APPBAR_HEIGHT = Platform.OS === 'ios' ? 44 : 55;
const BACKGROUND_COLOR = Platform.OS === 'ios' ? '#EFEFF2' : '#FFF';
const BORDER_BOTTOM_COLOR = 'rgba(0, 0, 0, .15)';
const BORDER_BOTTOM_WIDTH = Platform.OS === 'ios'
? StyleSheet.hairlineWidth
: 0;
const BORDER_BOTTOM_WIDTH =
Platform.OS === 'ios' ? StyleSheet.hairlineWidth : 0;
const BACK_BUTTON_HIT_SLOP = { top: 0, bottom: 0, left: 0, right: 30 };

const IPHONE_X_EXTRA_HEIGHT = isIPhoneX ? 20 : 0;
const IPHONE_X_TOP_OFFSET = isIPhoneX ? 30 : 0;

class ExNavigationBarTitle extends PureComponent {
render() {
const { children, style, textStyle, tintColor } = this.props;
Expand Down Expand Up @@ -85,7 +88,8 @@ const titleStyles = StyleSheet.create({
},
});

@withNavigation class ExNavigationBarBackButton extends PureComponent {
@withNavigation
class ExNavigationBarBackButton extends PureComponent {
render() {
const { tintColor } = this.props;

Expand Down Expand Up @@ -168,7 +172,11 @@ export default class ExNavigationBar extends PureComponent {
renderTitleComponent(props) {
const { navigationState } = props;
const title = String(navigationState.title || '');
return <ExNavigationBarTitle>{title}</ExNavigationBarTitle>;
return (
<ExNavigationBarTitle>
{title}
</ExNavigationBarTitle>
);
},
barHeight: APPBAR_HEIGHT,
statusBarHeight: STATUSBAR_HEIGHT,
Expand Down Expand Up @@ -201,8 +209,8 @@ export default class ExNavigationBar extends PureComponent {

if (this.props.navigationState.index !== nextProps.navigationState.index) {
this.setState({
delta: nextProps.navigationState.index -
this.props.navigationState.index,
delta:
nextProps.navigationState.index - this.props.navigationState.index,
});
} else {
this.setState({
Expand All @@ -229,7 +237,8 @@ export default class ExNavigationBar extends PureComponent {
});

// TODO: this should come from the latest scene config
const height = this.props.barHeight + this.props.statusBarHeight;
const height =
this.props.barHeight + this.props.statusBarHeight + IPHONE_X_EXTRA_HEIGHT;

let styleFromRouteConfig = this.props.latestRoute.getBarStyle();
let isTranslucent = !!this.props.latestRoute.getTranslucent();
Expand Down Expand Up @@ -284,7 +293,7 @@ export default class ExNavigationBar extends PureComponent {
<View
style={[
styles.appbarInnerContainer,
{ top: this.props.statusBarHeight },
{ top: this.props.statusBarHeight + IPHONE_X_EXTRA_HEIGHT },
]}>
{titleComponents}
{leftComponents}
Expand Down Expand Up @@ -386,8 +395,10 @@ export default class ExNavigationBar extends PureComponent {
}
}

ExNavigationBar.DEFAULT_HEIGHT = APPBAR_HEIGHT + STATUSBAR_HEIGHT;
ExNavigationBar.DEFAULT_HEIGHT_WITHOUT_STATUS_BAR = APPBAR_HEIGHT;
ExNavigationBar.DEFAULT_HEIGHT =
APPBAR_HEIGHT + STATUSBAR_HEIGHT + IPHONE_X_EXTRA_HEIGHT;
ExNavigationBar.DEFAULT_HEIGHT_WITHOUT_STATUS_BAR =
APPBAR_HEIGHT + IPHONE_X_EXTRA_HEIGHT;
ExNavigationBar.DEFAULT_BACKGROUND_COLOR = BACKGROUND_COLOR;
ExNavigationBar.DEFAULT_BORDER_BOTTOM_COLOR = BORDER_BOTTOM_COLOR;
ExNavigationBar.DEFAULT_BORDER_BOTTOM_WIDTH = BORDER_BOTTOM_WIDTH;
Expand Down
19 changes: 15 additions & 4 deletions src/tab/ExNavigationTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ import ExNavigatorContext from '../ExNavigatorContext';
import ExNavigationTabBar from './ExNavigationTabBar';
import ExNavigationTabItem from './ExNavigationTabItem';
import { createNavigatorComponent } from '../ExNavigationComponents';
import isIPhoneX from '../utils/isIPhoneX';

import type ExNavigationContext from '../ExNavigationContext';

const IPHONE_X_EXTRA_HEIGHT = isIPhoneX ? 38 : 0;
const IPHONE_X_BOTTOM_OFFSET = isIPhoneX ? 28 : 0;

export class ExNavigationTabContext extends ExNavigatorContext {
type = 'tab';

Expand Down Expand Up @@ -94,7 +98,13 @@ class ExNavigationTab extends PureComponent<any, Props, State> {

static defaultProps = {
renderTabBar(props) {
return <ExNavigationTabBar {...props} />;
return (
<ExNavigationTabBar
{...props}
extraHeight={IPHONE_X_EXTRA_HEIGHT}
bottomOffset={IPHONE_X_BOTTOM_OFFSET}
/>
);
},
};

Expand Down Expand Up @@ -153,8 +163,9 @@ class ExNavigationTab extends PureComponent<any, Props, State> {
const tabBar = this.props.renderTabBar(tabBarProps);
const TabBarComponent = tabBar.type;
// Get the tab bar's height from a static property on the class
const tabBarHeight =
this.props.tabBarHeight || TabBarComponent.defaultHeight || 0;
let tabBarHeight =
(this.props.tabBarHeight || TabBarComponent.defaultHeight || 0) +
IPHONE_X_EXTRA_HEIGHT;
const isTranslucent = this.props.translucent;

return (
Expand Down Expand Up @@ -302,7 +313,7 @@ class ExNavigationTab extends PureComponent<any, Props, State> {
let defaultRouteConfig = child.props.defaultRouteConfig || {};
defaultRouteConfig = {
...defaultRouteConfig,
__tabBarInset: this.props.tabBarHeight,
__tabBarInset: this.props.tabBarHeight + IPHONE_X_EXTRA_HEIGHT,
};
tabItem.element = cloneReferencedElement(child, {
...child.props,
Expand Down
19 changes: 15 additions & 4 deletions src/tab/ExNavigationTabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ export default class ExNavigationTabBar extends React.Component {
static defaultHeight = DEFAULT_TAB_BAR_HEIGHT;

render() {
const height = this.props.height || DEFAULT_TAB_BAR_HEIGHT;
const height =
(this.props.height || DEFAULT_TAB_BAR_HEIGHT) +
(this.props.extraHeight || 0);
let isTranslucent = this.props.translucent;
let backgroundColor = isTranslucent ? 'rgba(255,255,255,0.5)' : '#fefefe';
let paddingBottom = this.props.bottomOffset || 0;

return (
<View style={[styles.container, { height }]}>
Expand All @@ -40,7 +43,7 @@ export default class ExNavigationTabBar extends React.Component {
<View
style={[
styles.innerContainer,
{ backgroundColor },
{ backgroundColor, paddingBottom },
this.props.style,
]}>
<View style={styles.itemContainer}>
Expand All @@ -65,7 +68,11 @@ export default class ExNavigationTabBar extends React.Component {
if (renderTitle) {
title = renderTitle(isSelected, item.title, index);
} else {
title = <Text>{item.title}</Text>;
title = (
<Text>
{item.title}
</Text>
);
}
}

Expand All @@ -78,7 +85,11 @@ export default class ExNavigationTabBar extends React.Component {
if (renderBadge) {
badge = renderBadge(isSelected, item.title, index);
} else if (badgeText) {
badge = <TabBadge style={styles.badge}>{badgeText}</TabBadge>;
badge = (
<TabBadge style={styles.badge}>
{badgeText}
</TabBadge>
);
}

if (item.showsTouches) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/isIPhoneX.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Platform, Dimensions } from 'react-native';
const { width, height } = Dimensions.get('window');
const isIPhoneX = Platform.OS === 'ios' && width === 375 && height === 812;
export default isIPhoneX;

0 comments on commit 47ab675

Please sign in to comment.