使用BottomNavigation(而非TabView)崩溃的选项卡导航

问题描述 投票:0回答:2

我正在尝试使用BottomNavigation而不是TabView制作标签式导航应用程序。我基于支持嵌套页面路由器插座的this example。我能够使它工作,但我遇到的一个问题是当我恢复应用程序时,崩溃,seen here。我假设这是因为我正在使用的页面路由器插座是脏的。

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to resume activity {org.nativescript.nestedroutertabview/com.tns.NativeScriptActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3822)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3854)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:5034)
at android.view.ViewGroup.addView(ViewGroup.java:4865)
at android.view.ViewGroup.addView(ViewGroup.java:4805)
at android.view.ViewGroup.addView(ViewGroup.java:4778)

我会解释我改变的事情。

在app-routing.module中:我删除了行{ path: "", redirectTo: "/login", pathMatch: "full" },,因为想要应用程序在标签页而不是登录页面上启动。除了在app.component中添加this.routerExtension.navigate(["/tabs/default"], { clearHistory: true });之外,我无法找到一个好方法。

在tabs.component.html中,这是我的page-router-outlet设置:

<GridLayout rows="*, auto">
    <page-router-outlet name="playerTab" actionBarVisibility="never" visibility="{{  (selectedTab == 0) ? 'visible' : 'collapsed' }}"></page-router-outlet>
    <page-router-outlet name="teamTab" actionBarVisibility="never" visibility="{{  (selectedTab == 1) ? 'visible' : 'collapsed' }}"></page-router-outlet>

    <StackLayout row="1" verticalAlignment="bottom">
        <BottomNavigation id="bottomNavigation" activeColor="#00C99D" [tabs]="tabs" titleVisibility="never" (tabSelected)="onBottomNavigationTabSelected($event)"></BottomNavigation>
    </StackLayout>
</GridLayout>

我只是隐藏未使用的插座并显示当前标签。我所做的一切对我来说都不是很干净。

这是我项目的链接:https://github.com/keerl/login-bottom-navigation-ng

任何帮助表示赞赏。

angular nativescript angular2-nativescript nativescript-angular
2个回答
1
投票

我暂时找到了解决方案。如果我在visibility属性上使用'hidden'属性而不是'collapsed',它就不会再崩溃了。我仍然认为这不是正确的做法,所以如果有人有任何想法,我们将不胜感激。


0
投票

感谢您使用我的插件:D我认为问题在于您正在使用visibility属性。我建议你改用ngSwitch。在主GridLayout中设置NgSwitch,然后将每个page-router-outlet包装在StackLayout中,您可以在其中设置NgCase以根据所选选项卡显示页面路由器插座。

我希望这会有所帮助:D

© www.soinside.com 2019 - 2024. All rights reserved.