From 329ba3a2c5fe7ff69b3b28c32b7b966f0e1c69bb Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Mon, 16 Jan 2017 19:04:21 +0200 Subject: [PATCH] Page tests fix. --- tests/app/testRunner.ts | 2 +- tests/app/ui/page/page-tests-common.ts | 10 ++++++++-- tests/app/ui/page/page-tests.android.ts | 4 ++-- tests/app/ui/page/page-tests.ios.ts | 2 +- tns-core-modules/ui/core/view-common.ts | 6 +++++- tns-core-modules/ui/page/page-common.ts | 6 +----- tns-core-modules/ui/page/page.android.ts | 6 ++++++ tns-core-modules/ui/page/page.ios.ts | 9 +++++++-- 8 files changed, 31 insertions(+), 14 deletions(-) diff --git a/tests/app/testRunner.ts b/tests/app/testRunner.ts index 6387c2d1a..2b2f2eedd 100644 --- a/tests/app/testRunner.ts +++ b/tests/app/testRunner.ts @@ -81,7 +81,7 @@ allTests["SLIDER"] = require("./ui/slider/slider-tests"); allTests["SWITCH"] = require("./ui/switch/switch-tests"); allTests["PROGRESS"] = require("./ui/progress/progress-tests"); allTests["PLACEHOLDER"] = require("./ui/placeholder/placeholder-tests"); -// allTests["PAGE"] = require("./ui/page/page-tests"); +allTests["PAGE"] = require("./ui/page/page-tests"); allTests["LISTVIEW"] = require("./ui/list-view/list-view-tests"); allTests["ACTIVITY-INDICATOR"] = require("./ui/activity-indicator/activity-indicator-tests"); allTests["TEXT-FIELD"] = require("./ui/text-field/text-field-tests"); diff --git a/tests/app/ui/page/page-tests-common.ts b/tests/app/ui/page/page-tests-common.ts index 4fe829381..327a221ea 100644 --- a/tests/app/ui/page/page-tests-common.ts +++ b/tests/app/ui/page/page-tests-common.ts @@ -23,6 +23,7 @@ import { EventData } from "data/observable"; import { PercentLength } from "ui/core/view"; import * as platform from "platform"; import {unsetValue} from "ui/core/view"; +import { Color } from "color"; export function addLabelToPage(page: Page, text?: string) { let label = new Label(); @@ -122,7 +123,7 @@ export function test_NavigateToNewPage() { TKUnit.waitUntilReady(() => { return topFrame.currentPage !== null && topFrame.currentPage === currentPage }); TKUnit.assert(testPage.parent === undefined, "Page.parent should become undefined after navigating back"); - TKUnit.assert(testPage._context === undefined, "Page._context should become undefined after navigating back"); + TKUnit.assert(testPage._context === null, "Page._context should become undefined after navigating back"); TKUnit.assert(testPage.isLoaded === false, "Page.isLoaded should become false after navigating back"); TKUnit.assert(testPage.frame === undefined, "Page.frame should become undefined after navigating back"); TKUnit.assert(testPage._isAddedToNativeVisualTree === false, "Page._isAddedToNativeVisualTree should become false after navigating back"); @@ -376,7 +377,12 @@ export function test_page_backgroundColor_is_white() { page.id = "page_test_page_backgroundColor_is_white"; let factory = () => page; helper.navigate(factory); - TKUnit.assertEqual(page.style.backgroundColor.hex.toLowerCase(), "#ffffff", "page background-color"); + let whiteColor = new Color("white"); + if (platform.isIOS) { + TKUnit.assertTrue(whiteColor.ios.CGColor.isEqual(page.nativeView.backgroundColor.CGColor), "page default backgroundColor should be white"); + } else { + TKUnit.assertEqual(page.nativeView.getBackground().getColor(), whiteColor.android, "page default backgroundColor should be white"); + } } export function test_WhenPageIsLoadedFrameCurrentPageIsNotYetTheSameAsThePage() { diff --git a/tests/app/ui/page/page-tests.android.ts b/tests/app/ui/page/page-tests.android.ts index 73857c435..766d506ee 100644 --- a/tests/app/ui/page/page-tests.android.ts +++ b/tests/app/ui/page/page-tests.android.ts @@ -48,7 +48,7 @@ export function test_NavigateToNewPage_WithAndroidCache() { TKUnit.assert(testPage.frame === undefined, "Page.frame should become undefined after navigating back"); TKUnit.assert(testPage._isAddedToNativeVisualTree === false, "Page._isAddedToNativeVisualTree should become false after navigating back"); - TKUnit.assert(label._context === undefined, "InnerControl._context should not be set after navigate back."); + TKUnit.assert(label._context === null, "InnerControl._context should not be set after navigate back."); TKUnit.assert(label.android === undefined, "InnerControl.android should not be set after navigate back."); TKUnit.assert(label._nativeView === undefined, "InnerControl._nativeView hould not be set after navigate back."); TKUnit.assert(label.isLoaded === false, "InnerControl.isLoaded should become false after navigating back"); @@ -69,7 +69,7 @@ export var test_NavigateToNewPage_InnerControl = function () { var label = testPage.content; - TKUnit.assert(label._context === undefined, "InnerControl._context should be undefined after navigate back."); + TKUnit.assert(label._context === null, "InnerControl._context should be undefined after navigate back."); TKUnit.assert(label.android === undefined, "InnerControl.android should be undefined after navigate back."); TKUnit.assert(label._nativeView === undefined, "InnerControl._nativeView should be undefined after navigate back."); TKUnit.assert(label.isLoaded === false, "InnerControl.isLoaded should become false after navigating back"); diff --git a/tests/app/ui/page/page-tests.ios.ts b/tests/app/ui/page/page-tests.ios.ts index 129b25302..5b68d04b1 100644 --- a/tests/app/ui/page/page-tests.ios.ts +++ b/tests/app/ui/page/page-tests.ios.ts @@ -23,7 +23,7 @@ export function test_NavigateToNewPage_InnerControl() { helper.goBack(); - TKUnit.assertEqual(label._context, undefined, "label._context should be undefined after navigate back."); + TKUnit.assertEqual(label._context, null, "label._context should be undefined after navigate back."); TKUnit.assertEqual(label.android, undefined, "label.android should be undefined after navigate back."); TKUnit.assertFalse(label.isLoaded, "label.isLoaded should become false after navigating back"); } diff --git a/tns-core-modules/ui/core/view-common.ts b/tns-core-modules/ui/core/view-common.ts index e78954241..e4e30cca4 100644 --- a/tns-core-modules/ui/core/view-common.ts +++ b/tns-core-modules/ui/core/view-common.ts @@ -1485,7 +1485,11 @@ function convertToTransform(value: string): [CssProperty, any][] { } // Background properties. -export const backgroundInternalProperty = new CssProperty({ name: "backgroundInternal", cssName: "_backgroundInternal", defaultValue: Background.default }); +export const backgroundInternalProperty = new CssProperty({ + name: "backgroundInternal", + cssName: "_backgroundInternal", + defaultValue: Background.default +}); backgroundInternalProperty.register(Style); let pattern: RegExp = /url\(('|")(.*?)\1\)/; diff --git a/tns-core-modules/ui/page/page-common.ts b/tns-core-modules/ui/page/page-common.ts index 9f47133f5..a83218e1a 100644 --- a/tns-core-modules/ui/page/page-common.ts +++ b/tns-core-modules/ui/page/page-common.ts @@ -1,7 +1,6 @@ import { Page as PageDefinition, NavigatedData, ShownModallyData } from "ui/page"; import { - ContentView, View, backgroundColorProperty, - eachDescendant, Property, Color, isIOS, booleanConverter, resetCSSProperties + ContentView, View, eachDescendant, Property, Color, isIOS, booleanConverter, resetCSSProperties } from "ui/content-view"; import { Frame, topmost as topmostFrame, resolvePageFromEntry } from "ui/frame"; import { ActionBar } from "ui/action-bar"; @@ -41,9 +40,6 @@ export class PageBase extends ContentView implements PageDefinition { constructor() { super(); this.actionBar = new ActionBar(); - - // The default style of the page should be white background - this.style[backgroundColorProperty.cssName] = new Color("white"); } // public onLoaded() { diff --git a/tns-core-modules/ui/page/page.android.ts b/tns-core-modules/ui/page/page.android.ts index 82981eacf..02b2c2b57 100644 --- a/tns-core-modules/ui/page/page.android.ts +++ b/tns-core-modules/ui/page/page.android.ts @@ -92,10 +92,15 @@ export class Page extends PageBase { return this._grid; } + get nativeView(): android.view.ViewGroup { + return this._grid; + } + public _createNativeView() { this._grid = new org.nativescript.widgets.GridLayout(this._context); this._grid.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.auto)); this._grid.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.star)); + this.nativeView.setBackgroundColor(new Color("white").android); } public _addViewToNativeVisualTree(child: View, atIndex?: number): boolean { @@ -126,6 +131,7 @@ export class Page extends PageBase { if (!skipDetached) { super._tearDownUI(); + this._isAddedToNativeVisualTree = false; } } diff --git a/tns-core-modules/ui/page/page.ios.ts b/tns-core-modules/ui/page/page.ios.ts index 7cdfa8848..5a96a0601 100644 --- a/tns-core-modules/ui/page/page.ios.ts +++ b/tns-core-modules/ui/page/page.ios.ts @@ -5,6 +5,7 @@ } from "./page-common"; import { ios as iosApp } from "application"; import { device } from "platform"; +import { Color } from "color"; import * as uiUtils from "ui/utils"; export * from "./page-common"; @@ -115,9 +116,9 @@ class UIViewControllerImpl extends UIViewController { let widthSpec = layout.makeMeasureSpec(width, mode); let heightSpec = layout.makeMeasureSpec(height, mode); - View.measureChild(null, owner, widthSpec, heightSpec); + View.measureChild(owner._modalParent, owner, widthSpec, heightSpec); let top = ((backgroundSpanUnderStatusBar && isFullScreen) || ios.MajorVersion < 8 || !isFullScreen) ? 0 : statusBarHeight; - View.layoutChild(null, owner, 0, top, width, bottom); + View.layoutChild(owner._modalParent, owner, 0, top, width, bottom); if (ios.MajorVersion < 8) { if (!backgroundSpanUnderStatusBar && (!isTablet || isFullScreen)) { @@ -339,6 +340,7 @@ export class Page extends PageBase { super(); this._ios = UIViewControllerImpl.initWithOwner(new WeakRef(this)); this.nativeView = this._ios.view; + this.nativeView.backgroundColor = new Color("white").ios; } public requestLayout(): void { @@ -582,6 +584,9 @@ export class Page extends PageBase { } set [actionBarHiddenProperty.native](value: boolean) { this._updateEnableSwipeBackNavigation(value); + if (this.isLoaded) { + this.updateActionBar(value); + } } get [statusBarStyleProperty.native](): UIBarStyle {