Skip to content

Commit 043c650

Browse files
committed
add onselectedIndexChanged to trigger changes when tab selected.
1 parent 3fac314 commit 043c650

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

demo-ng/src/app.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
@import '@nativescript/theme/css/core.css';
22
@import '@nativescript/theme/css/default.css';
3+
4+
MDTabStrip {
5+
selected-item-color: #FFFFFF;
6+
un-selected-item-color: #404040;
7+
highlight-color: #4CFFFF;
8+
}

demo-ng/src/app/examples/tabs/tabs.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<MDTabs selectedIndex="1">
22
<!-- The bottom tab UI is created via MDTabStrip (the containier) and MDTabStripItem (for each tab)-->
3-
<MDTabStrip>
3+
<MDTabStrip >
44
<MDTabStripItem>
55
<Label text="Home"></Label>
66
<Image src="res://ic_home"></Image>

src/tabs/tabs.android.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ function getTabById(id: number): Tabs {
3737

3838
return ref && ref.get();
3939
}
40+
interface PositionChanger {
41+
onSelectedPositionChange(position: number, prevPosition: number);
42+
}
4043

4144
function initializeNativeClasses() {
4245
if (PagerAdapter) {
@@ -282,7 +285,7 @@ function initializeNativeClasses() {
282285
}
283286

284287
@NativeClass
285-
class TabsBarImplementation extends com.nativescript.material.core.TabsBar {
288+
class TabsBarImplementation extends com.nativescript.material.core.TabsBar implements PositionChanger {
286289
constructor(context: android.content.Context, public owner: Tabs) {
287290
super(context);
288291

@@ -477,6 +480,11 @@ export class Tabs extends TabsBase {
477480

478481
return nativeView;
479482
}
483+
onSelectedIndexChanged(oldIndex: number, newIndex:number) {
484+
const tabBarImplementation = (this._tabsBar as unknown ) as PositionChanger;
485+
tabBarImplementation.onSelectedPositionChange(oldIndex, newIndex);
486+
super.onSelectedIndexChanged(oldIndex, newIndex);
487+
}
480488

481489
public initNativeView(): void {
482490
super.initNativeView();

0 commit comments

Comments
 (0)