Skip to content

Commit d013c46

Browse files
committed
fix error cannot set tab item selected on loaded
1 parent b4d81bd commit d013c46

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@
9494
"dependencies": {
9595
"ts-node": "^8.10.2"
9696
}
97-
}
97+
}

src/bottomnavigationbar/bottomnavigationbar.ios.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { themer } from '@nativescript-community/ui-material-core';
22
import { Application, Color, Screen, Utils, backgroundColorProperty } from '@nativescript/core';
3-
import { BottomNavigationBarBase, BottomNavigationTabBase, TitleVisibility, activeColorCssProperty, badgeColorCssProperty, badgeTextColorCssProperty, inactiveColorCssProperty, tabsProperty, titleVisibilityProperty } from './bottomnavigationbar-common';
3+
import {
4+
BottomNavigationBarBase,
5+
BottomNavigationTabBase,
6+
TitleVisibility,
7+
activeColorCssProperty,
8+
badgeColorCssProperty,
9+
badgeTextColorCssProperty,
10+
inactiveColorCssProperty,
11+
tabsProperty,
12+
titleVisibilityProperty
13+
} from './bottomnavigationbar-common';
414

515
@NativeClass
616
class BottomNavigationBarDelegate extends NSObject {
@@ -17,21 +27,23 @@ class BottomNavigationBarDelegate extends NSObject {
1727
if (!owner) {
1828
return;
1929
}
20-
if (owner.selectedTabIndex === item.tag) {
21-
owner._emitTabReselected(item.tag);
30+
const tag = item && item.tag ? item.tag : 0;
31+
if (owner.selectedTabIndex === tag) {
32+
owner._emitTabReselected(tag);
2233
return;
2334
}
24-
owner._emitTabSelected(item.tag);
35+
owner._emitTabSelected(tag);
2536
}
2637

2738
bottomNavigationBarShouldSelectItem(bottomNavigationBar: MDCBottomNavigationBar, item: UITabBarItem): boolean {
2839
const owner = this._owner.get();
2940
if (!owner) {
3041
return true;
3142
}
32-
const bottomNavigationTab = owner.items[item.tag];
43+
const tag = item && item.tag ? item.tag : 0;
44+
const bottomNavigationTab = owner.items[tag];
3345
if (!bottomNavigationTab.isSelectable) {
34-
owner._emitTabPressed(item.tag);
46+
owner._emitTabPressed(tag);
3547
}
3648
return bottomNavigationTab.isSelectable;
3749
}
@@ -140,11 +152,9 @@ export class BottomNavigationBar extends BottomNavigationBarBase {
140152
return tab;
141153
});
142154
this.nativeViewProtected.items = new NSArray({ array: bottomNavigationTabs });
143-
let tabsArray = Utils.ios.collections.nsArrayToJSArray(this.nativeViewProtected.items)
144-
145155
// TODO: this is for he v8 runtime. Should not have to need this setTimeout(), find better way.
146156
setTimeout(() => {
147-
this.nativeViewProtected.selectedItem = tabsArray[this.selectedTabIndex];
157+
this.nativeViewProtected.selectedItem = this.nativeViewProtected.items.objectAtIndex(this.selectedTabIndex);
148158
}, 0);
149159
}
150160

0 commit comments

Comments
 (0)