fix(bottom-navigation): android light/dark theme change on device crash (#9270)

This commit is contained in:
Nathan Walker
2021-03-18 13:47:46 -07:00
committed by GitHub
parent 17bdd2ad96
commit 8476931d6c

View File

@@ -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 = <android.widget.ImageView>tabBarItem.getChildAt(0);
imgView.setImageDrawable(drawableInfo.drawable);
if (color) {
imgView.setColorFilter(color.android);
const drawableInfo = this.getIconInfo(tabStripItem, color);
const imgView = <android.widget.ImageView>tabBarItem.getChildAt(0);
imgView.setImageDrawable(drawableInfo.drawable);
if (color) {
imgView.setColorFilter(color.android);
}
} catch (err) {
// ignore
}
}