Skip to content

Commit 5f8fb2c

Browse files
authored
fix(ios): frame backstack disposal handling (#10672)
1 parent d3d4dfe commit 5f8fb2c

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

packages/core/ui/frame/frame-common.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ export class FrameBase extends CustomLayoutView {
217217
removed.resolvedPage = null;
218218
}
219219

220+
protected _disposeBackstackEntry(entry: BackstackEntry): void {
221+
const page = entry.resolvedPage;
222+
if (page) {
223+
page._tearDownUI(true);
224+
}
225+
}
226+
220227
public navigate(param: any) {
221228
if (Trace.isEnabled()) {
222229
Trace.write(`NAVIGATE`, Trace.categories.Navigation);

packages/core/ui/frame/index.android.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,11 @@ export class Frame extends FrameBase {
318318
if (this._tearDownPending) {
319319
this._tearDownPending = false;
320320
if (!entry.recreated) {
321-
clearEntry(entry);
321+
this._disposeBackstackEntry(entry);
322322
}
323323

324324
if (current && !current.recreated) {
325-
clearEntry(current);
325+
this._disposeBackstackEntry(current);
326326
}
327327

328328
// If we have context activity was recreated. Create new fragment
@@ -493,6 +493,17 @@ export class Frame extends FrameBase {
493493
removed.viewSavedState = null;
494494
}
495495

496+
protected _disposeBackstackEntry(entry: BackstackEntry): void {
497+
if (entry.fragment) {
498+
_clearFragment(entry);
499+
}
500+
501+
entry.recreated = false;
502+
entry.fragment = null;
503+
504+
super._disposeBackstackEntry(entry);
505+
}
506+
496507
public createNativeView() {
497508
// Create native view with available _currentEntry occur in Don't Keep Activities
498509
// scenario when Activity is recreated on app suspend/resume. Push frame back in frame stack
@@ -527,12 +538,12 @@ export class Frame extends FrameBase {
527538
// Don't destroy current and executing entries or UI will look blank.
528539
// We will do it in setCurrent.
529540
if (entry !== executingEntry) {
530-
clearEntry(entry);
541+
this._disposeBackstackEntry(entry);
531542
}
532543
});
533544

534545
if (current && !executingEntry) {
535-
clearEntry(current);
546+
this._disposeBackstackEntry(current);
536547
}
537548

538549
this._android.rootViewGroup = null;
@@ -641,19 +652,6 @@ function restoreTransitionState(entry: BackstackEntry, snapshot: TransitionState
641652
expandedEntry.transitionName = snapshot.transitionName;
642653
}
643654

644-
function clearEntry(entry: BackstackEntry): void {
645-
if (entry.fragment) {
646-
_clearFragment(entry);
647-
}
648-
649-
entry.recreated = false;
650-
entry.fragment = null;
651-
const page = entry.resolvedPage;
652-
if (page && page._context) {
653-
entry.resolvedPage._tearDownUI(true);
654-
}
655-
}
656-
657655
let framesCounter = 0;
658656
const framesCache = new Array<WeakRef<AndroidFrame>>();
659657

packages/core/ui/frame/index.ios.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ export class Frame extends FrameBase {
4242
}
4343

4444
public disposeNativeView() {
45+
const current = this._currentEntry;
46+
const executingEntry = this._executingContext ? this._executingContext.entry : null;
47+
48+
if (executingEntry) {
49+
this._disposeBackstackEntry(executingEntry);
50+
}
51+
52+
this.backStack.forEach((entry) => {
53+
if (entry !== executingEntry) {
54+
this._disposeBackstackEntry(entry);
55+
}
56+
});
57+
58+
if (current) {
59+
this._disposeBackstackEntry(current);
60+
}
61+
4562
this._removeFromFrameStack();
4663
this.viewController = null;
4764
this._animatedDelegate = null;

0 commit comments

Comments
 (0)