NativeScript / nativescript-angular

Integrating NativeScript with Angular
http://docs.nativescript.org/angular/tutorial/ng-chapter-0
Apache License 2.0
1.21k stars 241 forks source link

[Angular 10] Dismissing a dialog with tabs inside it throws exception #2259

Open mohammadrafigh opened 3 years ago

mohammadrafigh commented 3 years ago

Environment

Describe the bug I have a dialog which has 2 tabs inside it. When I try to dismiss the dialog by tapping the dialog overlay (dark transparent area) or by pressing back button, this exception occurs:

System.err: An uncaught Exception occurred on "main" thread.
System.err: Calling js method destroyItem failed
System.err: Error: java.lang.IllegalStateException: Cannot detach Fragment attached to a different FragmentManager. Fragment FragmentBase_vendor_135144_28_TabFragmentImplementation{f89a49e} (2f3646ad-0ab5-459a-9c9e-20f4ee91cb19) id=0xd android:viewpager:13:0} is already attached to a FragmentManager.
System.err: 
System.err: StackTrace:
System.err: FragmentPagerAdapter.destroyItem(file: node_modules/@nativescript/core/ui/tabs/index.android.js:159:0)
System.err:     at setItems(file: node_modules/@nativescript/core/ui/tabs/index.android.js:478:0)
System.err:     at onUnloaded(file: node_modules/@nativescript/core/ui/tabs/index.android.js:412:0)
System.err:     at (file: node_modules/@nativescript/core/ui/core/view-base/index.js:300:0)
System.err:     at callFunctionWithSuper(file: node_modules/@nativescript/core/ui/core/view-base/index.js:291:0)
System.err:     at callUnloaded(file: node_modules/@nativescript/core/ui/core/view-base/index.js:300:0)
System.err:     at unloadView(file: node_modules/@nativescript/core/ui/core/view-base/index.js:445:0)
System.err:     at (file: node_modules/@nativescript/core/ui/core/view-base/index.js:228:0)
System.err:     at eachChildView(file: node_modules/@nativescript/core/ui/layouts/layout-base-common.js:101:0)
System.err:     at eachChild(file: node_modules/@nativescript/core/ui/core/view/view-common.js:700:0)
System.err:     at onUnloaded(file: node_modules/@nativescript/core/ui/core/view-base/index.js:227:0)
System.err:     at onUnloaded(file: node_modules/@nativescript/core/ui/core/view/index.android.js:284:0)
System.err:     at (file: node_modules/@nativescript/core/ui/core/view-base/index.js:300:0)
System.err:     at callFunctionWithSuper(file: node_modules/@nativescript/core/ui/core/view-base/index.js:291:0)
System.err:     at callUnloaded(file: node_modules/@nativescript/core/ui/core/view-base/index.js:300:0)
System.err:     at unloadView(file: node_modules/@nativescript/core/ui/core/view-base/index.js:445:0)
System.err:     at (file: node_modules/@nativescript/core/ui/core/view-base/index.js:228:0)
System.err:     at eachChildView(file: node_modules/@nativescript/core/ui/layouts/layout-base-common.js:101:0)
System.err:     at eachChild(file: node_modules/@nativescript/core/ui/core/view/view-common.js:700:0)
System.err:     at onUnloaded(file: node_modules/@nativescript/core/ui/core/view-base/index.js:227:0)
System.err:     at onUnloaded(file: node_modules/@nativescript/core/ui/core/view/index.android.js:284:0)
System.err:     at (file: node_modules/@nativescript/core/ui/core/view-base/index.js:300:0)
System.err:     at callFunctionWithSuper(file: node_modules/@nativescript/core/ui/core/view-base/index.js:291:0)
System.err:     at callUnloaded(file: node_modules/@nativescript/core/ui/core/view-base/index.js:300:0)
System.err:     at DialogFragmentImpl.onDismiss(file: node_modules/@nativescript/core/ui/core/view/index.android.js:168:0)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1188)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1175)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1153)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1149)
System.err:     at com.tns.gen.androidx.viewpager.widget.PagerAdapter_vendor_135210_28_FragmentPagerAdapter.destroyItem(PagerAdapter_vendor_135210_28_FragmentPagerAdapter.java:45)
System.err:     at androidx.viewpager.widget.ViewPager.dataSetChanged(ViewPager.java:1047)
System.err:     at androidx.viewpager.widget.ViewPager$PagerObserver.onChanged(ViewPager.java:3097)
System.err:     at androidx.viewpager.widget.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:291)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1188)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1175)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1153)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1149)
System.err:     at com.tns.gen.androidx.fragment.app.DialogFragment_vendor_115854_28_DialogFragmentImpl.onDismiss(DialogFragment_vendor_115854_28_DialogFragmentImpl.java:25)
System.err:     at androidx.fragment.app.DialogFragment$3.onDismiss(DialogFragment.java:120)
System.err:     at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1407)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:107)
System.err:     at android.os.Looper.loop(Looper.java:214)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:7356)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
System.err: Caused by: java.lang.IllegalStateException: Cannot detach Fragment attached to a different FragmentManager. Fragment FragmentBase_vendor_135144_28_TabFragmentImplementation{f89a49e} (2f3646ad-0ab5-459a-9c9e-20f4ee91cb19) id=0xd android:viewpager:13:0} is already attached to a FragmentManager.
System.err:     at androidx.fragment.app.BackStackRecord.detach(BackStackRecord.java:222)
System.err:     ... 25 more

But closing the same dialog using this.params.closeCallback() works. It seems recent commits related to detaching components has broken something in dialogs.

edusperoni commented 3 years ago

Hey @mohammadrafigh

Does this also happen on 10.1.2?

mohammadrafigh commented 3 years ago

Hi, nope, actually I upgraded from 10.1.2 to 10.1.3 and again to 10.1.4 tonight and the exception occurs only on 10.1.3 and 10.1.4

On Mon, 21 Sep 2020, 23:27 Eduardo Speroni, notifications@github.com wrote:

Hey @mohammadrafigh https://github.com/mohammadrafigh

Does this also happen on 10.1.2?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NativeScript/nativescript-angular/issues/2259#issuecomment-696338852, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTM4ZGUWOWCVD4X37KLCW3SG6V3HANCNFSM4RUG4XTA .

edusperoni commented 3 years ago

Can you provide a sample project?

edusperoni commented 3 years ago

@mohammadrafigh I managed to reproduce the issue, but it also happens on 10.1.0 for me.

Are you sure it worked on <10.1.3?

mohammadrafigh commented 3 years ago

@edusperoni sorry for delay, I may be wrong at versions since I'm updating NS day to day to see if any of dozens of issues I faced after upgrading to NS7 has been fixed or not. Thanks for putting time on contribution in NS. I hope some day I can improve some aspects too.