From 87765564f6f2ac5877010e640107281a3ae44f36 Mon Sep 17 00:00:00 2001 From: Ely Lucas Date: Sun, 13 Oct 2019 15:20:39 -0600 Subject: [PATCH] fix(react): handle tab back nav better, fixes #19646 (#19647) --- .../src/components/navigation/IonTabBar.tsx | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/react/src/components/navigation/IonTabBar.tsx b/packages/react/src/components/navigation/IonTabBar.tsx index 18f4bfa2656..79e8fbf178f 100644 --- a/packages/react/src/components/navigation/IonTabBar.tsx +++ b/packages/react/src/components/navigation/IonTabBar.tsx @@ -6,7 +6,6 @@ import { IonTabBarInner } from '../inner-proxies'; import { IonTabButton } from '../proxies'; type Props = LocalJSX.IonTabBar & { - navigate?: (path: string, direction: 'back' | 'none') => void; currentPath?: string; slot?: 'bottom' | 'top'; }; @@ -22,6 +21,7 @@ interface State { } const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component { + context!: React.ContextType; constructor(props: Props) { super(props); @@ -67,13 +67,15 @@ const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component) => { - const { navigate } = this.props; - if (navigate) { - if (this.state.activeTab === e.detail.tab) { - navigate(this.state.tabs[e.detail.tab].originalHref, 'back'); + if (this.state.activeTab === e.detail.tab) { + const originalHref = this.state.tabs[e.detail.tab].originalHref; + if (this.context.hasIonicRouter()) { + this.context.goBack(originalHref); } else { - navigate(this.state.tabs[e.detail.tab].currentHref, 'none'); + this.context.navigate(originalHref, 'back'); } + } else { + this.context.navigate(this.state.tabs[e.detail.tab].currentHref, 'none'); } } @@ -96,6 +98,10 @@ const IonTabBarUnwrapped = /*@__PURE__*/(() => class extends React.Component ); } + + static get contextType() { + return NavContext; + } })(); export const IonTabBar: React.FC = props => { @@ -103,9 +109,6 @@ export const IonTabBar: React.FC = props => { return ( { - context.navigate(path, direction); - })} currentPath={props.currentPath || context.currentPath} > {props.children}