简体   繁体   English

嵌套的nativescript tabview操作栏

[英]nativescript tabview actionbar nested

I have 4 tabs and I'm using router-outlet for the "navigation" within each tab. 我有4个标签,每个标签内的“导航”使用的是路由器插座。 I wanted to ask you if you can create different actionbar for each tab and if you can navigate within the tabs also changing the title and the items of the actionbar 我想问你是否可以为每个选项卡创建不同的操作栏,以及是否可以在这些选项卡中导航,还更改了操作栏的标题和项目

您不能为每个标签保留单独的操作栏,但可以在标签之间进行切换时尝试更新操作栏。

I solved by creating for each component of the four tab an actionbar and navigating in the desired tab according to the tab selected, example: 通过为四个选项卡的每个组件创建一个动作栏并根据所选的选项卡导航到所需的选项卡,我解决了这个问题,例如:

public onIndexChanged(args) {
    let tabView = <TabView>args.object;
    if(tabView.selectedIndex == 0){
        this.title = this.test;
        this.routerExtensions.navigate(['tabs',
            {
                outlets: {'test': ['test'],
            }
        }], { 
            clearHistory: true 
         });
    }
    else if(tabView.selectedIndex == 1){
        this.title = this.test1;
        this.routerExtensions.navigate(['tabs',
            {
                outlets: {'test1': ['test1'],
            }
        }], { clearHistory: true });
    }
    else if(tabView.selectedIndex == 2){
        this.title = this.test2;
        this.routerExtensions.navigate(['tabs',
            {
                outlets: {'test2': ['test2'],
            }
        }], { clearHistory: true });
    }
    else if(tabView.selectedIndex == 3){
        this.title = this.notifications;
        this.routerExtensions.navigate(['tabs',
            {
                outlets: {'test3': ['test3'],
            }
        }], { clearHistory: true });
    }
    else if(tabView.selectedIndex == 4){
        this.title = this.settings;
        this.routerExtensions.navigate(['tabs',
            {
                outlets: {'test4': ['test4'],
            }
        }], { clearHistory: true });
    }
}

Then in each tab I have other views with other actionbars. 然后在每个选项卡中,我还有其他带有其他操作栏的视图。 When changing tab the history is canceled so if I go back to a previously opened tab, it is recreated and then the actionbar is updated again. 更改选项卡时,历史记录被取消,因此,如果我返回以前打开的选项卡,则会重新创建它,然后再次更新操作栏。

The only problem I found (I think it's a bug) is that (on android) the deletion of the history for router-outlet does not work. 我发现的唯一问题(我认为是个错误)是(在android上)删除路由器出口的历史记录不起作用。

EDIT 编辑

I had to pass a random parameter to allow the component that I am leaving to call the OnDestroy method so that when I return to the tab I left it, it recreates everything including the actionbar 我必须传递一个随机参数,以允许要离开的组件调用OnDestroy方法,以便当我返回到选项卡时,它会重新创建包括操作栏在内的所有内容

this.routerExtensions.navigate(['tabs',
        {
          parameterForOnDestroy: true
        },
        {
            outlets: {'test': ['test'],
        }
    }], { 
        clearHistory: true 
     });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM