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

Commit

Permalink
Fix back button title fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed May 24, 2019
1 parent 4f64830 commit 58901b2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/components/Header/HeaderBackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Props = {
};

type State = {
titleWidth?: number;
initialTitleWidth?: number;
};

class HeaderBackButton extends React.Component<Props, State> {
Expand All @@ -49,8 +49,12 @@ class HeaderBackButton extends React.Component<Props, State> {

onTitleLayout && onTitleLayout(e);

if (this.state.initialTitleWidth) {
return;
}

this.setState({
titleWidth: e.nativeEvent.layout.x + e.nativeEvent.layout.width,
initialTitleWidth: e.nativeEvent.layout.x + e.nativeEvent.layout.width,
});
};

Expand Down Expand Up @@ -79,11 +83,15 @@ class HeaderBackButton extends React.Component<Props, State> {
private getTitleText = () => {
const { layout, title, fallbackTitle } = this.props;

let { titleWidth } = this.state;
let { initialTitleWidth } = this.state;

if (!title) {
return fallbackTitle;
} else if (titleWidth && layout && titleWidth > layout.width / 3) {
} else if (
initialTitleWidth &&
layout &&
initialTitleWidth > layout.width / 4
) {
return fallbackTitle;
} else {
return title;
Expand Down

0 comments on commit 58901b2

Please sign in to comment.