diff --git a/tests/app/testRunner.ts b/tests/app/testRunner.ts index 789b5bd0d..89ff77777 100644 --- a/tests/app/testRunner.ts +++ b/tests/app/testRunner.ts @@ -65,7 +65,7 @@ allTests["STACKLAYOUT"] = require("./ui/layouts/stack-layout-tests"); allTests["FLEXBOXLAYOUT"] = require("./ui/layouts/flexbox-layout-tests"); allTests["STYLE-PROPERTIES"] = require("./ui/styling/style-properties-tests"); allTests["FRAME"] = require("./ui/frame/frame-tests"); -// allTests["VIEW"] = require("./ui/view/view-tests"); +allTests["VIEW"] = require("./ui/view/view-tests"); // allTests["STYLE"] = require("./ui/styling/style-tests"); // allTests["VISUAL-STATE"] = require("./ui/styling/visual-state-tests"); // allTests["VALUE-SOURCE"] = require("./ui/styling/value-source-tests"); diff --git a/tests/app/ui/helper.ts b/tests/app/ui/helper.ts index 47c1cd466..36a1258e6 100644 --- a/tests/app/ui/helper.ts +++ b/tests/app/ui/helper.ts @@ -10,6 +10,7 @@ import * as colorModule from "color"; import * as formattedStringModule from "text/formatted-string"; import * as spanModule from "text/span"; import * as enums from "ui/enums"; +import { ActionBar } from "ui/action-bar"; import { unsetValue } from "ui/core/view"; var DELTA = 0.1; @@ -35,7 +36,7 @@ function clearPage(): void { newPage.id = unsetValue; } -export function do_PageTest(test: (views: Array) => void, content: view.View, secondView: view.View, thirdView: view.View) { +export function do_PageTest(test: (views: [page.Page, view.View, view.View, view.View, ActionBar]) => void, content: view.View, secondView: view.View, thirdView: view.View) { clearPage(); let newPage = getCurrentPage(); newPage.content = content; @@ -43,7 +44,7 @@ export function do_PageTest(test: (views: Array) => void, content: vi newPage.content = null; } -export function do_PageTest_WithButton(test: (views: Array) => void) { +export function do_PageTest_WithButton(test: (views: [page.Page, button.Button, ActionBar]) => void) { clearPage(); let newPage = getCurrentPage(); let btn = new button.Button(); @@ -52,7 +53,7 @@ export function do_PageTest_WithButton(test: (views: Array) => void) newPage.content = null; } -export function do_PageTest_WithStackLayout_AndButton(test: (views: Array) => void) { +export function do_PageTest_WithStackLayout_AndButton(test: (views: [page.Page, stackLayoutModule.StackLayout, button.Button, ActionBar]) => void) { clearPage(); let newPage = getCurrentPage(); let stackLayout = new stackLayoutModule.StackLayout(); @@ -64,7 +65,7 @@ export function do_PageTest_WithStackLayout_AndButton(test: (views: Array(controlToTest: T, testFunction: (views: [T, page.Page]) => void, pageCss?) { clearPage(); let newPage = getCurrentPage(); newPage.content = controlToTest; @@ -92,9 +93,9 @@ export function buildUIWithWeakRefAndInteract(createFunc: ( } sp.removeChild(weakRef.get()); - + TKUnit.wait(1); // Wait for the TextField/TextView to close its keyboard so it can be released. - + if (newPage.ios) { /* tslint:disable:no-unused-expression */ // Could cause GC on the next call. @@ -115,7 +116,7 @@ export function buildUIWithWeakRefAndInteract(createFunc: ( newPage.content = sp; TKUnit.waitUntilReady(() => testFinished, MEMORY_ASYNC); - TKUnit.assertTrue(testFinished, "Test did not completed.") + TKUnit.assertTrue(testFinished, "Test did not completed."); done(null); } @@ -162,7 +163,7 @@ export function navigateWithEntry(entry: frame.NavigationEntry): page.Page { entry.moduleName = null; entry.create = function () { return page; - } + }; let currentPage = getCurrentPage(); frame.topmost().navigate(entry); @@ -177,8 +178,8 @@ export function goBack() { } export function assertAreClose(actual: number, expected: number, message: string): void { - var density = utils.layout.getDisplayDensity(); - var delta = Math.floor(density) !== density ? 1.1 : DELTA; + const density = utils.layout.getDisplayDensity(); + const delta = Math.floor(density) !== density ? 1.1 : DELTA; TKUnit.assertAreClose(actual, expected, delta, message); } @@ -204,7 +205,7 @@ export function forceGC() { utils.GC(); } -export function _generateFormattedString(): formattedStringModule.FormattedString{ +export function _generateFormattedString(): formattedStringModule.FormattedString { let formattedString = new formattedStringModule.FormattedString(); let span: spanModule.Span; @@ -218,7 +219,7 @@ export function _generateFormattedString(): formattedStringModule.FormattedStrin span.strikethrough = 1; span.text = "Formatted"; formattedString.spans.push(span); - + span = new spanModule.Span(); span.fontFamily = "sans-serif"; span.fontSize = 20; diff --git a/tests/app/ui/image/image-tests.ts b/tests/app/ui/image/image-tests.ts index 38e0c3cc6..9ff5d13e7 100644 --- a/tests/app/ui/image/image-tests.ts +++ b/tests/app/ui/image/image-tests.ts @@ -142,7 +142,7 @@ export function test_imageSourceNotResetAfterCreateUI() { let image = new ImageModule.Image(); let imageSource = ImageSourceModule.fromResource("splashscreen.9"); image.imageSource = imageSource; - helper.buildUIAndRunTest(image, (img, page) => { + helper.buildUIAndRunTest(image, () => { TKUnit.waitUntilReady(() => image.isLoaded); TKUnit.assertEqual(image.imageSource, imageSource); }); diff --git a/tests/app/ui/view/view-tests-common.ts b/tests/app/ui/view/view-tests-common.ts index 0b87f969f..2c94b3913 100644 --- a/tests/app/ui/view/view-tests-common.ts +++ b/tests/app/ui/view/view-tests-common.ts @@ -1,196 +1,196 @@ import * as TKUnit from "../../TKUnit"; -import * as viewModule from "ui/core/view"; -import * as frame from "ui/frame"; -import * as page from "ui/page"; -import * as button from "ui/button"; -import * as labelModule from "ui/label"; +import { View, eachDescendant, getViewById, InheritedProperty } from "ui/core/view"; +import { topmost } from "ui/frame"; +import { Page } from "ui/page"; +import { Button } from "ui/button"; +import { Label } from "ui/label"; +import { Color } from "color"; +import { Layout } from "ui/layouts/layout"; +import { StackLayout } from "ui/layouts/stack-layout"; +import { AbsoluteLayout } from "ui/layouts/absolute-layout"; +import * as utils from "utils/utils"; import * as types from "utils/types"; import * as helper from "../../ui/helper"; -import * as color from "color"; -import * as dependensyObservable from "ui/core/dependency-observable"; -import * as proxy from "ui/core/proxy"; -import * as layoutModule from "ui/layouts/layout"; import * as observable from "data/observable"; import * as bindable from "ui/core/bindable"; import * as definition from "./view-tests"; -import * as absoluteLayoutModule from "ui/layouts/absolute-layout"; -export var test_eachDescendant = function () { - var test = function (views: Array) { +export const test_eachDescendant = function () { + const test = function (views: Array) { // traverse the visual tree and verify the hierarchy - var counter = 0; - var callback = function (child: viewModule.View): boolean { + let counter = 0; + const callback = function (child: View): boolean { TKUnit.assert(child === views[counter]); counter++; return true; - } + }; - viewModule.eachDescendant(frame.topmost(), callback); + eachDescendant(topmost(), callback); // Descendants: page, actionBar, button TKUnit.assertEqual(counter, 3, "descendants"); - } + }; helper.do_PageTest_WithButton(test); -} +}; -export var test_getViewById_Static = function () { - var test = function (views: Array) { +export const test_getViewById_Static = function () { + const test = function (views: Array) { views[1].id = "myLayout"; // traverse the visual tree and verify the hierarchy - var result = viewModule.getViewById(frame.topmost(), "myLayout"); + const result = getViewById(topmost(), "myLayout"); TKUnit.assert(result === views[1]); - } + }; helper.do_PageTest_WithButton(test); -} +}; -export var test_getViewById_Instance = function () { - var test = function (views: Array) { +export const test_getViewById_Instance = function () { + const test = function (views: Array) { views[1].id = "myLayout"; // traverse the visual tree and verify the hierarchy - var result = frame.topmost().getViewById("myLayout"); + const result = topmost().getViewById("myLayout"); TKUnit.assert(result === views[1]); - } + }; helper.do_PageTest_WithButton(test); -} +}; -export var test_eachDescendant_Break_Iteration = function () { - var test = function (views: Array) { +export const test_eachDescendant_Break_Iteration = function () { + const test = function (views: Array) { // traverse the visual tree and verify the hierarchy - var counter = 0; - var callback = function (child: viewModule.View): boolean { + let counter = 0; + const callback = function (child: View): boolean { TKUnit.assert(child === views[0]); counter++; return false; - } + }; - viewModule.eachDescendant(frame.topmost(), callback); + eachDescendant(topmost(), callback); TKUnit.assert(counter === 1); - } + }; helper.do_PageTest_WithButton(test); -} +}; -export var test_parent_IsValid_WhenAttached_ToVisualTree = function () { - var test = function (views: Array) { +export const test_parent_IsValid_WhenAttached_ToVisualTree = function () { + const test = function (views: Array) { // views[0] is a Page instance, its parent should be the topmost frame TKUnit.assert(types.isDefined(views[0].parent)); - TKUnit.assert(views[0].parent === frame.topmost()); + TKUnit.assert(views[0].parent === topmost()); // views[1] is a Button instance, its parent should be the Page (views[0]) TKUnit.assert(types.isDefined(views[1].parent)); TKUnit.assert(views[1].parent === views[0]); - } + }; helper.do_PageTest_WithButton(test); -} +}; -export var test_parent_IsReset_WhenDetached_FromVisualTree = function () { - var cachedViews: Array; +export const test_parent_IsReset_WhenDetached_FromVisualTree = function () { + let cachedViews: Array; - var test = function (views: Array) { + const test = function (views: Array) { cachedViews = views; - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); TKUnit.assert(types.isUndefined(cachedViews[1].parent)); TKUnit.assert(types.isDefined(cachedViews[2].parent)); TKUnit.assert(cachedViews[2].parent === cachedViews[1]); -} +}; -export var test_domId_IsUnique = function () { - var btn = new button.Button(); - var topframe = frame.topmost(); +export const test_domId_IsUnique = function () { + const btn = new Button(); + const topframe = topmost(); TKUnit.assert(btn._domId !== topframe._domId); TKUnit.assert(btn._domId !== topframe.currentPage._domId); -} +}; -export var test_Id_WillNotCrash_WhenSetToNumber = function () { - var btn = new button.Button(); +export const test_Id_WillNotCrash_WhenSetToNumber = function () { + const btn = new Button(); btn.id = "1"; TKUnit.assert(btn.id === "1"); -} +}; -export var test_event_LoadedUnloaded_IsRaised = function () { - var test = function (views: Array) { - var i; +export const test_event_LoadedUnloaded_IsRaised = function () { + const test = function (views: Array) { + let i; for (i = 0; i < views.length; i++) { TKUnit.assert(views[i].isLoaded); } // change the page's content and verify the proper events - var layoutUnloaded = false, - buttonUnloaded = false; + let layoutUnloaded = false; + let buttonUnloaded = false; - views[1].on(viewModule.View.unloadedEvent, (data) => { + views[1].on(View.unloadedEvent, (data) => { layoutUnloaded = true; }); - views[2].on(viewModule.View.unloadedEvent, (data) => { + views[2].on(View.unloadedEvent, (data) => { buttonUnloaded = true; }); - var newButton = new button.Button(), - buttonLoaded = false; + const newButton = new Button(); + let buttonLoaded = false; - newButton.on(viewModule.View.loadedEvent, (data) => { + newButton.on(View.loadedEvent, (data) => { buttonLoaded = true; }); - (views[0]).content = newButton; + (views[0]).content = newButton; TKUnit.assert(layoutUnloaded); TKUnit.assert(buttonUnloaded); TKUnit.assert(buttonLoaded); - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); -} +}; export function test_bindingContext_IsInherited() { - var context = {}; - var test = function (views: Array) { + const context = {}; + const test = function (views: Array) { views[0].bindingContext = context; for (let i = 0; i < views.length; i++) { TKUnit.assertEqual(views[i].bindingContext, context); } - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); - frame.topmost().bindingContext = undefined; + topmost().bindingContext = undefined; } -export var test_isAddedToNativeVisualTree_IsUpdated = function () { - var test = function (views: Array) { +export const test_isAddedToNativeVisualTree_IsUpdated = function () { + const test = function (views: Array) { for (let i = 0; i < views.length; i++) { - TKUnit.assert(views[i]._isAddedToNativeVisualTree); + TKUnit.assert(views[i]._isAddedToNativeVisualTree, `View ${views[i]} not initially added`); } - var newButton = new button.Button(); - TKUnit.assert(!newButton._isAddedToNativeVisualTree); + const newButton = new Button(); + TKUnit.assert(!newButton._isAddedToNativeVisualTree, "Button is not added initially"); views[1]._addView(newButton); - TKUnit.assert(newButton._isAddedToNativeVisualTree); + TKUnit.assert(newButton._isAddedToNativeVisualTree, "Button is not added after _addView"); views[1]._removeView(newButton); - TKUnit.assert(!newButton._isAddedToNativeVisualTree); - } + TKUnit.assert(!newButton._isAddedToNativeVisualTree, "Button is removed after _removeView"); + }; helper.do_PageTest_WithStackLayout_AndButton(test); -} +}; -export var test_addView_WillThrow_IfView_IsAlreadyAdded = function () { - var test = function (views: Array) { - var newButton = new button.Button(); +export const test_addView_WillThrow_IfView_IsAlreadyAdded = function () { + const test = function (views: Array) { + const newButton = new Button(); views[1]._addView(newButton); - var thrown = false; + let thrown = false; try { views[1]._addView(newButton); } catch (e) { @@ -199,17 +199,17 @@ export var test_addView_WillThrow_IfView_IsAlreadyAdded = function () { } TKUnit.assert(thrown); - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); -} +}; -export var test_addToNativeVisualTree_WillThrow_IfView_IsAlreadyAdded = function () { - var test = function (views: Array) { - var newButton = new button.Button(); +export const test_addToNativeVisualTree_WillThrow_IfView_IsAlreadyAdded = function () { + const test = function (views: [Page, StackLayout, View, View]) { + const newButton = new Button(); views[1]._addView(newButton); - var thrown = false; + let thrown = false; try { views[1]._addViewToNativeVisualTree(newButton); } catch (e) { @@ -218,101 +218,50 @@ export var test_addToNativeVisualTree_WillThrow_IfView_IsAlreadyAdded = function } TKUnit.assert(thrown); - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); -} +}; -export var test_InheritableStyleProperties_AreInherited = function () { - var test = function (views: Array) { - var redColor = new color.Color("red"); +export const test_InheritableStyleProperties_AreInherited = function () { + helper.do_PageTest_WithStackLayout_AndButton((views) => { + const redColor = new Color("red"); views[0].style.color = redColor; - var newButton = new button.Button(); - views[1]._addView(newButton); + const newButton = new Button(); + views[1].addChild(newButton); - TKUnit.assert(newButton.style.color === redColor); - } + TKUnit.assertEqual(newButton.style.color, redColor, "Color should be inherited"); + }); +}; - helper.do_PageTest_WithStackLayout_AndButton(test); -} - -export class TestButton extends button.Button { +export class TestButton extends Button { } -export var test_InheritableStylePropertiesWhenUsedWithExtendedClass_AreInherited = function () { - let page = frame.topmost().currentPage; - let redColor = new color.Color("red"); +export const test_InheritableStylePropertiesWhenUsedWithExtendedClass_AreInherited = function () { + let page = topmost().currentPage; + let redColor = new Color("red"); page.style.color = redColor; let newButton = new TestButton(); page.content = newButton; TKUnit.assertEqual(newButton.style.color, redColor); -} +}; -var inheritanceTestDefaultValue = 42; +class TestView extends Layout { -var inheritanceTestProperty = new dependensyObservable.Property( - "inheritanceTest", - "TestView", - new proxy.PropertyMetadata(inheritanceTestDefaultValue, dependensyObservable.PropertyMetadataSettings.Inheritable) - ); - -var booleanInheritanceTestDefaultValue = true; - -var booleanInheritanceTestProperty = new dependensyObservable.Property( - "booleanInheritanceTest", - "TestView", - new proxy.PropertyMetadata(booleanInheritanceTestDefaultValue, dependensyObservable.PropertyMetadataSettings.Inheritable) -); - -var dummyProperty = new dependensyObservable.Property( - "dummy", - "TestView", - new proxy.PropertyMetadata(0) - ); - -class TestView extends layoutModule.Layout { - - constructor(name: string) { + constructor(public name: string) { super(); - this._tralala = name; } - private _tralala: string; - - get tralala(): string { - return this._tralala; - } - set tralala(value: string) { - this._tralala = value; - } - - get inheritanceTest(): number { - return this._getValue(inheritanceTestProperty); - } - set inheritanceTest(value: number) { - this._setValue(inheritanceTestProperty, value); - } - - get booleanInheritanceTest(): boolean { - return this._getValue(booleanInheritanceTestProperty); - } - set booleanInheritanceTest(value: boolean) { - this._setValue(booleanInheritanceTestProperty, value); - } - - get dummy(): number { - return this._getValue(dummyProperty); - } - set dummy(value: number) { - this._setValue(dummyProperty, value); - } + public inheritanceTest: number; + public booleanInheritanceTest: boolean; + public dummy: number; public toString() { - return super.toString() + "." + this.tralala; + return super.toString() + "." + this.name; } public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void { @@ -320,115 +269,126 @@ class TestView extends layoutModule.Layout { } } -export var test_InheritableProperties_getValuesFromParent = function () { - var testValue = 35; - var test = function (views: Array) { - var bottomView = views[3] +const inheritanceTestDefaultValue = 42; +const inheritanceTestProperty = new InheritedProperty({ name: "inheritanceTest", defaultValue: inheritanceTestDefaultValue }); +inheritanceTestProperty.register(TestView); + +const booleanInheritanceTestDefaultValue = true; +const booleanInheritanceTestProperty = new InheritedProperty({ name: "booleanInheritanceTest", defaultValue: booleanInheritanceTestDefaultValue }); +booleanInheritanceTestProperty.register(TestView); + +const dummyProperty = new InheritedProperty({ name: "dummy", defaultValue: 0 }); +dummyProperty.register(TestView); + +export const test_InheritableProperties_getValuesFromParent = function () { + const testValue = 35; + const test = function (views: Array) { + const bottomView = views[3]; TKUnit.assert(bottomView.inheritanceTest === testValue, "Expected: " + testValue + " Actual: " + bottomView.inheritanceTest); - } + }; - var firstView = new TestView("firstView"); + const firstView = new TestView("firstView"); firstView.inheritanceTest = testValue; - var secondView = new TestView("secondView"); - var thirdView = new TestView("thirdView"); + const secondView = new TestView("secondView"); + const thirdView = new TestView("thirdView"); firstView.addChild(secondView); secondView.addChild(thirdView); helper.do_PageTest(test, firstView, secondView, thirdView); -} +}; -export var test_BooleanInheritableProperties_getValuesFromParent = function () { - var testValue = false; - var test = function (views: Array) { - var bottomView = views[3] +export const test_BooleanInheritableProperties_getValuesFromParent = function () { + const testValue = false; + const test = function (views: Array) { + const bottomView = views[3]; TKUnit.assert(bottomView.booleanInheritanceTest === testValue, "Expected: " + testValue + " Actual: " + bottomView.booleanInheritanceTest); - } + }; - var firstView = new TestView("firstView"); + const firstView = new TestView("firstView"); firstView.booleanInheritanceTest = testValue; - var secondView = new TestView("secondView"); - var thirdView = new TestView("thirdView"); + const secondView = new TestView("secondView"); + const thirdView = new TestView("thirdView"); firstView.addChild(secondView); secondView.addChild(thirdView); helper.do_PageTest(test, firstView, secondView, thirdView); -} +}; -export var test_InheritableProperties_resetValuesOnRemoveFromVisualTree = function () { - var testValue = 35; - var test = function (views: Array) { - var bottomView = views[3]; +export const test_InheritableProperties_resetValuesOnRemoveFromVisualTree = function () { + const testValue = 35; + const test = function (views: Array) { + const bottomView = views[3]; TKUnit.assert(bottomView.inheritanceTest === testValue, "Expected: " + testValue + " Actual: " + bottomView.inheritanceTest); (views[2]).removeChild(bottomView); TKUnit.assert(bottomView.inheritanceTest === inheritanceTestDefaultValue, "Expected: " + inheritanceTestDefaultValue + " Actual: " + bottomView.inheritanceTest); - } + }; - var firstView = new TestView("firstView"); + const firstView = new TestView("firstView"); firstView.inheritanceTest = testValue; - var secondView = new TestView("secondView"); - var thirdView = new TestView("thirdView"); + const secondView = new TestView("secondView"); + const thirdView = new TestView("thirdView"); firstView.addChild(secondView); secondView.addChild(thirdView); helper.do_PageTest(test, firstView, secondView, thirdView); -} +}; -export var test_InheritableProperties_DefaultValue = function () { - var test = function (views: Array) { - var bottomView = views[3] +export const test_InheritableProperties_DefaultValue = function () { + const test = function (views: Array) { + const bottomView = views[3]; TKUnit.assert(bottomView.inheritanceTest === inheritanceTestDefaultValue, "Expected: " + inheritanceTestDefaultValue + " Actual: " + bottomView.inheritanceTest); - } + }; - var firstView = new TestView("firstView"); - var secondView = new TestView("secondView"); - var thirdView = new TestView("thirdView"); + const firstView = new TestView("firstView"); + const secondView = new TestView("secondView"); + const thirdView = new TestView("thirdView"); secondView.addChild(thirdView); firstView.addChild(secondView); helper.do_PageTest(test, firstView, secondView, thirdView); -} +}; -export var test_InheritableProperties_ChangeNotification = function () { - var testValue = 35; - var test = function (views: Array) { - var topView = views[1]; +export const test_InheritableProperties_ChangeNotification = function () { + const testValue = 35; + const test = function (views: Array) { + const topView = views[1]; topView.inheritanceTest = testValue; - var bottomView = views[3]; + const bottomView = views[3]; bottomView.bind({ targetProperty: "dummy", sourceProperty: "inheritanceTest" }, bottomView); TKUnit.assert(bottomView.dummy === testValue, "Expected: " + testValue + " Actual: " + bottomView.dummy); - } + }; - var firstView = new TestView("firstView"); - var secondView = new TestView("secondView"); - var thirdView = new TestView("thirdView"); + const firstView = new TestView("firstView"); + const secondView = new TestView("secondView"); + const thirdView = new TestView("thirdView"); secondView.addChild(thirdView); firstView.addChild(secondView); helper.do_PageTest(test, firstView, secondView, thirdView); -} +}; -function property_binding_test(propName: string, firstValue: any, secondValue: any, view?: viewModule.View) { - var actualResult; - var model = new observable.Observable(); +function property_binding_test(propName: string, firstValue: any, secondValue: any, view?: View) { + let actualResult; + const model = new observable.Observable(); model.set(propName, firstValue); - var options: bindable.BindingOptions = { + const options: bindable.BindingOptions = { sourceProperty: propName, targetProperty: propName - } + }; if (!view) { view = new TestView("view"); @@ -444,15 +404,15 @@ function property_binding_test(propName: string, firstValue: any, secondValue: a TKUnit.assertEqual(actualResult, secondValue); } -function property_binding_style_test(propName: string, firstValue: any, secondValue: any, view?: viewModule.View) { - var actualResult; - var model = new observable.Observable(); +function property_binding_style_test(propName: string, firstValue: any, secondValue: any, view?: View) { + let actualResult; + const model = new observable.Observable(); model.set(propName, firstValue); - var options: bindable.BindingOptions = { + const options: bindable.BindingOptions = { sourceProperty: propName, targetProperty: "style." + propName - } + }; if (!view) { view = new TestView("view"); @@ -468,288 +428,284 @@ function property_binding_style_test(propName: string, firstValue: any, secondVa TKUnit.assertEqual(actualResult, secondValue); } -export var test_binding_width = function () { +export const test_binding_width = function () { property_binding_test("width", 42, 43); -} +}; -export var test_binding_height = function () { +export const test_binding_height = function () { property_binding_test("height", 42, 43); -} +}; -export var test_binding_minWidth = function () { +export const test_binding_minWidth = function () { property_binding_test("minWidth", 42, 43); -} +}; -export var test_binding_minHeight = function () { +export const test_binding_minHeight = function () { property_binding_test("minHeight", 42, 43); -} +}; -export var test_binding_horizontalAlignment = function () { +export const test_binding_horizontalAlignment = function () { property_binding_test("horizontalAlignment", "left", "right"); -} +}; -export var test_binding_verticalAlignment = function () { +export const test_binding_verticalAlignment = function () { property_binding_test("verticalAlignment", "top", "bottom"); -} +}; -export var test_binding_marginLeft = function () { +export const test_binding_marginLeft = function () { property_binding_test("marginLeft", 42, 43); -} +}; -export var test_binding_marginTop = function () { +export const test_binding_marginTop = function () { property_binding_test("marginTop", 42, 43); -} +}; -export var test_binding_marginRight = function () { +export const test_binding_marginRight = function () { property_binding_test("marginRight", 42, 43); -} +}; -export var test_binding_marginBottom = function () { +export const test_binding_marginBottom = function () { property_binding_test("marginBottom", 42, 43); -} +}; -export var test_binding_visibility = function () { - property_binding_test("visibility", "collapsed", "visible"); -} +export const test_binding_visibility = function () { + property_binding_test("visibility", "collapse", "visible"); +}; -export var test_binding_isEnabled = function () { +export const test_binding_isEnabled = function () { property_binding_test("isEnabled", false, true); -} +}; -export var test_binding_isUserInteractionEnabled = function () { +export const test_binding_isUserInteractionEnabled = function () { property_binding_test("isUserInteractionEnabled", false, true); -} +}; -export var test_binding_id = function () { +export const test_binding_id = function () { property_binding_test("id", "id1", "id2"); -} +}; -export var test_binding_cssClass = function () { +export const test_binding_cssClass = function () { property_binding_test("cssClass", "class1", "class2"); -} +}; -export var test_binding_className = function () { +export const test_binding_className = function () { property_binding_test("className", "class1", "class2"); -} +}; -export var test_binding_style_color = function () { - property_binding_style_test("color", new color.Color("#FF0000"), new color.Color("#00FF00")); -} +export const test_binding_style_color = function () { + property_binding_style_test("color", new Color("#FF0000"), new Color("#00FF00")); +}; -export var test_binding_style_backgroundColor = function () { - property_binding_style_test("backgroundColor", new color.Color("#FF0000"), new color.Color("#00FF00")); -} +export const test_binding_style_backgroundColor = function () { + property_binding_style_test("backgroundColor", new Color("#FF0000"), new Color("#00FF00")); +}; -export var test_binding_style_fontSize = function () { +export const test_binding_style_fontSize = function () { property_binding_style_test("fontSize", 5, 10); -} +}; -export var test_binding_style_textAlignment = function () { +export const test_binding_style_textAlignment = function () { property_binding_style_test("textAlignment", "right", "center"); -} +}; -export var test_binding_style_width = function () { +export const test_binding_style_width = function () { property_binding_style_test("width", 42, 43); -} +}; -export var test_binding_style_height = function () { +export const test_binding_style_height = function () { property_binding_style_test("height", 42, 43); -} +}; -export var test_binding_style_minWidth = function () { +export const test_binding_style_minWidth = function () { property_binding_style_test("minWidth", 42, 43); -} +}; -export var test_binding_style_minHeight = function () { +export const test_binding_style_minHeight = function () { property_binding_style_test("minHeight", 42, 43); -} +}; -export var test_binding_style_margin = function () { - property_binding_style_test("margin", "1 1 1 1", "2 2 2 2"); -} +export const test_binding_style_margin = function () { + property_binding_style_test("margin", "1dip 2dip 3dip 4dip", "2dip 3dip 2dip 3dip"); +}; -export var test_binding_style_marginLeft = function () { +export const test_binding_style_marginLeft = function () { property_binding_style_test("marginLeft", 42, 43); -} +}; -export var test_binding_style_marginTop = function () { +export const test_binding_style_marginTop = function () { property_binding_style_test("marginTop", 42, 43); -} +}; -export var test_binding_style_marginRight = function () { +export const test_binding_style_marginRight = function () { property_binding_style_test("marginRight", 42, 43); -} +}; -export var test_binding_style_marginBottom = function () { +export const test_binding_style_marginBottom = function () { property_binding_style_test("marginBottom", 42, 43); -} +}; -export var test_binding_style_padding = function () { - property_binding_style_test("padding", "1 1 1 1", "2 2 2 2"); -} +export const test_binding_style_padding = function () { + property_binding_style_test("padding", "1dip 2dip 3dip 4dip", "2dip 3dip 2dip 3dip"); +}; -export var test_binding_style_paddingLeft = function () { +export const test_binding_style_paddingLeft = function () { property_binding_style_test("paddingLeft", 42, 43); -} +}; -export var test_binding_style_paddingTop = function () { +export const test_binding_style_paddingTop = function () { property_binding_style_test("paddingTop", 42, 43); -} +}; -export var test_binding_style_paddingRight = function () { +export const test_binding_style_paddingRight = function () { property_binding_style_test("paddingRight", 42, 43); -} +}; -export var test_binding_style_paddingBottom = function () { +export const test_binding_style_paddingBottom = function () { property_binding_style_test("paddingBottom", 42, 43); -} +}; -export var test_binding_style_horizontalAlignment = function () { +export const test_binding_style_horizontalAlignment = function () { property_binding_style_test("horizontalAlignment", "left", "right"); -} +}; -export var test_binding_style_verticalAlignment = function () { +export const test_binding_style_verticalAlignment = function () { property_binding_style_test("verticalAlignment", "top", "bottom"); -} +}; -export var test_binding_style_visibility = function () { - property_binding_style_test("visibility", "collapsed", "visible"); -} +export const test_binding_style_visibility = function () { + property_binding_style_test("visibility", "collapse", "visible"); +}; -export var test_binding_style_opacity = function () { +export const test_binding_style_opacity = function () { property_binding_style_test("opacity", 0.5, 0.6); -} +}; -function _createLabelWithBorder(): viewModule.View { - var lbl = new labelModule.Label(); +function _createLabelWithBorder(): View { + const lbl = new Label(); lbl.borderRadius = 10; lbl.borderWidth = 2; - lbl.borderColor = new color.Color("#FF0000"); - lbl.backgroundColor = new color.Color("#FFFF00"); + lbl.borderColor = new Color("#FF0000"); + lbl.backgroundColor = new Color("#FFFF00"); return lbl; } -export var testIsVisible = function () { - var lbl = new labelModule.Label(); +export const testIsVisible = function () { + const lbl = new Label(); - helper.buildUIAndRunTest(lbl, function (views: Array) { + helper.buildUIAndRunTest(lbl, function (views: Array) { TKUnit.assertEqual(lbl.visibility, "visible"); TKUnit.assertEqual(lbl.isCollapsed, false); lbl.visibility = "collapse"; TKUnit.assertEqual(lbl.visibility, "collapse"); TKUnit.assertEqual(lbl.isCollapsed, true); - - lbl.visibility = "collapse"; - TKUnit.assertEqual(lbl.visibility, "collapse"); - TKUnit.assertEqual(lbl.isCollapsed, true); }); -} +}; -export var testSetInlineStyle = function () { - var lbl = new labelModule.Label(); +export const testSetInlineStyle = function () { + const lbl = new Label(); - var expectedColor = "#ff0000"; - var expectedBackgroundColor = "#ff0000"; + const expectedColor = "#ff0000"; + const expectedBackgroundColor = "#ff0000"; lbl.setInlineStyle(`color: ${expectedColor};background-color: ${expectedBackgroundColor};`); - helper.buildUIAndRunTest(lbl, function (views: Array) { + helper.buildUIAndRunTest(lbl, function (views: Array) { TKUnit.assertEqual(lbl.color.hex, expectedColor); TKUnit.assertEqual(lbl.backgroundColor.hex, expectedBackgroundColor); }); -} +}; -export var testBorderWidth = function () { - helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { - var lbl = views[0]; - var expectedValue = lbl.borderWidth; - var actualValue = definition.getUniformNativeBorderWidth(lbl); - TKUnit.assertEqual(actualValue, expectedValue); +export const testBorderWidth = function () { + helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { + const lbl = views[0]; + const expectedValue = lbl.borderWidth * utils.layout.getDisplayDensity(); + const actualValue = definition.getUniformNativeBorderWidth(lbl); + TKUnit.assertAreClose(actualValue, expectedValue, 0.01, "borderWidth"); }); -} +}; -export var testCornerRadius = function () { - helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { - var lbl = views[0]; - var expectedValue = lbl.borderRadius; - var actualValue = definition.getUniformNativeCornerRadius(lbl); - TKUnit.assertEqual(actualValue, expectedValue); +export const testCornerRadius = function () { + helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { + const lbl = views[0]; + const expectedValue = lbl.borderRadius * utils.layout.getDisplayDensity(); + const actualValue = definition.getUniformNativeCornerRadius(lbl); + TKUnit.assertAreClose(actualValue, expectedValue, 0.01, "borderRadius"); }); -} +}; -export var testBorderColor = function () { - helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { - var lbl = views[0]; +export const testBorderColor = function () { + helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { + const lbl = views[0]; TKUnit.assertEqual(definition.checkUniformNativeBorderColor(lbl), true, "BorderColor not applied correctly!"); }); -} +}; -export var testBackgroundColor = function () { - helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { - var lbl = views[0]; +export const testBackgroundColor = function () { + helper.buildUIAndRunTest(_createLabelWithBorder(), function (views: Array) { + const lbl = views[0]; TKUnit.assertEqual(definition.checkNativeBackgroundColor(lbl), true, "BackgroundColor not applied correctly!"); }); -} +}; -export var testBackgroundImage = function () { - var lbl = _createLabelWithBorder(); +export const testBackgroundImage = function () { + const lbl = _createLabelWithBorder(); lbl.className = "myClass"; - helper.buildUIAndRunTest(lbl, function (views: Array) { - var page = views[1]; + helper.buildUIAndRunTest(lbl, function (views: Array) { + const page = views[1]; page.css = ".myClass { background-image: url('~/logo.png') }"; TKUnit.assertEqual(definition.checkNativeBackgroundImage(lbl), true, "Style background-image not loaded correctly."); }); -} +}; export function test_automation_text_default_value() { - let view = new button.Button(); + let view = new Button(); TKUnit.assertTrue(view.automationText === undefined, "AutomationText default value should be UNDEFINED."); } -export var test_getLocationInWindow_IsUndefinedWhenNotInTheVisualTree = function () { - var label = new labelModule.Label(); +export const test_getLocationInWindow_IsUndefinedWhenNotInTheVisualTree = function () { + const label = new Label(); TKUnit.assertNull(label.getLocationInWindow()); -} +}; -export var test_getLocationOnScreen_IsUndefinedWhenNotInTheVisualTree = function () { - var label = new labelModule.Label(); +export const test_getLocationOnScreen_IsUndefinedWhenNotInTheVisualTree = function () { + const label = new Label(); TKUnit.assertNull(label.getLocationOnScreen()); -} +}; -var delta = 1; -export var test_getLocationRelativeToOtherView = function () { - var a1 = new absoluteLayoutModule.AbsoluteLayout(); +const delta = 1; +export const test_getLocationRelativeToOtherView = function () { + const a1 = new AbsoluteLayout(); a1.width = 200; a1.height = 200; - a1.backgroundColor = new color.Color("red"); + a1.backgroundColor = new Color("red"); - var a2 = new absoluteLayoutModule.AbsoluteLayout(); + const a2 = new AbsoluteLayout(); a2.width = 100; a2.height = 100; - absoluteLayoutModule.AbsoluteLayout.setLeft(a2, 10); - absoluteLayoutModule.AbsoluteLayout.setTop(a2, 10); - a2.backgroundColor = new color.Color("green"); + AbsoluteLayout.setLeft(a2, 10); + AbsoluteLayout.setTop(a2, 10); + a2.backgroundColor = new Color("green"); - var label = new labelModule.Label(); + const label = new Label(); label.text = "label"; label.id = "label"; label.width = 70; label.height = 30; - absoluteLayoutModule.AbsoluteLayout.setLeft(label, 10); - absoluteLayoutModule.AbsoluteLayout.setTop(label, 10); - a2.backgroundColor = new color.Color("yellow"); + AbsoluteLayout.setLeft(label, 10); + AbsoluteLayout.setTop(label, 10); + a2.backgroundColor = new Color("yellow"); a2.addChild(label); a1.addChild(a2); - helper.buildUIAndRunTest(a1, function (views: Array) { + helper.buildUIAndRunTest(a1, function (views: Array) { TKUnit.waitUntilReady(() => a1.isLayoutValid); - var labelInA2 = label.getLocationRelativeTo(a2); - var labelInA1 = label.getLocationRelativeTo(a1); - var a2InA1 = a2.getLocationRelativeTo(a1); + const labelInA2 = label.getLocationRelativeTo(a2); + const labelInA1 = label.getLocationRelativeTo(a1); + const a2InA1 = a2.getLocationRelativeTo(a1); TKUnit.assertAreClose(labelInA2.x, 10, delta, "labelInA2.x"); TKUnit.assertAreClose(labelInA2.y, 10, delta, "labelInA2.y"); @@ -760,16 +716,16 @@ export var test_getLocationRelativeToOtherView = function () { TKUnit.assertAreClose(a2InA1.x, 10, delta, "a2InA1.x"); TKUnit.assertAreClose(a2InA1.y, 10, delta, "a2InA1.y"); }); -} +}; -export var test_getActualSize = function () { - var label = new labelModule.Label(); +export const test_getActualSize = function () { + const label = new Label(); label.width = 100; label.height = 200; - helper.buildUIAndRunTest(label, function (views: Array) { + helper.buildUIAndRunTest(label, function (views: Array) { TKUnit.waitUntilReady(() => label.isLayoutValid); - var actualSize = label.getActualSize(); + const actualSize = label.getActualSize(); TKUnit.assertAreClose(actualSize.width, 100, delta, "actualSize.width"); TKUnit.assertAreClose(actualSize.height, 200, delta, "actualSize.height"); }); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/tests/app/ui/view/view-tests.android.ts b/tests/app/ui/view/view-tests.android.ts index df266ec66..d4161157d 100644 --- a/tests/app/ui/view/view-tests.android.ts +++ b/tests/app/ui/view/view-tests.android.ts @@ -14,48 +14,48 @@ trace.enable(); global.moduleMerge(commonTests, exports); -export var test_event_onAttached_IsRaised = function () { - var listener = new Listener("_onAttached"); +export const test_event_setupUI_IsRaised = function () { + const listener = new Listener("_setupUI"); trace.addEventListener(listener); - var test = function (views: Array) { - // 2 onAttached calls: stack, button - TKUnit.assertEqual(listener.receivedEvents.length, 2, "onAttached calls"); + const test = function (views: Array) { + // 2 setupUI calls: stack, button + TKUnit.assertEqual(listener.receivedEvents.length, 2, "setupUI calls"); for (let i = 0; i < listener.receivedEvents.length; i++) { TKUnit.assertEqual(listener.receivedEvents[i].sender, views[i + 1]); // 0 is Page, so start with +1. - TKUnit.assertEqual(listener.receivedEvents[i].name, "_onAttached"); + TKUnit.assertEqual(listener.receivedEvents[i].name, "_setupUI"); } - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); trace.removeEventListener(listener); -} +}; -export var test_event_onAttached_IsRaised_WhenAttached_Dynamically = function () { - var test = function (views: Array) { - // add new button to the visual tree and ensure its _onAttached event - var listener = new Listener("_onAttached"); +export const test_event_setupUI_IsRaised_WhenAttached_Dynamically = function () { + const test = function (views: Array) { + // add new button to the visual tree and ensure its _setupUI event + const listener = new Listener("_setupUI"); trace.addEventListener(listener); - var newButton = new button.Button(); + const newButton = new button.Button(); (views[1]).addChild(newButton); TKUnit.assertEqual(listener.receivedEvents.length, 1); - TKUnit.assertEqual(listener.receivedEvents[0].name, "_onAttached"); + TKUnit.assertEqual(listener.receivedEvents[0].name, "_setupUI"); TKUnit.assertEqual(listener.receivedEvents[0].sender, newButton); trace.removeEventListener(listener); - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); -} +}; -export var test_event_onContextChanged_IsRaised_WhenAttached = function () { - var listener = new Listener("_onContextChanged"); +export const test_event_onContextChanged_IsRaised_WhenAttached = function () { + const listener = new Listener("_onContextChanged"); trace.addEventListener(listener); - var test = function (views: Array) { + const test = function (views: Array) { // 2 onContextChanged calls: stack, button TKUnit.assertEqual(listener.receivedEvents.length, 2, "onContextChanged calls"); @@ -63,19 +63,19 @@ export var test_event_onContextChanged_IsRaised_WhenAttached = function () { TKUnit.assertEqual(listener.receivedEvents[i].sender, views[i + 1]); // 0 is Page, so start with +1. TKUnit.assertEqual(listener.receivedEvents[i].name, "_onContextChanged"); } - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); trace.removeEventListener(listener); -} +}; -export var test_event_onContextChanged_IsRaised_WhenAttached_Dynamically = function () { - var test = function (views: Array) { +export const test_event_onContextChanged_IsRaised_WhenAttached_Dynamically = function () { + const test = function (views: Array) { // add new button to the visual tree and ensure its _onContextChanged event - var listener = new Listener("_onContextChanged"); + const listener = new Listener("_onContextChanged"); trace.addEventListener(listener); - var newButton = new button.Button(); + const newButton = new button.Button(); (views[1]).addChild(newButton); TKUnit.assertEqual(listener.receivedEvents.length, 1); @@ -83,63 +83,63 @@ export var test_event_onContextChanged_IsRaised_WhenAttached_Dynamically = funct TKUnit.assertEqual(listener.receivedEvents[0].sender, newButton); trace.removeEventListener(listener); - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); -} +}; -export var test_event_onDetached_IsRaised = function () { - var cachedViews: Array; - var listener: Listener; +export const test_event_tearDownUI_IsRaised = function () { + let cachedViews: Array; + let listener: Listener; - var test = function (views: Array) { + const test = function (views: Array) { cachedViews = views; // once the above method completes goBack on the current frame is called which will detach the tested views - listener = new Listener("_onDetached"); + listener = new Listener("_tearDownUI"); trace.addEventListener(listener); - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); // 2 detached calls: page, stack, button, actionBar - TKUnit.assertEqual(listener.receivedEvents.length, 2, "onDetached calls"); + TKUnit.assertEqual(listener.receivedEvents.length, 2, "tearDownUI calls"); - // _onDetached event is propagated to nested children first + // _tearDownUI event is propagated to nested children first for (let i = 0, j = listener.receivedEvents.length - 1; i < listener.receivedEvents.length; i++ , j--) { // check the sender and remove - var index = cachedViews.indexOf(listener.receivedEvents[i].sender); - TKUnit.assert(index >= 0, "_onDetached called for unknown sender"); + const index = cachedViews.indexOf(listener.receivedEvents[i].sender); + TKUnit.assert(index >= 0, "_tearDownUI called for unknown sender"); cachedViews.splice(index, 1); - TKUnit.assertEqual(listener.receivedEvents[i].name, "_onDetached"); + TKUnit.assertEqual(listener.receivedEvents[i].name, "_tearDownUI"); } trace.removeEventListener(listener); -} +}; -export var test_event_onDetached_IsRaised_WhenRemoved_Dynamically = function () { - var test = function (views: Array) { - // add new button to the visual tree and ensure its _onContextChanged event - var listener = new Listener("_onDetached"); +export const test_event_tearDownUI_IsRaised_WhenRemoved_Dynamically = function () { + const test = function (views: Array) { + // add new button to the visual tree and ensure its _tearDownUI event + const listener = new Listener("_tearDownUI"); trace.addEventListener(listener); // remove the button from the layout (views[1]).removeChild(views[2]); TKUnit.assertEqual(listener.receivedEvents.length, 1); - TKUnit.assertEqual(listener.receivedEvents[0].name, "_onDetached"); + TKUnit.assertEqual(listener.receivedEvents[0].name, "_tearDownUI"); TKUnit.assertEqual(listener.receivedEvents[0].sender, views[2]); trace.removeEventListener(listener); - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); -} +}; -export var test_events_onDetachedAndRemovedFromNativeVisualTree_AreRaised_WhenNavigateBack = function () { - let onDetachedListener = new Listener("_onDetached"); - let removeFromNativeVisualTreeListener = new Listener("childInLayoutRemovedFromNativeVisualTree"); +export const test_events_tearDownUIAndRemovedFromNativeVisualTree_AreRaised_WhenNavigateBack = function () { + let tearDownUIListener = new Listener("_tearDownUI"); + let removeFromNativeVisualTreeListener = new Listener("_removeViewFromNativeVisualTree"); let page = frame.topmost().currentPage; let stackLayout = new stack.StackLayout(); @@ -147,34 +147,34 @@ export var test_events_onDetachedAndRemovedFromNativeVisualTree_AreRaised_WhenNa stackLayout.addChild(btn); page.content = stackLayout; - trace.addEventListener(onDetachedListener); + trace.addEventListener(tearDownUIListener); trace.addEventListener(removeFromNativeVisualTreeListener); page.content = null; - // 2 onDetached calls: stack, button - TKUnit.assertEqual(onDetachedListener.receivedEvents.length, 2, "onDetached calls"); + // 2 tearDownUI calls: stack, button + TKUnit.assertEqual(tearDownUIListener.receivedEvents.length, 2, "tearDownUI calls"); - TKUnit.assertEqual(onDetachedListener.receivedEvents[0].name, "_onDetached"); - TKUnit.assertEqual(onDetachedListener.receivedEvents[0].sender, btn); // Button - TKUnit.assertEqual(onDetachedListener.receivedEvents[1].sender, stackLayout); // stackLayout + TKUnit.assertEqual(tearDownUIListener.receivedEvents[0].name, "_tearDownUI"); + TKUnit.assertEqual(tearDownUIListener.receivedEvents[0].sender, btn); // Button + TKUnit.assertEqual(tearDownUIListener.receivedEvents[1].sender, stackLayout); // stackLayout // this is an event fired from CustomLayoutView when a child is removed from the native visual tree // therefore this event is fired for StackLayout and Button (which is inside StackLayout). TKUnit.assertEqual(removeFromNativeVisualTreeListener.receivedEvents.length, 2); - TKUnit.assertEqual(removeFromNativeVisualTreeListener.receivedEvents[0].name, "childInLayoutRemovedFromNativeVisualTree"); - TKUnit.assertEqual(removeFromNativeVisualTreeListener.receivedEvents[0].sender, stackLayout); + TKUnit.assertEqual(removeFromNativeVisualTreeListener.receivedEvents[0].name, "_removeViewFromNativeVisualTree"); + TKUnit.assertEqual(removeFromNativeVisualTreeListener.receivedEvents[0].sender, btn); - TKUnit.assertEqual(removeFromNativeVisualTreeListener.receivedEvents[1].name, "childInLayoutRemovedFromNativeVisualTree"); - TKUnit.assertEqual(removeFromNativeVisualTreeListener.receivedEvents[1].sender, btn); + TKUnit.assertEqual(removeFromNativeVisualTreeListener.receivedEvents[1].name, "_removeViewFromNativeVisualTree"); + TKUnit.assertEqual(removeFromNativeVisualTreeListener.receivedEvents[1].sender, stackLayout); - trace.removeEventListener(onDetachedListener); + trace.removeEventListener(tearDownUIListener); trace.removeEventListener(removeFromNativeVisualTreeListener); -} +}; -export var test_cachedProperties_Applied_WhenNativeWidged_IsCreated = function () { - var test = function (views: Array) { - var newButton = new button.Button(); +export const test_cachedProperties_Applied_WhenNativeWidged_IsCreated = function () { + const test = function (views: Array) { + const newButton = new button.Button(); newButton.text = "Test Button"; TKUnit.assert(types.isUndefined(newButton.android)); @@ -183,37 +183,36 @@ export var test_cachedProperties_Applied_WhenNativeWidged_IsCreated = function ( TKUnit.assert(types.isDefined(newButton.android)); // TODO: There is currently an issue with the getText conversion to JavaScript string TKUnit.assertEqual(newButton.android.getText(), "Test Button"); - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); -} +}; export function test_automation_text_set_to_native() { - var test = function (views: Array) { - var newButton = new button.Button(); + const test = function (views: Array) { + const newButton = new button.Button(); newButton.automationText = "Button1"; (views[1]).addChild(newButton); TKUnit.assertEqual((newButton.android).getContentDescription(), "Button1", "contentDescription not set to native view."); - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); } -export var test_event_onContextChanged_IsNotRaised_WhenAttachedToSameContext = function () { - var test = function (views: Array) { - var listener = new Listener("_onContextChanged"); +export const test_event_onContextChanged_IsNotRaised_WhenAttachedToSameContext = function () { + const test = function (views: Array) { + const listener = new Listener("_onContextChanged"); trace.addEventListener(listener); - // views[2]._onContextChanged(views[0]._context); views[2]._setupUI(views[0]._context); TKUnit.assertEqual(listener.receivedEvents.length, 0, "listener.receivedEvents.length"); trace.removeEventListener(listener); - } + }; helper.do_PageTest_WithStackLayout_AndButton(test); -} +}; class Listener implements trace.EventListener { public filter: string; @@ -232,111 +231,111 @@ class Listener implements trace.EventListener { } } -export var test_StylePropertiesDefaultValuesCache = function () { - var testValue = 35; +export const test_StylePropertiesDefaultValuesCache = function () { + const testValue = 35; - var test = function (views: Array) { - var testLabel = new labelModule.Label(); - var testButton = new button.Button(); + const test = function (views: [view.View, stack.StackLayout, button.Button, view.View]) { + const testLabel = new labelModule.Label(); + const testButton = new button.Button(); - var stack = views[1]; + const stack = views[1]; stack.addChild(testLabel); stack.addChild(testButton); - var defaultLabelFontSize = ((testLabel.android)).getTextSize(); - var defaultButtonFontSize = ((testButton.android)).getTextSize(); + const defaultLabelFontSize = ((testLabel.android)).getTextSize(); + const defaultButtonFontSize = ((testButton.android)).getTextSize(); testLabel.style.fontSize = testValue; testButton.style.fontSize = testValue; - var actualLabelTextSize = ((testLabel.android)).getTextSize(); - var actualButtonTextSize = ((testButton.android)).getTextSize(); + let actualLabelTextSize = ((testLabel.android)).getTextSize(); + let actualButtonTextSize = ((testButton.android)).getTextSize(); TKUnit.assert(actualLabelTextSize !== defaultLabelFontSize, "Label text size should be different from default!"); TKUnit.assert(actualButtonTextSize !== defaultButtonFontSize, "Button text size should be different from default!"); - testLabel.style.fontSize = undefined; - testButton.style.fontSize = undefined; + testLabel.style.fontSize = view.unsetValue; + testButton.style.fontSize = view.unsetValue; actualLabelTextSize = ((testLabel.android)).getTextSize(); actualButtonTextSize = ((testButton.android)).getTextSize(); - TKUnit.assert(actualLabelTextSize === defaultLabelFontSize, "Label text size should be default!"); - TKUnit.assert(actualButtonTextSize === defaultButtonFontSize, "Button text size should be default!"); + TKUnit.assertEqual(actualLabelTextSize, defaultLabelFontSize, "Label text size should be default!"); + TKUnit.assertEqual(actualButtonTextSize, defaultButtonFontSize, "Button text size should be default!"); }; helper.do_PageTest_WithStackLayout_AndButton(test); -} +}; export function getUniformNativeBorderWidth(v: view.View): number { - var bkg = v.android.getBackground(); + const bkg = v.android.getBackground(); return bkg ? bkg.getUniformBorderWidth() : 0; } export function checkUniformNativeBorderColor(v: view.View): boolean { - var bkg = (v.android).getBackground(); + const bkg = (v.android).getBackground(); return bkg && bkg.getUniformBorderColor() === (v.borderColor).android; } export function getUniformNativeCornerRadius(v: view.View): number { - var bkg = v.android.getBackground(); - return bkg ? bkg.getUniformBorderRadius() : 0 + const bkg = v.android.getBackground(); + return bkg ? bkg.getUniformBorderRadius() : 0; } export function checkNativeBackgroundColor(v: view.View): boolean { - var bkg = (v.android).getBackground(); + const bkg = (v.android).getBackground(); return v.backgroundColor && bkg && bkg.getBackgroundColor() === v.backgroundColor.android; } export function checkNativeBackgroundImage(v: view.View): boolean { - var bkg = (v.android).getBackground(); + const bkg = (v.android).getBackground(); return bkg && !types.isNullOrUndefined(bkg.getBackgroundImage()); } let SDK: number; function getSDK() { - if (!SDK) { - SDK = android.os.Build.VERSION.SDK_INT; - } + if (!SDK) { + SDK = android.os.Build.VERSION.SDK_INT; + } - return SDK; + return SDK; } export function test_AndroidLayerType_BorderWidth() { - helper.buildUIAndRunTest(new labelModule.Label(), (views: Array) => { - let lbl = (views[0]); - let androidView = lbl.android; - let originalLayerType = androidView.getLayerType(); - lbl.borderWidth = 5; - TKUnit.assertEqual(androidView.getLayerType(), getSDK() < 18 ? android.view.View.LAYER_TYPE_SOFTWARE : originalLayerType); - lbl.borderWidth = 0; - TKUnit.assertEqual(androidView.getLayerType(), originalLayerType); - }); + helper.buildUIAndRunTest(new labelModule.Label(), (views: Array) => { + let lbl = (views[0]); + let androidView = lbl.android; + let originalLayerType = androidView.getLayerType(); + lbl.borderWidth = 5; + TKUnit.assertEqual(androidView.getLayerType(), getSDK() < 18 ? android.view.View.LAYER_TYPE_SOFTWARE : originalLayerType); + lbl.borderWidth = 0; + TKUnit.assertEqual(androidView.getLayerType(), originalLayerType); + }); }; export function test_AndroidLayerType_BorderRadius() { - helper.buildUIAndRunTest(new labelModule.Label(), (views: Array) => { - let lbl = (views[0]); - let androidView = lbl.android; - let originalLayerType = androidView.getLayerType(); - lbl.borderRadius = 5; - TKUnit.assertEqual(androidView.getLayerType(), getSDK() < 18 ? android.view.View.LAYER_TYPE_SOFTWARE : originalLayerType); - lbl.borderRadius = 0; - TKUnit.assertEqual(androidView.getLayerType(), originalLayerType); - }); + helper.buildUIAndRunTest(new labelModule.Label(), (views: Array) => { + let lbl = (views[0]); + let androidView = lbl.android; + let originalLayerType = androidView.getLayerType(); + lbl.borderRadius = 5; + TKUnit.assertEqual(androidView.getLayerType(), getSDK() < 18 ? android.view.View.LAYER_TYPE_SOFTWARE : originalLayerType); + lbl.borderRadius = 0; + TKUnit.assertEqual(androidView.getLayerType(), originalLayerType); + }); }; export function test_AndroidLayerType_ClipPath() { - helper.buildUIAndRunTest(new labelModule.Label(), (views: Array) => { - let lbl = (views[0]); - let androidView = lbl.android; - let originalLayerType = androidView.getLayerType(); - lbl.style.clipPath = "rect(0, 0, 100%, 100%)"; - TKUnit.assertEqual(androidView.getLayerType(), getSDK() < 18 ? android.view.View.LAYER_TYPE_SOFTWARE : originalLayerType); - lbl.style.clipPath = undefined; - TKUnit.assertEqual(androidView.getLayerType(), originalLayerType); - }); + helper.buildUIAndRunTest(new labelModule.Label(), (views: Array) => { + let lbl = (views[0]); + let androidView = lbl.android; + let originalLayerType = androidView.getLayerType(); + lbl.style.clipPath = "rect(0, 0, 100%, 100%)"; + TKUnit.assertEqual(androidView.getLayerType(), getSDK() < 18 ? android.view.View.LAYER_TYPE_SOFTWARE : originalLayerType); + lbl.style.clipPath = undefined; + TKUnit.assertEqual(androidView.getLayerType(), originalLayerType); + }); }; \ No newline at end of file diff --git a/tests/app/ui/view/view-tests.ios.ts b/tests/app/ui/view/view-tests.ios.ts index aeb257e36..7828bd018 100644 --- a/tests/app/ui/view/view-tests.ios.ts +++ b/tests/app/ui/view/view-tests.ios.ts @@ -8,6 +8,18 @@ import * as button from "ui/button"; global.moduleMerge(commonTests, exports); +class MyGrid extends grid.GridLayout { + public backgroundSetterCount: number = 0; + + get [view.backgroundInternalProperty.native](): any { + return null; + } + set [view.backgroundInternalProperty.native](value: any) { + this.backgroundSetterCount ++; + } + +} + export function getUniformNativeBorderWidth(v: view.View): number { return (v.ios).layer.borderWidth; } @@ -41,28 +53,20 @@ export function checkNativeBackgroundImage(v: view.View): boolean { export function testBackgroundInternalChangedOnceOnResize() { let root = helper.getCurrentPage(); - let layout = new grid.GridLayout(); + let layout = new MyGrid(); layout.className = "myClass"; layout.backgroundColor = new color.Color(255, 255, 0, 0); root.css = ".myClass { background-image: url('~/tests/logo.png') }"; root.content = layout; - let sizeChangedCount = 0; function trackCount() { - let result = sizeChangedCount; - sizeChangedCount = 0; + let result = layout.backgroundSetterCount; + layout.backgroundSetterCount = 0; return result; } - var base = (layout.style)._applyStyleProperty; - (layout.style)._applyStyleProperty = function (property) { - base.apply(layout.style, arguments); - if (property.name === "_backgroundInternal") { - ++sizeChangedCount; - } - } - + trackCount(); layout.requestLayout(); layout.layout(0, 0, 200, 200); diff --git a/tns-core-modules/ui/action-bar/action-bar.ios.ts b/tns-core-modules/ui/action-bar/action-bar.ios.ts index 34036025d..89a85ccbe 100644 --- a/tns-core-modules/ui/action-bar/action-bar.ios.ts +++ b/tns-core-modules/ui/action-bar/action-bar.ios.ts @@ -1,6 +1,7 @@ import { IOSActionItemSettings, ActionItem as ActionItemDefinition } from "ui/action-bar"; import { ActionItemBase, ActionBarBase, isVisible, View, colorProperty, backgroundColorProperty, backgroundInternalProperty, layout } from "./action-bar-common"; import { ImageSource, fromFileOrResource } from "image-source"; +import { Color } from "color"; export * from "./action-bar-common"; @@ -295,10 +296,15 @@ export class ActionBar extends ActionBarBase { get [colorProperty.native](): UIColor { return null; } - set [colorProperty.native](color: UIColor) { - let navBar = this.navBar; - navBar.tintColor = color; - navBar.titleTextAttributes = { [NSForegroundColorAttributeName]: color }; + set [colorProperty.native](color: Color) { + const navBar = this.navBar; + if (color) { + navBar.tintColor = color.ios; + navBar.titleTextAttributes = { [NSForegroundColorAttributeName]: color.ios }; + } else { + navBar.tintColor = null; + navBar.titleTextAttributes = null; + } } get [backgroundColorProperty.native](): UIColor { diff --git a/tns-core-modules/ui/activity-indicator/activity-indicator.ios.ts b/tns-core-modules/ui/activity-indicator/activity-indicator.ios.ts index efa6d72f2..db56a8c1d 100644 --- a/tns-core-modules/ui/activity-indicator/activity-indicator.ios.ts +++ b/tns-core-modules/ui/activity-indicator/activity-indicator.ios.ts @@ -1,5 +1,6 @@ import { ActivityIndicatorBase, busyProperty, colorProperty } from "./activity-indicator-common"; import { ios } from "utils/utils"; +import { Color } from "color"; export * from "./activity-indicator-common"; @@ -36,7 +37,7 @@ export class ActivityIndicator extends ActivityIndicatorBase { get [colorProperty.native](): UIColor { return this.nativeView.color; } - set [colorProperty.native](value: UIColor) { - this.nativeView.color = value; + set [colorProperty.native](value: UIColor | Color) { + this.nativeView.color = value instanceof Color ? value.ios : value;; } } \ No newline at end of file diff --git a/tns-core-modules/ui/core/view-base.ts b/tns-core-modules/ui/core/view-base.ts index be0e01b1c..02d048c6d 100644 --- a/tns-core-modules/ui/core/view-base.ts +++ b/tns-core-modules/ui/core/view-base.ts @@ -104,7 +104,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition { public bindingContext: any; public nativeView: any; public parent: ViewBase; - public isCollapsed; + public isCollapsed = false; public id: string; public className: string; @@ -402,7 +402,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition { } protected _addViewCore(view: ViewBase, atIndex?: number) { - if (isIOS || this._context) { + if (this._context) { view._setupUI(this._context, atIndex); } @@ -443,7 +443,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition { // view.unsetInheritedProperties(); - if (isIOS || view._context) { + if (view._context) { view._tearDownUI(); } } @@ -465,7 +465,17 @@ export class ViewBase extends Observable implements ViewBaseDefinition { } public _setupUI(context: android.content.Context, atIndex?: number) { + traceNotifyEvent(this, "_setupUI"); + if (traceEnabled) { + traceWrite(`${this}._setupUI(${context})`, traceCategories.VisualTreeEvents); + } + + if (this._context === context) { + return; + } + this._context = context; + traceNotifyEvent(this, "_onContextChanged"); // TODO: refactor createUI to return native view this._createNativeView(); @@ -474,7 +484,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition { this._initNativeView(); if (this.parent) { - this.parent._addViewToNativeVisualTree(this, atIndex); + this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, atIndex); } if (this.nativeView) { @@ -485,13 +495,13 @@ export class ViewBase extends Observable implements ViewBaseDefinition { child._setupUI(context); return true; }); - - // if (traceEnabled) { - // traceNotifyEvent(this, "_onAttached"); - // } } public _tearDownUI(force?: boolean) { + if (traceEnabled) { + traceWrite(`${this}._tearDownUI(${force})`, traceCategories.VisualTreeEvents); + } + this.eachChild((child) => { child._tearDownUI(force); return true; @@ -511,6 +521,8 @@ export class ViewBase extends Observable implements ViewBaseDefinition { this._disposeNativeView(); this._context = null; + traceNotifyEvent(this, "_onContextChanged"); + traceNotifyEvent(this, "_tearDownUI"); } _childIndexToNativeChildIndex(index?: number): number { @@ -532,6 +544,7 @@ export class ViewBase extends Observable implements ViewBaseDefinition { * Method is intended to be overridden by inheritors and used as "protected" */ public _removeViewFromNativeVisualTree(view: ViewBase) { + traceNotifyEvent(view, "_removeViewFromNativeVisualTree"); view._isAddedToNativeVisualTree = false; } diff --git a/tns-core-modules/ui/frame/frame.ios.ts b/tns-core-modules/ui/frame/frame.ios.ts index 1f4f32cee..1c6043eb0 100644 --- a/tns-core-modules/ui/frame/frame.ios.ts +++ b/tns-core-modules/ui/frame/frame.ios.ts @@ -16,6 +16,8 @@ const DELEGATE = "_delegate"; let navDepth = -1; +const FRAME_CONTEXT = {}; + export class Frame extends FrameBase { private _ios: iOSFrame; private _paramToNavigate: any; @@ -29,6 +31,13 @@ export class Frame extends FrameBase { public _bottom: number; public _isInitialNavigation: boolean = true; + public get _context(): any { + return FRAME_CONTEXT; + } + public set _context(value:any) { + throw new Error("Frame _context is readonly"); + } + constructor() { super(); this._ios = new iOSFrame(this); @@ -657,7 +666,7 @@ export function _getNativeCurve(transition: NavigationTransition): UIViewAnimati traceWrite("Transition curve resolved to UIViewAnimationCurve.Linear.", traceCategories.Transition); } return UIViewAnimationCurve.Linear; - + default: if (traceEnabled) { traceWrite("Transition curve resolved to original: " + transition.curve, traceCategories.Transition); diff --git a/tns-core-modules/ui/progress/progress.ios.ts b/tns-core-modules/ui/progress/progress.ios.ts index 1bfeef91d..251683847 100644 --- a/tns-core-modules/ui/progress/progress.ios.ts +++ b/tns-core-modules/ui/progress/progress.ios.ts @@ -38,11 +38,7 @@ export class Progress extends ProgressBase { return this._ios.progressTintColor; } set [colorProperty.native](value: Color) { - if (value instanceof Color) { - this._ios.progressTintColor = value.ios; - } else { - this._ios.progressTintColor = value; - } + this._ios.progressTintColor = value instanceof Color ? value.ios : value;; } get [backgroundColorProperty.native](): UIColor { diff --git a/tns-core-modules/ui/styling/font-common.ts b/tns-core-modules/ui/styling/font-common.ts index 7ce49e48b..88e2bb91b 100644 --- a/tns-core-modules/ui/styling/font-common.ts +++ b/tns-core-modules/ui/styling/font-common.ts @@ -1,51 +1,30 @@ import { Font as FontDefinition, ParsedFont } from "ui/styling/font"; -import { makeValidator, makeParser} from "ui/core/properties"; +import { makeValidator, makeParser } from "ui/core/properties"; export abstract class FontBase implements FontDefinition { public static default = undefined; - private _fontFamily: string; - private _fontStyle: FontStyle; - private _fontWeight: FontWeight; - private _fontSize: number; - - get fontFamily(): string { - return this._fontFamily; - } - - get fontStyle(): FontStyle { - return this._fontStyle; - } - - get fontWeight(): FontWeight { - return this._fontWeight; - } - - get fontSize(): number { - return this._fontSize; - } - get isItalic(): boolean { - return this._fontStyle === FontStyle.ITALIC; + return this.fontStyle === FontStyle.ITALIC; } get isBold(): boolean { - return this._fontWeight === FontWeight.BOLD - || this._fontWeight === "700"; + return this.fontWeight === FontWeight.BOLD + || this.fontWeight === "700"; } - protected constructor(family: string, size: number, style: FontStyle, weight: FontWeight) { - this._fontFamily = family; - this._fontSize = size; - this._fontStyle = style; - this._fontWeight = weight; + protected constructor( + public readonly fontFamily: string, + public readonly fontSize: number, + public readonly fontStyle: FontStyle, + public readonly fontWeight: FontWeight) { } public abstract getAndroidTypeface(): android.graphics.Typeface; public abstract getUIFont(defaultFont: UIFont): UIFont; public abstract withFontFamily(family: string): FontBase; public abstract withFontStyle(style: string): FontBase; - public abstract withFontWeight(weight: string):FontBase; + public abstract withFontWeight(weight: string): FontBase; public abstract withFontSize(size: number): FontBase; public static equals(value1: FontBase, value2: FontBase): boolean { @@ -79,10 +58,10 @@ export namespace FontWeight { export const THIN: "100" = "100"; export const EXTRA_LIGHT: "200" = "200"; export const LIGHT: "300" = "300"; - export const NORMAL: "normal" = "normal"; + export const NORMAL: "normal" = "normal"; export const MEDIUM: "500" = "500"; export const SEMI_BOLD: "600" = "600"; - export const BOLD: "bold" = "bold"; + export const BOLD: "bold" = "bold"; export const EXTRA_BOLD: "800" = "800"; export const BLACK: "900" = "900"; export const isValid = makeValidator(THIN, EXTRA_LIGHT, LIGHT, NORMAL, "400", MEDIUM, SEMI_BOLD, BOLD, "700", EXTRA_BOLD, BLACK); @@ -114,7 +93,7 @@ export module genericFontFamilies { const styles = new Set(); [ - FontStyle.NORMAL, + FontStyle.NORMAL, FontStyle.ITALIC ].forEach((val, i, a) => styles.add(val)); @@ -132,16 +111,16 @@ const styles = new Set(); //- 900(Black / Heavy) (API21 -black) const weights = new Set(); [ - FontWeight.THIN, - FontWeight.EXTRA_LIGHT, - FontWeight.LIGHT, - FontWeight.NORMAL, - "400", - FontWeight.MEDIUM, - FontWeight.SEMI_BOLD, - FontWeight.BOLD, - "700", - FontWeight.EXTRA_BOLD, + FontWeight.THIN, + FontWeight.EXTRA_LIGHT, + FontWeight.LIGHT, + FontWeight.NORMAL, + "400", + FontWeight.MEDIUM, + FontWeight.SEMI_BOLD, + FontWeight.BOLD, + "700", + FontWeight.EXTRA_BOLD, FontWeight.BLACK ].forEach((val, i, a) => weights.add(val)); diff --git a/tns-core-modules/ui/styling/font.android.ts b/tns-core-modules/ui/styling/font.android.ts index c096267c6..0017fdef8 100644 --- a/tns-core-modules/ui/styling/font.android.ts +++ b/tns-core-modules/ui/styling/font.android.ts @@ -36,7 +36,7 @@ export class Font extends FontBase { public getAndroidTypeface(): android.graphics.Typeface { if (!this._typeface) { - var fontStyle = 0; + let fontStyle = 0; if (this.isBold) { fontStyle |= android.graphics.Typeface.BOLD; } @@ -44,7 +44,7 @@ export class Font extends FontBase { fontStyle |= android.graphics.Typeface.ITALIC; } - var typeFace = createTypeface(this); + const typeFace = createTypeface(this); this._typeface = android.graphics.Typeface.create(typeFace, fontStyle); } return this._typeface; @@ -66,8 +66,8 @@ function loadFontFromFile(fontFamily: string): android.graphics.Typeface { if (result === undefined) { result = null; - var fontAssetPath: string; - var basePath = fs.path.join(fs.knownFolders.currentApp().path, "fonts", fontFamily); + let fontAssetPath: string; + const basePath = fs.path.join(fs.knownFolders.currentApp().path, "fonts", fontFamily); if (fs.File.exists(basePath + ".ttf")) { fontAssetPath = FONTS_BASE_PATH + fontFamily + ".ttf"; } @@ -83,7 +83,7 @@ function loadFontFromFile(fontFamily: string): android.graphics.Typeface { if (fontAssetPath) { try { fontAssetPath = fs.path.join(fs.knownFolders.currentApp().path, fontAssetPath); - result = android.graphics.Typeface.createFromFile(fontAssetPath) + result = android.graphics.Typeface.createFromFile(fontAssetPath); } catch (e) { if (traceEnabled) { traceWrite("Error loading font asset: " + fontAssetPath, traceCategories.Error, traceMessageType.error); @@ -98,13 +98,13 @@ function loadFontFromFile(fontFamily: string): android.graphics.Typeface { function createTypeface(font: Font): android.graphics.Typeface { //http://stackoverflow.com/questions/19691530/valid-values-for-androidfontfamily-and-what-they-map-to - var fonts = parseFontFamily(font.fontFamily); - var result = null; + const fonts = parseFontFamily(font.fontFamily); + let result = null; if (fonts.length === 0) { return null; } - for (var i = 0; i < fonts.length; i++) { + for (let i = 0; i < fonts.length; i++) { switch (fonts[i].toLowerCase()) { case genericFontFamilies.serif: result = android.graphics.Typeface.create("serif" + getFontWeightSuffix(font.fontWeight), 0); diff --git a/tns-core-modules/ui/text-base/text-base.android.ts b/tns-core-modules/ui/text-base/text-base.android.ts index 80ef32070..90838f180 100644 --- a/tns-core-modules/ui/text-base/text-base.android.ts +++ b/tns-core-modules/ui/text-base/text-base.android.ts @@ -1,7 +1,7 @@ import { - TextBaseCommon, textProperty, formattedTextProperty, textAlignmentProperty, textDecorationProperty, - textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty, whiteSpaceProperty, - Font, Color, FormattedString, TextDecoration, TextAlignment, TextTransform, WhiteSpace, + TextBaseCommon, formattedTextProperty, textAlignmentProperty, textDecorationProperty, fontSizeProperty, + textProperty, textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty, + whiteSpaceProperty, Font, Color, FormattedString, TextDecoration, TextAlignment, TextTransform, WhiteSpace, paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, Length } from "./text-base-common"; import { toUIString } from "utils/types"; @@ -64,6 +64,18 @@ export class TextBase extends TextBaseCommon { } } + //FontSize + get [fontSizeProperty.native](): { nativeSize: number } { + return { nativeSize: this._nativeView.getTextSize() }; + } + set [fontSizeProperty.native](value: number | { nativeSize: number }) { + if (typeof value === "number") { + this._nativeView.setTextSize(value); + } else { + this._nativeView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.nativeSize); + } + } + //FontInternal get [fontInternalProperty.native](): { typeface: android.graphics.Typeface, fontSize: number } { let textView = this._nativeView; @@ -75,14 +87,11 @@ export class TextBase extends TextBaseCommon { set [fontInternalProperty.native](value: Font | { typeface: android.graphics.Typeface, fontSize: number }) { let textView = this._nativeView; if (value instanceof Font) { - // Set value + // Set value. Note: Size is handled in fontSizeProperty.native textView.setTypeface(value.getAndroidTypeface()); - if (value.fontSize !== undefined) { - textView.setTextSize(value.fontSize); - } } else { - // Reset value + // Reset value. Note: Resetting fontInternal will reset the size also. textView.setTypeface(value.typeface); textView.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.fontSize); }