@@ -179,7 +179,7 @@ function initializeNativeClasses() {
179
179
tabStrip . notify ( {
180
180
eventName : TabStrip . itemTapEvent ,
181
181
object : tabStrip ,
182
- index : position ,
182
+ index : position
183
183
} ) ;
184
184
}
185
185
@@ -420,7 +420,7 @@ export class BottomNavigation extends TabNavigationBase {
420
420
const fragmentToDetach = this . _currentFragment ;
421
421
if ( fragmentToDetach ) {
422
422
this . destroyItem ( ( fragmentToDetach as any ) . index , fragmentToDetach ) ;
423
- this . commitCurrentTransaction ( ) ;
423
+ this . removeFragment ( fragmentToDetach ) ;
424
424
}
425
425
}
426
426
@@ -446,28 +446,41 @@ export class BottomNavigation extends TabNavigationBase {
446
446
447
447
private disposeTabFragments ( ) : void {
448
448
const fragmentManager = this . _getFragmentManager ( ) ;
449
- const transaction = fragmentManager . beginTransaction ( ) ;
450
449
const fragments = fragmentManager . getFragments ( ) . toArray ( ) ;
451
450
for ( let i = 0 ; i < fragments . length ; i ++ ) {
452
- transaction . remove ( fragments [ i ] ) ;
451
+ this . removeFragment ( fragments [ i ] ) ;
453
452
}
454
-
455
- transaction . commitNowAllowingStateLoss ( ) ;
456
- }
457
-
458
- private get currentTransaction ( ) : androidx . fragment . app . FragmentTransaction {
459
- if ( ! this . _currentTransaction ) {
460
- const fragmentManager = this . _getFragmentManager ( ) ;
461
- this . _currentTransaction = fragmentManager . beginTransaction ( ) ;
462
- }
463
-
464
- return this . _currentTransaction ;
465
453
}
466
-
467
- private commitCurrentTransaction ( ) : void {
468
- if ( this . _currentTransaction ) {
469
- this . _currentTransaction . commitNowAllowingStateLoss ( ) ;
470
- this . _currentTransaction = null ;
454
+ private attachFragment ( fragment : androidx . fragment . app . Fragment , id ?: number , name ?: string ) : void {
455
+ const fragmentManager = this . _getFragmentManager ( ) ;
456
+ if ( fragment ) {
457
+ if ( fragment . isAdded ( ) || fragment . isRemoving ( ) ) {
458
+ // ignore
459
+ } else {
460
+ const fragmentExitTransition = fragment . getExitTransition ( ) ;
461
+ if ( fragmentExitTransition && fragmentExitTransition instanceof org . nativescript . widgets . CustomTransition ) {
462
+ fragmentExitTransition . setResetOnTransitionEnd ( true ) ;
463
+ }
464
+ if ( fragmentManager ) {
465
+ if ( ! fragmentManager . isDestroyed ( ) ) {
466
+ try {
467
+ if ( fragmentManager . isStateSaved ( ) ) {
468
+ if ( id && name ) {
469
+ fragmentManager . beginTransaction ( ) . add ( id , fragment , name ) . commitNowAllowingStateLoss ( ) ;
470
+ } else {
471
+ fragmentManager . beginTransaction ( ) . attach ( fragment ) . commitNowAllowingStateLoss ( ) ;
472
+ }
473
+ } else {
474
+ if ( id && name ) {
475
+ fragmentManager . beginTransaction ( ) . add ( id , fragment , name ) . commitNow ( ) ;
476
+ } else {
477
+ fragmentManager . beginTransaction ( ) . attach ( fragment ) . commitNow ( ) ;
478
+ }
479
+ }
480
+ } catch ( e ) { }
481
+ }
482
+ }
483
+ }
471
484
}
472
485
}
473
486
@@ -487,8 +500,6 @@ export class BottomNavigation extends TabNavigationBase {
487
500
488
501
const fragment = this . instantiateItem ( this . _contentView , index ) ;
489
502
this . setPrimaryItem ( index , fragment ) ;
490
-
491
- this . commitCurrentTransaction ( ) ;
492
503
}
493
504
494
505
private instantiateItem ( container : android . view . ViewGroup , position : number ) : androidx . fragment . app . Fragment {
@@ -497,10 +508,10 @@ export class BottomNavigation extends TabNavigationBase {
497
508
const fragmentManager = this . _getFragmentManager ( ) ;
498
509
let fragment : androidx . fragment . app . Fragment = fragmentManager . findFragmentByTag ( name ) ;
499
510
if ( fragment != null ) {
500
- this . currentTransaction . attach ( fragment ) ;
511
+ this . attachFragment ( fragment ) ;
501
512
} else {
502
513
fragment = TabFragment . newInstance ( this . _domId , position ) ;
503
- this . currentTransaction . add ( container . getId ( ) , fragment , name ) ;
514
+ this . attachFragment ( fragment , container . getId ( ) , name ) ;
504
515
}
505
516
506
517
if ( fragment !== this . _currentFragment ) {
@@ -537,7 +548,7 @@ export class BottomNavigation extends TabNavigationBase {
537
548
538
549
private destroyItem ( position : number , fragment : androidx . fragment . app . Fragment ) : void {
539
550
if ( fragment ) {
540
- this . currentTransaction . detach ( fragment ) ;
551
+ this . removeFragment ( fragment ) ;
541
552
if ( this . _currentFragment === fragment ) {
542
553
this . _currentFragment = null ;
543
554
}
@@ -547,6 +558,34 @@ export class BottomNavigation extends TabNavigationBase {
547
558
this . items [ position ] . canBeLoaded = false ;
548
559
}
549
560
}
561
+ private removeFragment ( fragment : androidx . fragment . app . Fragment , fragmentManager ?: any ) {
562
+ if ( ! fragmentManager ) {
563
+ fragmentManager = this . _getFragmentManager ( ) ;
564
+ }
565
+ if ( fragment ) {
566
+ if ( ! fragment . isAdded ( ) || fragment . isRemoving ( ) ) {
567
+ // ignore
568
+ return ;
569
+ } else {
570
+ const fragmentExitTransition = fragment . getExitTransition ( ) ;
571
+ if ( fragmentExitTransition && fragmentExitTransition instanceof org . nativescript . widgets . CustomTransition ) {
572
+ fragmentExitTransition . setResetOnTransitionEnd ( true ) ;
573
+ }
574
+ if ( fragment && fragment . isAdded ( ) && ! fragment . isRemoving ( ) ) {
575
+ const pfm = ( fragment as any ) . getParentFragmentManager ? ( fragment as any ) . getParentFragmentManager ( ) : null ;
576
+ if ( pfm && ! pfm . isDestroyed ( ) ) {
577
+ try {
578
+ if ( pfm . isStateSaved ( ) ) {
579
+ pfm . beginTransaction ( ) . remove ( fragment ) . commitNowAllowingStateLoss ( ) ;
580
+ } else {
581
+ pfm . beginTransaction ( ) . remove ( fragment ) . commitNow ( ) ;
582
+ }
583
+ } catch ( e ) { }
584
+ }
585
+ }
586
+ }
587
+ }
588
+ }
550
589
551
590
private setTabStripItems ( items : TabStripItem [ ] ) {
552
591
if ( ! this . tabStrip || ! items ) {
@@ -665,7 +704,7 @@ export class BottomNavigation extends TabNavigationBase {
665
704
666
705
return {
667
706
drawable : imageDrawable ,
668
- height : image . getHeight ( ) ,
707
+ height : image . getHeight ( )
669
708
} ;
670
709
}
671
710
@@ -684,7 +723,7 @@ export class BottomNavigation extends TabNavigationBase {
684
723
685
724
const iconSpecSize = getIconSpecSize ( {
686
725
width : inWidth ,
687
- height : inHeight ,
726
+ height : inHeight
688
727
} ) ;
689
728
690
729
const widthPixels = iconSpecSize . width * Utils . layout . getDisplayDensity ( ) ;
0 commit comments