From a61de80a354cf9633a4dc8fc6ac2e97f26ffe5f8 Mon Sep 17 00:00:00 2001 From: Martin Yankov Date: Tue, 29 Oct 2019 17:01:05 +0200 Subject: [PATCH] fix(bottom-navigation-android): crash when changing tab and suspending app (#8030) --- .../ui/bottom-navigation/bottom-navigation.android.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts b/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts index ba8f96ff7..077a4096c 100644 --- a/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts +++ b/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts @@ -380,9 +380,7 @@ export class BottomNavigation extends TabNavigationBase { this._bottomNavigationBar.setVisibility(android.view.View.GONE); } - if (this._attachedToWindow) { - this.changeTab(this.selectedIndex); - } + this.changeTab(this.selectedIndex); } _onAttachedToWindow(): void { @@ -467,8 +465,9 @@ export class BottomNavigation extends TabNavigationBase { // TODO: Should we extract adapter-like class? // TODO: Rename this? public changeTab(index: number) { - // this is the case when there are no items - if (index === -1) { + // index is -1 when there are no items + // bot nav is not attached if you change the tab too early + if (index === -1 || !this._attachedToWindow) { return; }