Skip to content

Setting the selectedIndex on BottomNavigation property makes the app crash  #7884

Closed

Description

@beeman

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 6.1.2
  • Cross-platform modules: 6.1.1
  • Android Runtime: 6.1.2
  • iOS Runtime: 6.1.0
  • Plugin(s): none

Describe the bug

The app crashes when setting the selectedIndex attribute on the BottomNavigation component. While the change is visible after restarting the app, it keeps crashing on each change making development quite painful.

To Reproduce

  • Create a new app using the tab-navigation-ng template:
tns create --template tns-template-tab-navigation-ng nativescript-bottom-nav-issue
cd nativescript-bottom-nav-issue
tns run android
  • Make sure the app works
  • Open src/app/app.component.html
  • Change the first line to <BottomNavigation selectedIndex="1">
  • Wait till the app refreshes and see the crash 💥

Expected behavior

The app does not crash.

Sample project

https://github.com/beeman/nativescript-bottom-nav-issue

Additional context

Stacktrace ``` System.err: An uncaught Exception occurred on "main" thread. System.err: Calling js method run failed System.err: Error: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. System.err: android.view.ViewGroup.addViewInner(ViewGroup.java:5038) System.err: android.view.ViewGroup.addView(ViewGroup.java:4869) System.err: android.view.ViewGroup.addView(ViewGroup.java:4809) System.err: android.view.ViewGroup.addView(ViewGroup.java:4782) System.err: androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1466) System.err: androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) System.err: androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) System.err: androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269) System.err: androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) System.err: androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2466) System.err: androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483) System.err: androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) System.err: androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:797) System.err: androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625) System.err: androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411) System.err: androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) System.err: androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243) System.err: androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654) System.err: com.tns.Runtime.callJSMethodNative(Native Method) System.err: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1209) System.err: com.tns.Runtime.callJSMethodImpl(Runtime.java:1096) System.err: com.tns.Runtime.callJSMethod(Runtime.java:1083) System.err: com.tns.Runtime.callJSMethod(Runtime.java:1063) System.err: com.tns.Runtime.callJSMethod(Runtime.java:1055) System.err: com.tns.gen.java.lang.Runnable.run(Runnable.java:17) System.err: android.os.Handler.handleCallback(Handler.java:873) System.err: android.os.Handler.dispatchMessage(Handler.java:99) System.err: android.os.Looper.loop(Looper.java:201) System.err: android.app.ActivityThread.main(ActivityThread.java:6810) System.err: java.lang.reflect.Method.invoke(Native Method) System.err: com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) System.err: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) System.err: System.err: StackTrace: System.err: push.../node_modules/tns-core-modules/ui/bottom-navigation/bottom-navigation.js.BottomNavigation.commitCurrentTransaction(file:///node_modules/tns-core-modules/ui/bottom-navigation/bottom-navigation.js:315:0) System.err: at push.../node_modules/tns-core-modules/ui/bottom-navigation/bottom-navigation.js.BottomNavigation.changeTab(file:///node_modules/tns-core-modules/ui/bottom-navigation/bottom-navigation.js:329:0) System.err: at push.../node_modules/tns-core-modules/ui/bottom-navigation/bottom-navigation.js.BottomNavigation.onLoaded(file:///node_modules/tns-core-modules/ui/bottom-navigation/bottom-navigation.js:259:0) System.err: at (file:///node_modules/tns-core-modules/ui/core/view-base/view-base.js:312:75) System.err: at push.../node_modules/tns-core-modules/ui/core/view-base/view-base.js.ViewBase.callFunctionWithSuper(file:///node_modules/tns-core-modules/ui/core/view-base/view-base.js:305:0) System.err: at push.../node_modules/tns-core-modules/ui/core/view-base/view-base.js.ViewBase.callLoaded(file:///node_modules/tns-core-modules/ui/core/view-base/view-base.js:312:0) System.err: at push.../node_modules/tns-core-modules/ui/frame/frame.js.ActivityCallbacksImplementation.resetActivityContent(file:///node_modules/tns-core-modules/ui/frame/frame.js:950:0) System.err: at _resetRootView(file:///node_modules/tns-core-modules/application/application.js:149:0) System.err: at push.../node_modules/nativescript-angular/platform-common.js.NativeScriptPlatformRef._livesync(file:///node_modules/nativescript-angular/platform-common.js:273:0) System.err: at (file:///node_modules/nativescript-angular/platform-common.js:102:74) System.err: at push.../node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js.ZoneDelegate.invokeTask(file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:421:0) System.err: at push.../node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js.Zone.runTask(file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:188:0) System.err: at push.../node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js.ZoneTask.invokeTask(file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:496:0) System.err: at ZoneTask.invoke(file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:485:0) System.err: at timer(file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:1561:0) System.err: at invoke(file:///node_modules/tns-core-modules/timer/timer.js:20:30) System.err: at push.../node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js.ZoneDelegate.invoke(file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:388:0) System.err: at push.../node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js.Zone.runGuarded(file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:151:0) System.err: at (file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:129:0) System.err: at run(file:///node_modules/tns-core-modules/timer/timer.js:24:0) System.err: at com.tns.Runtime.callJSMethodNative(Native Method) System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1209) System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:1096) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1083) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1063) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1055) System.err: at com.tns.gen.java.lang.Runnable.run(Runnable.java:17) System.err: at android.os.Handler.handleCallback(Handler.java:873) System.err: at android.os.Handler.dispatchMessage(Handler.java:99) System.err: at android.os.Looper.loop(Looper.java:201) System.err: at android.app.ActivityThread.main(ActivityThread.java:6810) System.err: at java.lang.reflect.Method.invoke(Native Method) System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) System.err: Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. System.err: at android.view.ViewGroup.addViewInner(ViewGroup.java:5038) System.err: at android.view.ViewGroup.addView(ViewGroup.java:4869) System.err: at android.view.ViewGroup.addView(ViewGroup.java:4809) System.err: at android.view.ViewGroup.addView(ViewGroup.java:4782) System.err: at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1466) System.err: at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) System.err: at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) System.err: at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269) System.err: at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) System.err: at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2466) System.err: at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1483) System.err: at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) System.err: at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:797) System.err: at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625) System.err: at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411) System.err: at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) System.err: at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243) System.err: at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654) System.err: ... 14 more
</details>

![image](https://user-images.githubusercontent.com/36491/65917354-c91c7700-e39c-11e9-8e73-665fe4c54011.png)


Activity

  1. tsonevn commented on Oct 1, 2019

    @tsonevn
    Contributor

    HI @beeman,
    Thank you for the attached sample project. I was able to recreate the issue in non-Angular {N} app as well. I will mark the issue as a bug and we will investigate it further.
    Archive.zip

    Update:
    Attaching an example with BottomNavigation without nested Frames.

    Archive.zip

  2. self-assigned this
    on Oct 28, 2019
  3. tsonevn commented on Oct 31, 2019

    @tsonevn
    Contributor

    I am attaching a new sample project, where the issue is still reproducible.
    Archive.zip

  4. manoldonev commented on Nov 18, 2019

    @manoldonev
    Contributor

    Fixed with latest cross-platform modules 6.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions