Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/core/ui/action-bar/action-bar-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class ActionBarBase extends View implements ActionBarDefinition {
public effectiveContentInsetRight: number;

disposeNativeView() {
this._actionItems = null;
super.disposeNativeView();
}

Expand Down
27 changes: 27 additions & 0 deletions packages/core/ui/frame/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,33 @@ export class ActivityCallbacksImplementation implements AndroidActivityCallbacks
const isRestart = !!savedInstanceState && moduleLoaded;
superFunc.call(activity, isRestart ? savedInstanceState : null);

if (isRestart && activity.getSupportFragmentManager) {
// Remove restored fragments that NativeScript will recreate via _setupUI/createNativeView.
// NativeScript tears down and rebuilds the entire view tree on activity recreation,
// so restored fragments (especially from ViewPager2/tabs) become orphaned without views.
// NativeScript core's own fragments use tags like "fragment{id}[{depth}]" and are
// handled by _processNextNavigationEntry. We remove all non-NativeScript fragments.
const fm = activity.getSupportFragmentManager();
const fragments = fm.getFragments();
if (fragments && fragments.size() > 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The java size() call can be done only once and store the return value in a variable.
e.g.

const size = fragments.size();

const ft = fm.beginTransaction();
let removed = false;
for (let i = fragments.size() - 1; i >= 0; i--) {
const f = fragments.get(i);
if (!f) continue;
const tag = f.getTag();
if (tag && tag.startsWith('fragment')) {
continue;
}
ft.remove(f);
removed = true;
}
if (removed) {
ft.commitNowAllowingStateLoss();
}
}
}

// Try to get the rootViewId form the saved state in case the activity
// was destroyed and we are now recreating it.
if (savedInstanceState) {
Expand Down
Loading