Skip to content

Commit ac04ede

Browse files
Hristo HristovHristo Hristov
authored andcommitted
Implemented showModal on View
1 parent 04c1132 commit ac04ede

37 files changed

+1958
-1511
lines changed

tests/app/ui/frame/frame-tests-common.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,80 @@ export function test_go_back_to_backstack_entry() {
147147
TKUnit.assertFalse(frame.canGoBack(), '2');
148148
frame.goBack();
149149
TKUnit.waitUntilReady(() => frame.navigationQueueIsEmpty());
150+
}
151+
152+
export function test_page_parent_when_backstackVisible_is_false() {
153+
const frame = topmost();
154+
155+
const pages = new Array<Page>();
156+
const create = () => {
157+
const page = new Page();
158+
pages.push(page);
159+
return page;
160+
};
161+
162+
frame.navigate({ create: () => new Page(), clearHistory: true });
163+
frame.navigate({ create, backstackVisible: false });
164+
frame.navigate(() => new Page());
165+
TKUnit.waitUntilReady(() => frame.navigationQueueIsEmpty());
166+
167+
TKUnit.assertEqual(pages.length, 1);
168+
TKUnit.assertEqual(frame.backStack.length, 1);
169+
pages.forEach(p => {
170+
TKUnit.assertNull(p.parent);
171+
TKUnit.assertNull(p.frame);
172+
});
173+
174+
pages.length = 0;
175+
}
176+
177+
export function test_page_parent_when_navigate_with_clear_history() {
178+
const frame = topmost();
179+
180+
const pages = new Array<Page>();
181+
const create = () => {
182+
const page = new Page();
183+
pages.push(page);
184+
return page;
185+
};
186+
187+
frame.navigate({ create });
188+
frame.navigate({ create, backstackVisible: false });
189+
frame.navigate({ create });
190+
frame.navigate({ create: () => new Page(), clearHistory: true });
191+
TKUnit.waitUntilReady(() => frame.navigationQueueIsEmpty());
192+
193+
TKUnit.assertEqual(pages.length, 3);
194+
TKUnit.assertEqual(frame.backStack.length, 0);
195+
pages.forEach(p => {
196+
TKUnit.assertNull(p.parent);
197+
TKUnit.assertNull(p.frame);
198+
});
199+
200+
pages.length = 0;
201+
}
202+
203+
export function test_page_parent_when_navigate_back() {
204+
const frame = topmost();
205+
206+
const pages = new Array<Page>();
207+
const create = () => {
208+
const page = new Page();
209+
pages.push(page);
210+
return page;
211+
};
212+
213+
frame.navigate({ create: () => new Page(), clearHistory: true });
214+
frame.navigate({ create });
215+
frame.goBack();
216+
TKUnit.waitUntilReady(() => frame.navigationQueueIsEmpty());
217+
218+
TKUnit.assertEqual(pages.length, 1);
219+
TKUnit.assertEqual(frame.backStack.length, 0);
220+
pages.forEach(p => {
221+
TKUnit.assertNull(p.parent);
222+
TKUnit.assertNull(p.frame);
223+
});
224+
225+
pages.length = 0;
150226
}

tests/app/ui/helper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { FlexboxLayout } from "tns-core-modules/ui/layouts/flexbox-layout";
1313
import { FormattedString, Span } from "tns-core-modules/text/formatted-string";
1414
import { _getProperties, _getStyleProperties } from "tns-core-modules/ui/core/properties";
1515
import { device } from "tns-core-modules/platform";
16+
// TODO: Remove this and get it from global to decouple builder for angular
17+
import { createViewFromEntry } from "tns-core-modules/ui/builder";
1618

1719
const DELTA = 0.1;
1820
const sdkVersion = parseInt(device.sdkVersion);
@@ -170,7 +172,7 @@ export function waitUntilLayoutReady(view: View): void {
170172
}
171173

172174
export function navigateWithEntry(entry: frame.NavigationEntry): Page {
173-
const page = frame.resolvePageFromEntry(entry);
175+
const page = createViewFromEntry(entry) as Page;
174176
entry.moduleName = null;
175177
entry.create = function () {
176178
return page;

tests/app/ui/page/page-tests-common.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { Page, ShownModallyData, NavigatedData } from "tns-core-modules/ui/page"
44
import { topmost, NavigationEntry } from "tns-core-modules/ui/frame";
55
// << article-require-page-module
66

7-
import { resolvePageFromEntry } from "tns-core-modules/ui/frame";
7+
// TODO: Remove this and get it from global to decouple builder for angular
8+
import { createViewFromEntry } from "tns-core-modules/ui/builder";
89

910
// >> article-set-bindingcontext
1011
function pageLoaded(args) {
@@ -508,12 +509,12 @@ export function test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal() {
508509
moduleName: basePath + "modal-page"
509510
};
510511

511-
modalPage = <Page>resolvePageFromEntry(entry);
512+
modalPage = createViewFromEntry(entry) as Page;
512513
modalPage.on(Page.shownModallyEvent, onShownModal);
513514
modalPage.on(Page.loadedEvent, onModalLoaded);
514515
modalPage.on(Page.unloadedEvent, onModalUnloaded);
515516

516-
page.showModal(modalPage, ctx, modalCloseCallback, false);
517+
page.showModal(modalPage, ctx, modalCloseCallback, false, false);
517518
TKUnit.assertTrue((<any>modalPage).showingModally, "showingModally");
518519
};
519520

tests/app/ui/page/page-tests.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@ export var test_Resolve_Fragment_ForPage = function () {
105105
frame.navigate(pageFactory);
106106
TKUnit.waitUntilReady(() => frame.navigationQueueIsEmpty());
107107

108-
const fragment = frame.android.fragmentForPage(testPage);
108+
const fragment = frame.android.fragmentForPage(frame._currentEntry);
109109
TKUnit.assertNotNull(fragment, "Failed to resolve native fragment for page");
110110
}

tests/app/ui/page/page-tests.ios.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function test_WhenShowingModalPageUnloadedIsNotFiredForTheMasterPage() {
4242

4343
var navigatedToEventHandler = function (args) {
4444
var basePath = "ui/page/";
45-
modalPage = masterPage.showModal(basePath + "modal-page", null, null, false);
45+
modalPage = masterPage.showModal(basePath + "modal-page", null, null, false) as Page;
4646
modalPage.on(Page.unloadedEvent, onModalUnloaded);
4747
};
4848

@@ -80,6 +80,7 @@ function getNativeHeight(view: View): number {
8080

8181
export function test_correct_layout_scrollable_content_false() {
8282
const page = new Page();
83+
topmost().viewController.navigationBar.translucent = true;
8384
(<any>page).scrollableContent = false;
8485
page.actionBar.title = "ActionBar";
8586
page.actionBarHidden = true;
@@ -127,6 +128,7 @@ export function test_correct_layout_scrollable_content_false() {
127128

128129
export function test_correct_layout_scrollable_content_true() {
129130
const page = new Page();
131+
topmost().viewController.navigationBar.translucent = true;
130132
(<any>page).scrollableContent = true;
131133
page.actionBar.title = "ActionBar";
132134
page.actionBarHidden = true;
@@ -196,6 +198,7 @@ export function test_correct_layout_scrollable_content_true_flat_action_bar() {
196198
const contentHeight = getHeight(lbl);
197199
const expectedLabelHeight = screenHeight - statusBarHeight - navBarHeight - tabBarHeight;
198200
TKUnit.assertEqual(contentHeight, expectedLabelHeight, "lbl.height !== screenHeight - statusBar - navBarHeight - tabBarHeight");
201+
page.actionBar.flat = false;
199202
}
200203

201204
export function test_correct_layout_scrollable_content_true_flat_action_bar_edges_span_under_opaque_bars() {
@@ -235,6 +238,7 @@ export function test_correct_layout_scrollable_content_true_flat_action_bar_edge
235238

236239
const contentHeight = getHeight(lbl);
237240
TKUnit.assertEqual(contentHeight, screenHeight, "lbl.height !== screenHeight");
241+
page.actionBar.flat = false;
238242
}
239243

240244
export function test_correct_layout_scrollable_content_true_top_edge_does_not_span() {
@@ -266,12 +270,15 @@ export function test_correct_layout_scrollable_content_true_top_edge_does_not_sp
266270

267271
const contentHeight = getHeight(lbl);
268272
TKUnit.assertEqual(contentHeight, expectedPageHeight, "lbl.height !== screenHeight - statusBar - navBarHeight");
273+
(<UIViewController>page.viewController).edgesForExtendedLayout = UIRectEdge.All;
269274
}
270275

271276
export function test_correct_layout_scrollable_content_true_bottom_edge_does_not_span() {
272277
const page = new Page();
273278
(<any>page).scrollableContent = true;
274279
page.actionBar.title = "ActionBar";
280+
page.viewController.automaticallyAdjustsScrollViewInsets = false;
281+
(<UIViewController>page.viewController).edgesForExtendedLayout = UIRectEdge.All;
275282

276283
const tabView = new TabView();
277284
const tabItem = new TabViewItem();

tests/app/ui/styling/style-tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export function test_css_is_applied_inside_TabView() {
112112
helper.buildUIAndRunTest(tabView, function (views: Array<viewModule.View>) {
113113
const page = <pageModule.Page>views[1];
114114
page.css = "button { color: red; }";
115+
TKUnit.waitUntilReady(() => testButton.isLoaded);
115116
helper.assertViewColor(testButton, "#FF0000");
116117
});
117118
}

tests/app/ui/tab-view/tab-view-navigation-tests.ts

Lines changed: 33 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as TKUnit from "../../TKUnit";
22
import * as helper from "../helper";
3-
import {Label} from "tns-core-modules/ui/label";
4-
import {StackLayout} from "tns-core-modules/ui/layouts/stack-layout";
3+
import { Label } from "tns-core-modules/ui/label";
4+
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
55
import * as frameModule from "tns-core-modules/ui/frame";
6-
import {Page} from "tns-core-modules/ui/page";
7-
import {ListView, ItemEventData} from "tns-core-modules/ui/list-view";
8-
import {TabView, TabViewItem} from "tns-core-modules/ui/tab-view";
9-
import {Button} from "tns-core-modules/ui/button";
6+
import { Page } from "tns-core-modules/ui/page";
7+
import { ListView, ItemEventData } from "tns-core-modules/ui/list-view";
8+
import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view";
9+
import { Button } from "tns-core-modules/ui/button";
1010

1111
var ASYNC = 2;
1212

@@ -96,7 +96,7 @@ export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithALis
9696
tabViewitem.title = "About";
9797
tabViewitem.view = aboutLayout;
9898
items.push(tabViewitem);
99-
99+
100100
tabView.items = items;
101101

102102
tabViewPage = new Page();
@@ -114,13 +114,12 @@ export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithALis
114114

115115
// This will navigate to a details page. The wait is inside the method.
116116
_clickTheFirstButtonInTheListViewNatively(tabView);
117-
TKUnit.waitUntilReady(() => topFrame.currentPage.id === "details-page");
118117

119118
frameModule.goBack();
120-
TKUnit.waitUntilReady(() => topFrame.currentPage === tabViewPage);
121-
TKUnit.waitUntilReady(() => tabViewIsFullyLoaded(tabView));
119+
TKUnit.waitUntilReady(() => topFrame.navigationQueueIsEmpty());//() => topFrame.currentPage === tabViewPage);
122120

123121
frameModule.goBack();
122+
124123
TKUnit.waitUntilReady(() => topFrame.currentPage === rootPage);
125124

126125
if (topFrame.android) {
@@ -130,23 +129,14 @@ export function testWhenNavigatingBackToANonCachedPageContainingATabViewWithALis
130129
TKUnit.assert(tabView.items[0].view instanceof ListView, "ListView should be created when navigating back to the main page.");
131130
}
132131

133-
export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack_NoPageCaching() {
134-
testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack(false);
135-
}
136-
137-
export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack_WithPageCaching() {
138-
testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack(true);
139-
}
140-
141132
function tabViewIsFullyLoaded(tabView: TabView): boolean {
142133
if (!tabView.isLoaded) {
143134
return false;
144135
}
145136

146-
for (var i = 0; i < tabView.items.length; i++) {
147-
if (!tabView.items[i].view.isLoaded) {
148-
return false;
149-
}
137+
const i = tabView.selectedIndex;
138+
if (i >= 0 && !tabView.items[i].isLoaded) {
139+
return false;
150140
}
151141

152142
if (tabView.android) {
@@ -159,33 +149,17 @@ function tabViewIsFullyLoaded(tabView: TabView): boolean {
159149
return true;
160150
}
161151

162-
function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack(enablePageCache: boolean) {
152+
export function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack() {
163153
let topFrame = frameModule.topmost();
164154
let rootPage = helper.getCurrentPage();
165155

166-
let oldChache;
167-
if (topFrame.android) {
168-
oldChache = topFrame.android.cachePagesOnNavigate;
169-
topFrame.android.cachePagesOnNavigate = enablePageCache;
170-
}
171-
172156
let itemCount = 2;
173157
let loadedEventsCount = [0, 0];
174158
let unloadedEventsCount = [0, 0];
175159

176-
let tabView = _createTabView();
160+
const tabView = _createTabView();
177161
tabView.items = _createItems(itemCount);
178162

179-
let tabViewPage: Page;
180-
helper.navigateWithHistory(() => {
181-
tabViewPage = new Page();
182-
tabViewPage.content = tabView;
183-
return tabViewPage;
184-
});
185-
186-
TKUnit.waitUntilReady(() => topFrame.currentPage === tabViewPage, ASYNC);
187-
TKUnit.waitUntilReady(() => tabViewIsFullyLoaded(tabView), ASYNC);
188-
189163
function createLoadedFor(tabIndex: number) {
190164
return function () {
191165
loadedEventsCount[tabIndex] = loadedEventsCount[tabIndex] + 1;
@@ -198,43 +172,37 @@ function testLoadedAndUnloadedAreFired_WhenNavigatingAwayAndBack(enablePageCache
198172
}
199173
}
200174

201-
for (let i = 0; i < itemCount; i++) {
202-
tabView.items[i].view.on("loaded", createLoadedFor(i));
203-
tabView.items[i].view.on("unloaded", createUnloadedFor(i));
204-
}
205-
206-
let detailsPage = new Page();
207-
208-
let createFunc = () => {
209-
return detailsPage;
210-
};
175+
tabView.items.forEach((item, i) => {
176+
item.view.on("loaded", createLoadedFor(i));
177+
item.view.on("unloaded", createUnloadedFor(i));
178+
});
211179

212-
let entry: frameModule.NavigationEntry = { create: createFunc, animated: false };
213-
topFrame.navigate(entry);
180+
const tabViewPage = new Page();
181+
helper.navigateWithHistory(() => {
182+
tabViewPage.content = tabView;
183+
return tabViewPage;
184+
});
185+
TKUnit.waitUntilReady(() => tabViewIsFullyLoaded(tabView), ASYNC);
214186

215-
TKUnit.waitUntilReady(() => topFrame.currentPage === detailsPage);
187+
const detailsPage = new Page();
188+
helper.navigateWithHistory(() => detailsPage);
189+
TKUnit.assertEqual(topFrame.currentPage, detailsPage);
216190

217-
topFrame.goBack();
218-
TKUnit.waitUntilReady(() => topFrame.currentPage === tabViewPage);
219-
TKUnit.waitUntilReady(() => tabViewIsFullyLoaded(tabView));
191+
helper.goBack();
192+
TKUnit.assertEqual(topFrame.currentPage, tabViewPage);
220193

221194
for (let i = 0; i < itemCount; i++) {
222195
tabView.items[i].view.off("loaded");
223196
tabView.items[i].view.off("unloaded");
224197
}
225198

226-
topFrame.goBack();
227-
228-
TKUnit.waitUntilReady(() => topFrame.currentPage === rootPage);
229-
230-
if (topFrame.android) {
231-
topFrame.android.cachePagesOnNavigate = oldChache;
232-
}
199+
helper.goBack();
200+
TKUnit.assertEqual(topFrame.currentPage, rootPage);
233201

234202
topFrame.currentPage.id = null;
235203

236-
TKUnit.arrayAssert(loadedEventsCount, [1, 1]);
237-
TKUnit.arrayAssert(unloadedEventsCount, [1, 1]);
204+
TKUnit.arrayAssert(loadedEventsCount, [2, 0]);
205+
TKUnit.arrayAssert(unloadedEventsCount, [1, 0]);
238206
}
239207

240208
function _clickTheFirstButtonInTheListViewNatively(tabView: TabView) {

0 commit comments

Comments
 (0)