henrychavez / nativescript-bottom-navigation

Nativescript plugin for Android & iOS to have the bottom navigation bar of Material Design
Apache License 2.0
58 stars 18 forks source link

How do i change the select default tab when i go to a new component? (Angular) #67

Closed hitmacreed closed 5 years ago

hitmacreed commented 5 years ago

How do i change the select default tab to other tab (ative) when i go to a new component??

---- MY CODE ----

 <BottomNavigation 
            [tabs]="tabs" 
            activeColor="rgba(255, 186, 105, 1)"
            inactiveColor="white" 
            backgroundColor="rgba(133, 94, 196, 1)" 
            (tabSelected)="onBottomNavigationTabSelected($event)"
            (tabPressed)="onBottomNavigationTabPressed($event)"
            row="1">
        </BottomNavigation> 
public tabs: BottomNavigationTab[] = [
    new BottomNavigationTab('Saldos', 'money'),
    new BottomNavigationTab('Movimentos', 'movimentos'),
    new BottomNavigationTab('Usar', 'add'),
    new BottomNavigationTab('Cartões', 'credit'),
    new BottomNavigationTab('Mais', 'more')
  ];
onBottomNavigationTabSelected(args: OnTabSelectedEventData): void { 

   switch (args.newIndex) {
       case 0: 
            console.log(args.newIndex);
             this.routerExtensions.navigate(["balance"],{
                transition: {
                name: "fade"
                },
            });
         // activate this tab here 
        console.log(args.newIndex);
          });

           break;
       case 2: 
            console.log(args.newIndex);
           break;
       case 3: 
             console.log(args.newIndex);
           break;
       default:
        console.log(args.newIndex);
    }
  }
henrychavez commented 5 years ago

Hi @hitmacreed,

I'm not sure I understand your problem when you press a tab it selects automatically then the tabSelected event is emitted and then you can do what you need to do

hitmacreed commented 5 years ago

@henrychavez What i mean is when i move to a nem component lets say it has index 1 , the active tab Stays at index 0 ( the ícon and txt dont Change to a the Next One)

hitmacreed commented 5 years ago

@henrychavez Solved by using ngSwitch Directive