File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,7 +29,6 @@ export class ActionBarBase extends View implements ActionBarDefinition {
2929 public effectiveContentInsetRight : number ;
3030
3131 disposeNativeView ( ) {
32- this . _actionItems = null ;
3332 super . disposeNativeView ( ) ;
3433 }
3534
Original file line number Diff line number Diff line change @@ -814,6 +814,34 @@ export class ActivityCallbacksImplementation implements AndroidActivityCallbacks
814814 const isRestart = ! ! savedInstanceState && moduleLoaded ;
815815 superFunc . call ( activity , isRestart ? savedInstanceState : null ) ;
816816
817+ if ( isRestart && activity . getSupportFragmentManager ) {
818+ // Remove restored fragments that NativeScript will recreate via _setupUI/createNativeView.
819+ // NativeScript tears down and rebuilds the entire view tree on activity recreation,
820+ // so restored fragments (especially from ViewPager2/tabs) become orphaned without views.
821+ // NativeScript core's own fragments use tags like "fragment{id}[{depth}]" and are
822+ // handled by _processNextNavigationEntry. We remove all non-NativeScript fragments.
823+ const fm = activity . getSupportFragmentManager ( ) ;
824+ const fragments = fm . getFragments ( ) ;
825+ const size = fragments ?. size ?.( ) ?? 0 ;
826+ if ( size > 0 ) {
827+ const ft = fm . beginTransaction ( ) ;
828+ let removed = false ;
829+ for ( let i = size - 1 ; i >= 0 ; i -- ) {
830+ const f = fragments . get ( i ) ;
831+ if ( ! f ) continue ;
832+ const tag = f . getTag ( ) ;
833+ if ( tag && tag . startsWith ( 'fragment' ) ) {
834+ continue ;
835+ }
836+ ft . remove ( f ) ;
837+ removed = true ;
838+ }
839+ if ( removed ) {
840+ ft . commitNowAllowingStateLoss ( ) ;
841+ }
842+ }
843+ }
844+
817845 // Try to get the rootViewId form the saved state in case the activity
818846 // was destroyed and we are now recreating it.
819847 if ( savedInstanceState ) {
You can’t perform that action at this time.
0 commit comments