fix back navigation

This commit is contained in:
Manol Donev
2019-06-04 17:40:26 +03:00
parent 30d06f2d7e
commit 6d36041823
6 changed files with 21 additions and 25 deletions

View File

@@ -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);

View File

@@ -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();

View File

@@ -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);
}

View File

@@ -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
*/

View File

@@ -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++;
}

View File

@@ -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;