【问题标题】:Tab navigation using BottomNavigation (not TabView) crashing使用 BottomNavigation(不是 TabView)的选项卡导航崩溃
【发布时间】: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


    【解决方案1】:

    我暂时找到了解决办法。如果我在可见性属性上使用“隐藏”属性而不是“折叠”属性,它就不会再崩溃了。我仍然认为这不是正确的做法,所以如果有人有任何想法,将不胜感激。

    【讨论】:

      【解决方案2】:

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

      我希望这会有所帮助:D

      【讨论】:

      • 我试过了,但网点似乎不再正确呈现,它只是一个空白页面。我暂时找到了一种解决方法,方法是使用“隐藏”而不是“折叠”。
      • 您是否尝试将 ngCase 应用于每个 page-router-outlet directl6?
      猜你喜欢
      • 1970-01-01
      • 2021-07-05
      • 2017-11-10
      • 2020-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      相关资源
      最近更新 更多