@@ -103,7 +103,7 @@ function initializeNativeClasses() {
103
103
104
104
// Get view as bitmap and set it as background. This is workaround for the disapearing nested fragments.
105
105
// TODO: Consider removing it when update to androidx.fragment:1.2.0
106
- if ( hasRemovingParent && this . owner . selectedIndex === this . index ) {
106
+ if ( hasRemovingParent && this . owner . selectedIndex === this . index && this . owner . nativeViewProtected ) {
107
107
this . backgroundBitmap = this . loadBitmapFromView ( this . owner . nativeViewProtected ) ;
108
108
}
109
109
@@ -200,18 +200,17 @@ function initializeNativeClasses() {
200
200
}
201
201
202
202
destroyItem ( container : android . view . ViewGroup , position : number , object : java . lang . Object ) : void {
203
+ const fragment : androidx . fragment . app . Fragment = object as androidx . fragment . app . Fragment ;
203
204
if ( ! this . mCurTransaction ) {
204
- const fragmentManager = this . owner . _getFragmentManager ( ) ;
205
- this . mCurTransaction = fragmentManager . beginTransaction ( ) ;
205
+ const fragmentManager : androidx . fragment . app . FragmentManager = this . owner . _getParentFragmentManagerFromFragment ( fragment ) ;
206
+ this . mCurTransaction = fragmentManager ? .beginTransaction ( ) ;
206
207
}
207
208
208
- const fragment : androidx . fragment . app . Fragment = object as androidx . fragment . app . Fragment ;
209
-
210
209
const index = this . owner . fragments . indexOf ( fragment ) ;
211
210
// if (index !== -1) {
212
211
// this.owner.fragments.splice(index, 1);
213
212
// }
214
- this . mCurTransaction . detach ( fragment ) ;
213
+ this . mCurTransaction ? .detach ( fragment ) ;
215
214
216
215
if ( this . mCurrentPrimaryItem === fragment ) {
217
216
this . mCurrentPrimaryItem = null ;
@@ -479,7 +478,7 @@ export class Tabs extends TabsBase {
479
478
return nativeView ;
480
479
}
481
480
onSelectedIndexChanged ( oldIndex : number , newIndex : number ) {
482
- const tabBarImplementation = ( this . _tabsBar as unknown ) as PositionChanger ;
481
+ const tabBarImplementation = this . _tabsBar as unknown as PositionChanger ;
483
482
if ( tabBarImplementation ) {
484
483
tabBarImplementation . onSelectedPositionChange ( oldIndex , newIndex ) ;
485
484
}
@@ -621,14 +620,22 @@ export class Tabs extends TabsBase {
621
620
}
622
621
623
622
private disposeCurrentFragments ( ) : void {
624
- const fragmentManager = this . _getFragmentManager ( ) ;
625
- const transaction = fragmentManager . beginTransaction ( ) ;
623
+ let fragmentManager : androidx . fragment . app . FragmentManager ;
624
+ for ( const fragment of this . fragments ) {
625
+ fragmentManager = this . _getParentFragmentManagerFromFragment ( fragment ) ;
626
+ if ( fragmentManager ) {
627
+ break ;
628
+ }
629
+ }
630
+ if ( fragmentManager ) {
631
+ const transaction = fragmentManager . beginTransaction ( ) ;
626
632
627
- const fragments = this . fragments ;
628
- for ( let i = 0 ; i < fragments . length ; i ++ ) {
629
- transaction . remove ( fragments [ i ] ) ;
633
+ const fragments = this . fragments ;
634
+ for ( let i = 0 ; i < fragments . length ; i ++ ) {
635
+ transaction . remove ( fragments [ i ] ) ;
636
+ }
637
+ transaction . commitNowAllowingStateLoss ( ) ;
630
638
}
631
- transaction . commitNowAllowingStateLoss ( ) ;
632
639
this . fragments = [ ] ;
633
640
}
634
641
0 commit comments