diff --git a/tns-core-modules/ui/frame/fragment.transitions.android.ts b/tns-core-modules/ui/frame/fragment.transitions.android.ts index 151066f1c..437698d8e 100644 --- a/tns-core-modules/ui/frame/fragment.transitions.android.ts +++ b/tns-core-modules/ui/frame/fragment.transitions.android.ts @@ -724,6 +724,7 @@ function transitionOrAnimationCompleted(entry: ExpandedEntry): void { entries.delete(entry); if (entries.size === 0) { const frame = entry.resolvedPage.frame; + // We have 0 or 1 entry per frameId in completedEntries // So there is no need to make it to Set like waitingQueue const previousCompletedAnimationEntry = completedEntries.get(frameId); @@ -734,8 +735,8 @@ function transitionOrAnimationCompleted(entry: ExpandedEntry): void { current = current || entry; // Will be null if Frame is shown modally... // transitionOrAnimationCompleted fires again (probably bug in android). - if (current) { - setTimeout(() => frame.setCurrent(current)); + if (current && frame._executingContext) { + setTimeout(() => frame.setCurrent(current, frame._executingContext.navigationType)); } } else { completedEntries.set(frameId, entry); diff --git a/tns-core-modules/ui/frame/frame-common.ts b/tns-core-modules/ui/frame/frame-common.ts index 93c12b08d..b88d79c56 100644 --- a/tns-core-modules/ui/frame/frame-common.ts +++ b/tns-core-modules/ui/frame/frame-common.ts @@ -13,7 +13,6 @@ import { getModuleName } from "../../utils/utils"; export * from "../core/view"; export enum NavigationType { - unset, back, forward, replace @@ -219,7 +218,7 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { return this._currentEntry === entry; } - public setCurrent(entry: BackstackEntry): void { + public setCurrent(entry: BackstackEntry, navigationType: NavigationType): void { const newPage = entry.resolvedPage; // In case we navigated forward to a page that was in the backstack // with clearHistory: true @@ -230,8 +229,6 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { this._currentEntry = entry; - const navigationContext = this._executingContext || { navigationType: NavigationType.unset }; - const navigationType = navigationContext.navigationType; const isBack = navigationType === NavigationType.back; if (isBack) { this._pushInFrameStack(); diff --git a/tns-core-modules/ui/frame/frame.android.ts b/tns-core-modules/ui/frame/frame.android.ts index 8d4ac385d..bdf640b8c 100644 --- a/tns-core-modules/ui/frame/frame.android.ts +++ b/tns-core-modules/ui/frame/frame.android.ts @@ -265,11 +265,9 @@ export class Frame extends FrameBase { return newFragment; } - public setCurrent(entry: BackstackEntry): void { + public setCurrent(entry: BackstackEntry, navigationType: NavigationType): void { const current = this._currentEntry; const currentEntryChanged = current !== entry; - const navigationContext = this._executingContext || { navigationType: NavigationType.unset }; - const navigationType = navigationContext.navigationType; if (currentEntryChanged) { this._updateBackstack(entry, navigationType); @@ -300,7 +298,7 @@ export class Frame extends FrameBase { } } - super.setCurrent(entry); + super.setCurrent(entry, navigationType); // If we had real navigation process queue. this._processNavigationQueue(entry.resolvedPage); @@ -375,8 +373,7 @@ export class Frame extends FrameBase { navDepth = -1; } - const navigationContext = this._executingContext || { navigationType: NavigationType.unset }; - const isReplace = navigationContext.navigationType === NavigationType.replace; + const isReplace = this._executingContext && this._executingContext.navigationType === NavigationType.replace; if (!isReplace) { navDepth++; } @@ -470,16 +467,16 @@ export class Frame extends FrameBase { this.nativeViewProtected[ownerSymbol] = null; this._tearDownPending = !!this._executingContext; const current = this._currentEntry; - const executingContext = this._executingContext || { entry: null }; + const executingEntry = this._executingContext ? this._executingContext.entry : null; this.backStack.forEach(entry => { // Don't destroy current and executing entries or UI will look blank. // We will do it in setCurrent. - if (entry !== executingContext.entry) { + if (entry !== executingEntry) { clearEntry(entry); } }); - if (current && !executingContext.entry) { + if (current && !executingEntry) { clearEntry(current); } diff --git a/tns-core-modules/ui/frame/frame.d.ts b/tns-core-modules/ui/frame/frame.d.ts index aa358d2cf..78ac20725 100644 --- a/tns-core-modules/ui/frame/frame.d.ts +++ b/tns-core-modules/ui/frame/frame.d.ts @@ -117,8 +117,9 @@ export class Frame extends View { /** * @private * @param entry to set as current + * @param navigationType */ - setCurrent(entry: BackstackEntry): void; + setCurrent(entry: BackstackEntry, navigationType: NavigationType): void; /** * @private */ diff --git a/tns-core-modules/ui/frame/frame.ios.ts b/tns-core-modules/ui/frame/frame.ios.ts index 03f553fc8..d06548dcb 100644 --- a/tns-core-modules/ui/frame/frame.ios.ts +++ b/tns-core-modules/ui/frame/frame.ios.ts @@ -53,14 +53,13 @@ export class Frame extends FrameBase { return this._ios; } - public setCurrent(entry: BackstackEntry): void { + public setCurrent(entry: BackstackEntry, navigationType: NavigationType): void { const current = this._currentEntry; const currentEntryChanged = current !== entry; - const navigationContext = this._executingContext || { navigationType: NavigationType.unset }; if (currentEntryChanged) { - this._updateBackstack(entry, navigationContext.navigationType); + this._updateBackstack(entry, navigationType); - super.setCurrent(entry); + super.setCurrent(entry, navigationType); } } @@ -78,8 +77,7 @@ export class Frame extends FrameBase { navDepth = -1; } - const navigationContext = this._executingContext || { navigationType: NavigationType.unset }; - const isReplace = navigationContext.navigationType === NavigationType.replace; + const isReplace = this._executingContext && this._executingContext.navigationType === NavigationType.replace; if (!isReplace) { navDepth++; } diff --git a/tns-core-modules/ui/page/page.ios.ts b/tns-core-modules/ui/page/page.ios.ts index 4e03a8ef9..c80a6becd 100644 --- a/tns-core-modules/ui/page/page.ios.ts +++ b/tns-core-modules/ui/page/page.ios.ts @@ -26,7 +26,8 @@ function isBackNavigationTo(page: Page, entry): boolean { return false; } - const navigationContext = frame._executingContext || { navigationType: NavigationType.unset }; + // if executing context is null here this most probably means back navigation through iOS back button + const navigationContext = frame._executingContext || { navigationType: NavigationType.back }; const isReplace = navigationContext.navigationType === NavigationType.replace; if (isReplace) { return false; @@ -141,10 +142,11 @@ class UIViewControllerImpl extends UIViewController { const newEntry: BackstackEntry = this[ENTRY]; // frame.setCurrent(...) will reset executing context so retrieve it here - const navigationContext = frame._executingContext || { navigationType: NavigationType.unset }; + // if executing context is null here this most probably means back navigation through iOS back button + const navigationContext = frame._executingContext || { navigationType: NavigationType.back }; const isReplace = navigationContext.navigationType === NavigationType.replace; - frame.setCurrent(newEntry); + frame.setCurrent(newEntry, navigationContext.navigationType); if (isReplace) { let controller = newEntry.resolvedPage.ios;