mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
fix(bottom-navigation): fragment handling (#9243)
This commit is contained in:
@ -540,7 +540,9 @@ export class BottomNavigation extends TabNavigationBase {
|
||||
|
||||
if (fragment != null) {
|
||||
fragment.setMenuVisibility(true);
|
||||
fragment.setUserVisibleHint(true);
|
||||
// commenting out as it fixes rare crash when going
|
||||
// back from deeply nested/modally shown fragments
|
||||
// fragment.setUserVisibleHint(true);
|
||||
}
|
||||
|
||||
this._currentFragment = fragment;
|
||||
@ -582,8 +584,8 @@ export class BottomNavigation extends TabNavigationBase {
|
||||
fragmentExitTransition.setResetOnTransitionEnd(true);
|
||||
}
|
||||
if (fragment && fragment.isAdded() && !fragment.isRemoving()) {
|
||||
const pfm = (<any>fragment).getParentFragmentManager ? (<any>fragment).getParentFragmentManager() : null;
|
||||
if (pfm && !pfm.isDestroyed()) {
|
||||
const pfm = (<any>fragment).getParentFragmentManager ? (<any>fragment).getParentFragmentManager() : fragmentManager;
|
||||
if (pfm) {
|
||||
try {
|
||||
if (pfm.isStateSaved()) {
|
||||
pfm.beginTransaction().remove(fragment).commitNowAllowingStateLoss();
|
||||
|
@ -205,13 +205,24 @@ function initializeNativeClasses() {
|
||||
}
|
||||
|
||||
destroyItem(container: android.view.ViewGroup, position: number, object: java.lang.Object): void {
|
||||
if (!this.mCurTransaction) {
|
||||
const fragmentManager = this.owner._getFragmentManager();
|
||||
this.mCurTransaction = fragmentManager.beginTransaction();
|
||||
}
|
||||
|
||||
const fragment: androidx.fragment.app.Fragment = <androidx.fragment.app.Fragment>object;
|
||||
this.mCurTransaction.detach(fragment);
|
||||
|
||||
if(fragment.isAdded()) {
|
||||
if (!this.mCurTransaction) {
|
||||
try {
|
||||
// try to get the correct FragmentManager
|
||||
// @ts-ignore
|
||||
const fragmentManager = fragment.getParentFragmentManager()
|
||||
this.mCurTransaction = fragmentManager.beginTransaction();
|
||||
} catch (err) {
|
||||
const fragmentManager = this.owner._getFragmentManager();
|
||||
this.mCurTransaction = fragmentManager.beginTransaction();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.mCurTransaction.detach(fragment);
|
||||
}
|
||||
|
||||
if (this.mCurrentPrimaryItem === fragment) {
|
||||
this.mCurrentPrimaryItem = null;
|
||||
|
Reference in New Issue
Block a user