mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fix clear history transition (#4951)
* fix: Navigation test app added * Removed native popToBackstack call. Implemented custom fragment save/restore state. When navigating back we reverse manually transitions/animations because we no longer add them to navite backstack. Fragment instance stored on entry. Animation and Transition listeners now holds reference to entry instead of fragment for easier update of fragment. Animation and Transition listeners removed when entry removed from backstack. Animation and Transition removed from fragment when fragment activity is destroyed. * Revert package.json start up entry Fixed bug where goBack took the last element in backstack while navigationQueue is not empty. Fixed bug where goBack to specific entry in the backstack was removing that entry... Removed duplicated method Refactored method name Fixed TS
This commit is contained in:
@@ -152,14 +152,16 @@ export function getClearCurrentPage(): Page {
|
||||
return page;
|
||||
}
|
||||
|
||||
export function waitUntilNavigatedFrom(oldPage: Page) {
|
||||
export function waitUntilNavigatedFrom(action: Function) {
|
||||
const currentPage = frame.topmost().currentPage;
|
||||
let completed = false;
|
||||
function navigatedFrom(args) {
|
||||
args.object.page.off("navigatedFrom", navigatedFrom);
|
||||
completed = true;
|
||||
}
|
||||
|
||||
oldPage.on("navigatedFrom", navigatedFrom);
|
||||
currentPage.on("navigatedFrom", navigatedFrom);
|
||||
action();
|
||||
TKUnit.waitUntilReady(() => completed);
|
||||
}
|
||||
|
||||
@@ -168,22 +170,18 @@ export function waitUntilLayoutReady(view: View): void {
|
||||
}
|
||||
|
||||
export function navigateWithEntry(entry: frame.NavigationEntry): Page {
|
||||
let page = frame.resolvePageFromEntry(entry);
|
||||
const page = frame.resolvePageFromEntry(entry);
|
||||
entry.moduleName = null;
|
||||
entry.create = function () {
|
||||
return page;
|
||||
};
|
||||
|
||||
let currentPage = getCurrentPage();
|
||||
frame.topmost().navigate(entry);
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
waitUntilNavigatedFrom(() => frame.topmost().navigate(entry));
|
||||
return page;
|
||||
}
|
||||
|
||||
export function goBack() {
|
||||
let currentPage = getCurrentPage();
|
||||
frame.topmost().goBack();
|
||||
waitUntilNavigatedFrom(currentPage);
|
||||
waitUntilNavigatedFrom(() => frame.topmost().goBack());
|
||||
}
|
||||
|
||||
export function assertAreClose(actual: number, expected: number, message: string): void {
|
||||
|
||||
@@ -5,6 +5,7 @@ import * as testModule from "../../ui-test";
|
||||
import * as layoutHelper from "../layouts/layout-helper";
|
||||
import { Page } from "tns-core-modules/ui/page";
|
||||
import * as frame from "tns-core-modules/ui/frame";
|
||||
import * as helper from "../helper";
|
||||
|
||||
// >> article-require-scrollview-module
|
||||
import * as scrollViewModule from "tns-core-modules/ui/scroll-view";
|
||||
@@ -154,15 +155,8 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
this.testView.scrollToVerticalOffset(layoutHelper.dp(100), false);
|
||||
TKUnit.assertAreClose(layoutHelper.dip(this.testView.verticalOffset), 100, 0.1, "this.testView.verticalOffset before navigation");
|
||||
|
||||
let page = new Page();
|
||||
let createFunc = () => {
|
||||
return page;
|
||||
};
|
||||
|
||||
let entry: frame.NavigationEntry = { create: createFunc, animated: false };
|
||||
frame.topmost().navigate(entry);
|
||||
TKUnit.waitUntilReady(() => page.isLayoutValid);
|
||||
frame.topmost().goBack();
|
||||
helper.navigateWithHistory(() => new Page());
|
||||
helper.goBack();
|
||||
|
||||
// Wait for the page to reload.
|
||||
TKUnit.waitUntilReady(() => { return TKUnit.areClose(layoutHelper.dip(this.testView.verticalOffset), 100, 0.1); });
|
||||
@@ -178,19 +172,8 @@ class ScrollLayoutTest extends testModule.UITest<scrollViewModule.ScrollView> {
|
||||
this.testView.scrollToHorizontalOffset(layoutHelper.dp(100), false);
|
||||
|
||||
TKUnit.assertAreClose(layoutHelper.dip(this.testView.horizontalOffset), 100, 0.1, "this.testView.horizontalOffset before navigation");
|
||||
|
||||
let page = new Page();
|
||||
let createFunc = () => {
|
||||
return page;
|
||||
};
|
||||
|
||||
let entry: frame.NavigationEntry = { create: createFunc, animated: false };
|
||||
frame.topmost().navigate(entry);
|
||||
TKUnit.waitUntilReady(() => page.isLayoutValid);
|
||||
frame.topmost().goBack();
|
||||
|
||||
// Wait for the page to reload.
|
||||
TKUnit.waitUntilReady(() => { return TKUnit.areClose(layoutHelper.dip(this.testView.horizontalOffset), 100, 0.1); });
|
||||
helper.navigateWithHistory(() => new Page());
|
||||
helper.goBack();
|
||||
|
||||
// Check verticalOffset after navigation
|
||||
TKUnit.assertAreClose(layoutHelper.dip(this.testView.horizontalOffset), 100, 0.1, "this.testView.horizontalOffset after navigation");
|
||||
|
||||
Reference in New Issue
Block a user