From 8476931d6cc5cbd63a034369976fdfb1f8e430d8 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Thu, 18 Mar 2021 13:47:46 -0700 Subject: [PATCH] fix(bottom-navigation): android light/dark theme change on device crash (#9270) --- .../bottom-navigation.android.ts | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts b/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts index 6f133e4f9..ca25e1e9b 100644 --- a/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts +++ b/nativescript-core/ui/bottom-navigation/bottom-navigation.android.ts @@ -744,7 +744,12 @@ export class BottomNavigation extends TabNavigationBase { } public updateAndroidItemAt(index: number, spec: org.nativescript.widgets.TabItemSpec) { - this._bottomNavigationBar.updateItemAt(index, spec); + // this can throw when switching light/dark theme mode on device, just ignore + try { + this._bottomNavigationBar.updateItemAt(index, spec); + } catch (err) { + // ignore + } } public getTabBarBackgroundColor(): android.graphics.drawable.Drawable { @@ -825,13 +830,18 @@ export class BottomNavigation extends TabNavigationBase { } private setIconColor(tabStripItem: TabStripItem, color?: Color) { - const tabBarItem = this._bottomNavigationBar.getViewForItemAt(tabStripItem._index); + // this can throw when switching light/dark theme mode on device, just ignore + try { + const tabBarItem = this._bottomNavigationBar.getViewForItemAt(tabStripItem._index); - const drawableInfo = this.getIconInfo(tabStripItem, color); - const imgView = tabBarItem.getChildAt(0); - imgView.setImageDrawable(drawableInfo.drawable); - if (color) { - imgView.setColorFilter(color.android); + const drawableInfo = this.getIconInfo(tabStripItem, color); + const imgView = tabBarItem.getChildAt(0); + imgView.setImageDrawable(drawableInfo.drawable); + if (color) { + imgView.setColorFilter(color.android); + } + } catch (err) { + // ignore } }