【发布时间】:2019-02-26 13:44:38
【问题描述】:
我正在尝试使用BottomNavigation 而不是 TabView 制作一个选项卡式导航应用程序。我基于支持嵌套页面路由器插座的this example。我能够让它工作,但我遇到的一个问题是当我恢复应用程序时,它崩溃了,seen here。我假设这是因为我对 page-router-outlets 所做的事情很脏。
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