From f80e6c6be655c3c56be7da664bd2008c2eba478e Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Wed, 3 Feb 2021 21:50:21 +0100 Subject: [PATCH] =?UTF-8?q?fix(android):=20prevent=20=E2=80=9Cflashing?= =?UTF-8?q?=E2=80=9D=20activity=20on=20app=20start?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was due to a change made a while back to fix an issue with resetRootView. The consequence was that we were waiting for the frame to be “attachedToWindow” to load the first frame page. That PR make it so that we apply that check/fix only when the activity was reset. Thus it wont happen on app start --- packages/core/ui/frame/index.android.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/core/ui/frame/index.android.ts b/packages/core/ui/frame/index.android.ts index ccfc3a918..285a249b9 100644 --- a/packages/core/ui/frame/index.android.ts +++ b/packages/core/ui/frame/index.android.ts @@ -84,6 +84,7 @@ export class Frame extends FrameBase { private _containerViewId = -1; private _tearDownPending = false; private _attachedToWindow = false; + private _wasReset = false; private _cachedTransitionState: TransitionState; constructor() { @@ -150,6 +151,7 @@ export class Frame extends FrameBase { } this._attachedToWindow = true; + this._wasReset = false; this._processNextNavigationEntry(); } @@ -164,7 +166,16 @@ export class Frame extends FrameBase { // In this case call _navigateCore in order to recreate the current fragment. // Don't call navigate because it will fire navigation events. // As JS instances are alive it is already done for the current page. - if (!this.isLoaded || this._executingContext || !this._attachedToWindow) { + if (!this.isLoaded || this._executingContext) { + return; + } + + // in case the activity is "reset" using resetRootView we must wait for + // the attachedToWindow event to make the first navigation or it will crash + // https://github.com/NativeScript/NativeScript/commit/9dd3e1a8076e5022e411f2f2eeba34aabc68d112 + // though we should not do it on app "start" + // or it will create a "flash" to activity background color + if (this._wasReset && !this._attachedToWindow) { return; } @@ -224,7 +235,8 @@ export class Frame extends FrameBase { public _onRootViewReset(): void { super._onRootViewReset(); - + // used to handle the "first" navigate differently on first run and on reset + this._wasReset = true; // call this AFTER the super call to ensure descendants apply their rootview-reset logic first // i.e. in a scenario with nested frames / frame with tabview let the descendandt cleanup the inner // fragments first, and then cleanup the parent fragments