Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/app/navigation-app/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.btn1 {
background-color: lightgreen;
color: coral;
font-size: 20;
font-family: monospace;
}

.btn2 {
background-color: coral;
color: lightgreen;
font-size: 24;
font-family: serif;
}
12 changes: 12 additions & 0 deletions apps/app/navigation-app/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as application from "tns-core-modules/application";
import * as trace from "tns-core-modules/trace";
trace.addCategories(
trace.categories.Transition)
// + "," +
// trace.categories.NativeLifecycle + "," +
// trace.categories.Navigation);
trace.enable();

// Needed only for build infrastructure
application.setCssFileName("navigation-app/app.css");
application.start({ moduleName: "navigation-app/main-page" });
69 changes: 69 additions & 0 deletions apps/app/navigation-app/main-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { EventData } from 'tns-core-modules/data/observable';
import { Page, NavigatedData } from 'tns-core-modules/ui/page';
import { topmost, NavigationEntry } from 'tns-core-modules/ui/frame';

export function nav() {
const e: NavigationEntry = {
moduleName: "navigation-app/main-page"
}
topmost().navigate(e)
}
export function navClearTrans() {
console.log("transition and clear")

const e: NavigationEntry = {
transition: {
name: "slideLeft",
curve: "linear"
},
clearHistory: true,
moduleName: "navigation-app/main-page"
}
topmost().navigate(e)
}

export function navWithTransition() {
const e: NavigationEntry = {
transition: {
name: "slideLeft",
curve: "linear"
},
moduleName: "navigation-app/main-page"
}
topmost().navigate(e)
}

export function navWithClear() {
const e: NavigationEntry = {
clearHistory: true,
moduleName: "navigation-app/main-page"
}
topmost().navigate(e)
}

let i = 0;
const colors = ["lightgreen", "lightblue", "lightcoral"]

export function navigatedFrom(args: NavigatedData) {
console.log(`navigatedFrom ${args.object.toString()} isBack: ${args.isBackNavigation}`)
}

export function navigatedTo(args: NavigatedData) {
console.log(`navigatedTo ${args.object.toString()} isBack: ${args.isBackNavigation}`)
}

export function navigatingTo(args: NavigatedData) {
if (!args.isBackNavigation) {
(<any>args.object).page.backgroundColor = colors[(i++) % 3];
const array = new Array();
for (let i = 0; i < 50; i++) {
array[i] = i;
}
(<any>args.object).page.bindingContext = array;
}
console.log(`navigatingTo ${args.object.toString()} isBack: ${args.isBackNavigation}`)
}

export function navigatingFrom(args: NavigatedData) {
console.log(`navigatingFrom ${args.object.toString()} isBack: ${args.isBackNavigation}`)
}
13 changes: 13 additions & 0 deletions apps/app/navigation-app/main-page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
navigatingTo="navigatingTo"
navigatingFrom="navigatingFrom"
navigatedTo="navigatedTo"
navigatedFrom="navigatedFrom">
<StackLayout>
<Button text="Nav" tap="nav" />
<Button text="Clear history Trans" tap="navClearTrans" />
<Button text="Nav Transition" tap="navWithTransition" />
<Button text="Nav Clear" tap="navWithClear" />
<ListView items="{{ $value }}" />
</StackLayout>
</Page>
16 changes: 7 additions & 9 deletions tests/app/ui/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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 {
Expand Down
27 changes: 5 additions & 22 deletions tests/app/ui/scroll-view/scroll-view-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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); });
Expand All @@ -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");
Expand Down
9 changes: 7 additions & 2 deletions tns-core-modules/ui/frame/fragment.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ class FragmentClass extends android.app.Fragment {
}

public toString(): string {
return this._callbacks.toStringOverride(this, super.toString);
const callbacks = this._callbacks;
if (callbacks) {
return callbacks.toStringOverride(this, super.toString);
} else {
super.toString();
}
}
}

setFragmentClass(FragmentClass);
setFragmentClass(FragmentClass);
Loading