From 4e62b00ddb84823654c864d32e298db286068733 Mon Sep 17 00:00:00 2001 From: Dimitris-Rafail Katsampas Date: Thu, 2 Mar 2023 18:39:32 +0200 Subject: [PATCH] fix(core): Frame to Page property propagation (#10225) --- packages/core/ui/frame/frame-common.ts | 15 ++++++++++++--- packages/core/ui/frame/index.android.ts | 10 ++++++---- packages/core/ui/page/index.ios.ts | 4 +++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/core/ui/frame/frame-common.ts b/packages/core/ui/frame/frame-common.ts index 94ffc0b1a..f16484b23 100644 --- a/packages/core/ui/frame/frame-common.ts +++ b/packages/core/ui/frame/frame-common.ts @@ -43,6 +43,14 @@ export class FrameBase extends CustomLayoutView { public actionBarVisibility: 'auto' | 'never' | 'always'; public _currentEntry: BackstackEntry; + + /** + * A reference of current page that is set earlier than current entry. + * Using this property, methods like 'eachChildView' and '_childrenCount' gain access to page view + * just in time for calls like '_addView' to perform view-tree iterations. + */ + public _resolvedPage: Page; + public _animationInProgress = false; public _executingContext: NavigationContext; public _isInFrameStack = false; @@ -238,6 +246,8 @@ export class FrameBase extends CustomLayoutView { // In case we navigated forward to a page that was in the backstack // with clearHistory: true if (!newPage.frame) { + this._resolvedPage = newPage; + this._addView(newPage); newPage._frame = this; } @@ -456,7 +466,6 @@ export class FrameBase extends CustomLayoutView { if (this._currentEntry) { return this._currentEntry.resolvedPage; } - return null; } @@ -508,7 +517,7 @@ export class FrameBase extends CustomLayoutView { } get _childrenCount(): number { - if (this.currentPage) { + if (this._resolvedPage) { return 1; } @@ -516,7 +525,7 @@ export class FrameBase extends CustomLayoutView { } public eachChildView(callback: (child: View) => boolean) { - const page = this.currentPage; + const page = this._resolvedPage; if (page) { callback(page); } diff --git a/packages/core/ui/frame/index.android.ts b/packages/core/ui/frame/index.android.ts index 1b926728e..337198e68 100644 --- a/packages/core/ui/frame/index.android.ts +++ b/packages/core/ui/frame/index.android.ts @@ -913,6 +913,8 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks { return null; } + frame._resolvedPage = page; + if (page.parent === frame) { // If we are navigating to a page that was destroyed // reinitialize its UI. @@ -920,6 +922,10 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks { const context = (container && container.getContext()) || (inflater && inflater.getContext()); page._setupUI(context); } + + if (frame.isLoaded && !page.isLoaded) { + page.callLoaded(); + } } else { if (!frame._styleScope) { // Make sure page will have styleScope even if parents don't. @@ -929,10 +935,6 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks { frame._addView(page); } - if (frame.isLoaded && !page.isLoaded) { - page.callLoaded(); - } - const savedState = entry.viewSavedState; if (savedState) { (page.nativeViewProtected).restoreHierarchyState(savedState); diff --git a/packages/core/ui/page/index.ios.ts b/packages/core/ui/page/index.ios.ts index d6bc16367..bd2bbab0e 100644 --- a/packages/core/ui/page/index.ios.ts +++ b/packages/core/ui/page/index.ios.ts @@ -120,7 +120,7 @@ class UIViewControllerImpl extends UIViewController { return; } - const frame = this.navigationController ? (this.navigationController).owner : null; + const frame: Frame = this.navigationController ? (this.navigationController).owner : null; const newEntry = this[ENTRY]; // Don't raise event if currentPage was showing modal page. @@ -130,6 +130,8 @@ class UIViewControllerImpl extends UIViewController { } if (frame) { + frame._resolvedPage = owner; + if (!owner.parent) { owner._frame = frame; if (!frame._styleScope) {