mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-12 22:30:36 +08:00
Get truncated back button title from the previous scene (#1167)
This commit is contained in:
17
packages/react-navigation/src/views/Header.js
vendored
17
packages/react-navigation/src/views/Header.js
vendored
@@ -59,8 +59,12 @@ class Header extends React.PureComponent<void, HeaderProps, HeaderState> {
|
||||
return sceneOptions.title;
|
||||
}
|
||||
|
||||
_getLastScene(scene: NavigationScene): ?NavigationScene {
|
||||
return this.props.scenes.find(s => s.index === scene.index - 1);
|
||||
}
|
||||
|
||||
_getBackButtonTitleString(scene: NavigationScene): ?string {
|
||||
const lastScene = this.props.scenes.find(s => s.index === scene.index - 1);
|
||||
const lastScene = this._getLastScene(scene);
|
||||
if (!lastScene) {
|
||||
return null;
|
||||
}
|
||||
@@ -71,6 +75,14 @@ class Header extends React.PureComponent<void, HeaderProps, HeaderState> {
|
||||
return this._getHeaderTitleString(lastScene);
|
||||
}
|
||||
|
||||
_getTruncatedBackButtonTitle(scene: NavigationScene): ?string {
|
||||
const lastScene = this._getLastScene(scene);
|
||||
if (!lastScene) {
|
||||
return null;
|
||||
}
|
||||
return this.props.getScreenDetails(lastScene).options.headerTruncatedBackTitle;
|
||||
}
|
||||
|
||||
_renderTitleComponent = (props: SceneProps) => {
|
||||
const details = this.props.getScreenDetails(props.scene);
|
||||
const headerTitle = details.options.headerTitle;
|
||||
@@ -114,6 +126,7 @@ class Header extends React.PureComponent<void, HeaderProps, HeaderState> {
|
||||
return null;
|
||||
}
|
||||
const backButtonTitle = this._getBackButtonTitleString(props.scene);
|
||||
const truncatedBackButtonTitle = this._getTruncatedBackButtonTitle(props.scene);
|
||||
const width = this.state.widths[props.scene.key]
|
||||
? (this.props.layout.initWidth - this.state.widths[props.scene.key]) / 2
|
||||
: undefined;
|
||||
@@ -123,7 +136,7 @@ class Header extends React.PureComponent<void, HeaderProps, HeaderState> {
|
||||
pressColorAndroid={options.headerPressColorAndroid}
|
||||
tintColor={options.headerTintColor}
|
||||
title={backButtonTitle}
|
||||
truncatedTitle={options.headerTruncatedBackTitle}
|
||||
truncatedTitle={truncatedBackButtonTitle}
|
||||
width={width}
|
||||
/>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user