Fix regressions in Header (#1027)

* Fix warnings and errors with Header

* bring back deleted docs

* headerLeft can be null
This commit is contained in:
Mike Grabowski
2017-04-13 22:56:42 +02:00
committed by GitHub
parent 52e24dd380
commit 4c55887990
2 changed files with 17 additions and 15 deletions

View File

@@ -81,16 +81,15 @@ class Header extends React.PureComponent<void, HeaderProps, HeaderState> {
}
_getBackButtonTitleString(scene: NavigationScene): ?string {
const sceneOptions = this.props.getScreenDetails(scene).options;
const {headerBackTitle} = sceneOptions;
const lastScene = scene.index && this.props.scenes.find(s => s.index === scene.index - 1);
if (headerBackTitle || headerBackTitle === null) {
return headerBackTitle;
} else if (lastScene) {
return this._getHeaderTitleString(lastScene);
} else {
const lastScene = this.props.scenes.find(s => s.index === scene.index - 1);
if (!lastScene) {
return null;
}
const { headerBackTitle } = this.props.getScreenDetails(lastScene).options;
if (headerBackTitle || headerBackTitle === null) {
return headerBackTitle;
}
return this._getHeaderTitleString(lastScene);
}
_renderTitleComponent = (props: SceneProps) => {
@@ -128,14 +127,13 @@ class Header extends React.PureComponent<void, HeaderProps, HeaderState> {
};
_renderLeftComponent = (props: SceneProps) => {
const options = this.props.getScreenDetails(props.scene).options;
if (typeof options.headerLeft !== 'undefined') {
return options.headerLeft;
}
if (props.scene.index === 0) {
return null;
}
const details = this.props.getScreenDetails(props.scene);
const {headerLeft, headerPressColorAndroid} = details.options;
if (headerLeft) {
return headerLeft;
}
const backButtonTitle = this._getBackButtonTitleString(props.scene);
const width = this.state.widths[props.scene.key]
? (this.props.layout.initWidth - this.state.widths[props.scene.key]) / 2
@@ -143,8 +141,8 @@ class Header extends React.PureComponent<void, HeaderProps, HeaderState> {
return (
<HeaderBackButton
onPress={() => this.props.navigation.goBack(null)}
pressColorAndroid={headerPressColorAndroid}
tintColor={details.options.headerTintColor}
pressColorAndroid={options.headerPressColorAndroid}
tintColor={options.headerTintColor}
title={backButtonTitle}
width={width}
/>