mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Fix WrapLayout
Fix ScrollView Fix Stylers.android Remove some method from View class Fix layout-helper test views Fix all android failing tests Remove onLayout on Button and TextBase
This commit is contained in:
@ -31,16 +31,15 @@ export var testAll = function () {
|
||||
absoluteLayout.width = 230;
|
||||
absoluteLayout.height = 230;
|
||||
absoluteLayout.style.backgroundColor = new colorModule.Color("LightGray");
|
||||
var label;
|
||||
var label = new labelModule.Label();
|
||||
//// In absolute layout place of an UI element is determined by 4 parameters : left, top, width and height.
|
||||
label = new labelModule.Label();
|
||||
absoluteLayoutModule.AbsoluteLayout.setLeft(label, 10);
|
||||
absoluteLayoutModule.AbsoluteLayout.setTop(label, 10);
|
||||
label.width = 100;
|
||||
label.height = 100;
|
||||
label.text = "LT";
|
||||
label.id = "LT";
|
||||
label.style.backgroundColor = new colorModule.Color("Red");
|
||||
absoluteLayoutModule.AbsoluteLayout.setLeft(label, 10);
|
||||
absoluteLayoutModule.AbsoluteLayout.setTop(label, 10);
|
||||
absoluteLayout.addChild(label);
|
||||
// ```
|
||||
// </snippet>
|
||||
|
@ -1,5 +1,6 @@
|
||||
import pageModule = require("ui/page");
|
||||
import button = require("ui/button");
|
||||
import {DockLayout} from "ui/layouts/dock-layout";
|
||||
import TKUnit = require("../TKUnit");
|
||||
import helper = require("./layout-helper");
|
||||
import navHelper = require("../ui/helper");
|
||||
@ -31,31 +32,8 @@ import enums = require("ui/enums");
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
export class MyDockLayout extends dockModule.DockLayout {
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
|
||||
public get arranged(): boolean {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.measureCount++;
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(left, top, right, bottom);
|
||||
this.arrangeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
var testPage: pageModule.Page;
|
||||
var rootLayout: MyDockLayout;
|
||||
var rootLayout: DockLayout;
|
||||
var tmp: button.Button;
|
||||
|
||||
export function setUpModule() {
|
||||
@ -78,7 +56,7 @@ export function tearDownModule() {
|
||||
}
|
||||
|
||||
export function setUp() {
|
||||
rootLayout = new MyDockLayout();
|
||||
rootLayout = new DockLayout();
|
||||
rootLayout.height = 300;
|
||||
rootLayout.width = 300;
|
||||
testPage.content = rootLayout;
|
||||
@ -234,4 +212,4 @@ export function test_codesnippets() {
|
||||
dockLayout.addChild(btnDockedToRight);
|
||||
// ```
|
||||
// </snippet>
|
||||
};
|
||||
}
|
@ -82,130 +82,130 @@ function colSpan(view: view.View): number {
|
||||
return layout.GridLayout.getColumnSpan(view);
|
||||
}
|
||||
|
||||
export function test_GridLayout_row_defaultValue() {
|
||||
export function test_row_defaultValue() {
|
||||
TKUnit.assert(tmp !== null);
|
||||
TKUnit.assertEqual(row(tmp), 0, "'row' property default value should be 0.");
|
||||
}
|
||||
|
||||
export function test_GridLayout_rowSpan_defaultValue() {
|
||||
export function test_rowSpan_defaultValue() {
|
||||
|
||||
TKUnit.assert(tmp !== null);
|
||||
TKUnit.assertEqual(rowSpan(tmp), 1, "'rowSpan' property default value should be 1.");
|
||||
}
|
||||
|
||||
export function test_GridLayout_column_defaultValue() {
|
||||
export function test_column_defaultValue() {
|
||||
|
||||
TKUnit.assert(tmp !== null);
|
||||
TKUnit.assertEqual(col(tmp), 0, "'column' property default value should be 0.");
|
||||
}
|
||||
|
||||
export function test_GridLayout_columnSpan_defaultValue() {
|
||||
export function test_columnSpan_defaultValue() {
|
||||
TKUnit.assert(tmp !== null);
|
||||
TKUnit.assertEqual(colSpan(tmp), 1, "'columnSpan' property default value should be 1.");
|
||||
}
|
||||
|
||||
export function test_GridLayout_getRow_shouldThrow_onNullValues() {
|
||||
export function test_getRow_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.getRow(null);
|
||||
}, "getRow called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_getRowSpan_shouldThrow_onNullValues() {
|
||||
export function test_getRowSpan_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.getRowSpan(null);
|
||||
}, "getRowSpan called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_getColumn_shouldThrow_onNullValues() {
|
||||
export function test_getColumn_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.getColumn(null);
|
||||
}, "getColumn called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_getColumnSpan_shouldThrow_onNullValues() {
|
||||
export function test_getColumnSpan_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.getColumnSpan(null);
|
||||
}, "getColumnSpan called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_setRow_shouldThrow_onNullValues() {
|
||||
export function test_setRow_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setRow(null, 1);
|
||||
}, "setRow called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_setRowSpan_shouldThrow_onNullValues() {
|
||||
export function test_setRowSpan_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setRowSpan(null, 1);
|
||||
}, "setRowSpan called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_setColumn_shouldThrow_onNullValues() {
|
||||
export function test_setColumn_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setColumn(null, 1);
|
||||
}, "setColumn called with null should throw exception")
|
||||
}
|
||||
|
||||
export function test_GridLayout_setColumnSpan_shouldThrow_onNullValues() {
|
||||
export function test_setColumnSpan_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setColumnSpan(null, 1);
|
||||
}, "setColumnSpan called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_setRow_shouldThrow_onNegativeValues() {
|
||||
export function test_setRow_shouldThrow_onNegativeValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setRow(tmp, -1);
|
||||
}, "setRow should throw when value < 0");
|
||||
}
|
||||
|
||||
export function test_GridLayout_setRowSpan_shouldThrow_onNotPositiveValues() {
|
||||
export function test_setRowSpan_shouldThrow_onNotPositiveValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setRowSpan(tmp, 0);
|
||||
}, "setRowSpan should throw when value <= 0");
|
||||
}
|
||||
|
||||
export function test_GridLayout_setColumn_shouldThrow_onNegativeValues() {
|
||||
export function test_setColumn_shouldThrow_onNegativeValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setColumn(tmp, -1);
|
||||
}, "setColumn should when value < 0");
|
||||
}
|
||||
|
||||
export function test_GridLayout_setColumnSpan_shouldThrow_onNotPositiveValues() {
|
||||
export function test_setColumnSpan_shouldThrow_onNotPositiveValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
layout.GridLayout.setColumnSpan(tmp, 0);
|
||||
}, "setColumnSpan should throw when value <= 0");
|
||||
}
|
||||
|
||||
export function test_GridLayout_addRow_shouldThrow_onNullValues() {
|
||||
export function test_addRow_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
rootLayout.addRow(null);
|
||||
}, "addRow called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_addColumn_shouldThrow_onNullValues() {
|
||||
export function test_addColumn_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
rootLayout.addColumn(null);
|
||||
}, "addColumn called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_removeRow_shouldThrow_onNullValues() {
|
||||
export function test_removeRow_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
rootLayout.removeRow(null);
|
||||
}, "removeRow called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_removeColumn_shouldThrow_onNullValues() {
|
||||
export function test_removeColumn_shouldThrow_onNullValues() {
|
||||
TKUnit.assertThrows(() => {
|
||||
rootLayout.removeColumn(null);
|
||||
}, "removeColumn called with null should throw exception");
|
||||
}
|
||||
|
||||
export function test_GridLayout_getRows_shouldNotReturnNULL() {
|
||||
export function test_getRows_shouldNotReturnNULL() {
|
||||
var rows = rootLayout.getRows();
|
||||
TKUnit.assert(rows, "getRows should not return null/undefinied");
|
||||
}
|
||||
|
||||
export function test_GridLayout_getColumns_shouldNotReturnNULL() {
|
||||
export function test_getColumns_shouldNotReturnNULL() {
|
||||
var cols = rootLayout.getColumns();
|
||||
TKUnit.assert(cols, "getColumns should not return null/undefinied");
|
||||
}
|
||||
@ -300,19 +300,19 @@ function prepareGridLayout(wait?: boolean) {
|
||||
|
||||
if (wait) {
|
||||
TKUnit.waitUntilReady(function () {
|
||||
return (rootLayout.getChildAt(rootLayout.getChildrenCount() - 1)).isLayoutValid;
|
||||
return rootLayout.isLayoutValid;
|
||||
}, ASYNC);
|
||||
}
|
||||
}
|
||||
|
||||
export function test_GridLayout_desiredSize_isCorrect() {
|
||||
export function test_desiredSize_isCorrect() {
|
||||
prepareGridLayout(false);
|
||||
|
||||
rootLayout.width = Number.NaN;
|
||||
rootLayout.height = Number.NaN;
|
||||
|
||||
TKUnit.waitUntilReady(function () {
|
||||
return rootLayout.getChildAt(rootLayout.getChildrenCount() - 1).isLayoutValid;
|
||||
return rootLayout.isLayoutValid;
|
||||
}, ASYNC);
|
||||
|
||||
var maxWidth = 0;
|
||||
@ -356,7 +356,7 @@ export function test_GridLayout_desiredSize_isCorrect() {
|
||||
TKUnit.assertAreClose(measuredHeight, maxHeight, delta, "GridLayout incorrect measured height");
|
||||
}
|
||||
|
||||
export function test_GridLayout_columnsActualWidth_isCorrect() {
|
||||
export function test_columnsActualWidth_isCorrect() {
|
||||
prepareGridLayout(true);
|
||||
|
||||
var cols = rootLayout.getColumns();
|
||||
@ -366,7 +366,7 @@ export function test_GridLayout_columnsActualWidth_isCorrect() {
|
||||
TKUnit.assertEqual(cols[3].actualLength, 100, "Auto column should be 100px width");
|
||||
}
|
||||
|
||||
export function test_GridLayout_rowsActualHeight_isCorrect() {
|
||||
export function test_rowsActualHeight_isCorrect() {
|
||||
prepareGridLayout(true);
|
||||
|
||||
var rows = rootLayout.getRows();
|
||||
@ -376,7 +376,7 @@ export function test_GridLayout_rowsActualHeight_isCorrect() {
|
||||
TKUnit.assertEqual(rows[3].actualLength, 100, "Auto row should be 100px width");
|
||||
}
|
||||
|
||||
export function test_GridLayout_Measure_and_Layout_Children_withCorrect_size() {
|
||||
export function test_Measure_and_Layout_Children_withCorrect_size() {
|
||||
|
||||
prepareGridLayout(true);
|
||||
|
||||
@ -407,7 +407,7 @@ export function test_GridLayout_Measure_and_Layout_Children_withCorrect_size() {
|
||||
TKUnit.assertAreClose(btn.layoutHeight, h, delta, "Absolute rows should layout with specific height");
|
||||
}
|
||||
else {
|
||||
TKUnit.assertAreClose(btn.measureHeight, h, delta, "Auto rows should measure with specific height");
|
||||
TKUnit.assertAreClose(btn.measureHeight, h, delta, "Star rows should measure with specific height");
|
||||
TKUnit.assertAreClose(btn.layoutHeight, h, delta, "Star rows should layout with exact length");
|
||||
}
|
||||
|
||||
@ -419,14 +419,14 @@ export function test_GridLayout_Measure_and_Layout_Children_withCorrect_size() {
|
||||
TKUnit.assertAreClose(btn.layoutWidth, w, delta, "Absolute columns should layout with specific width");
|
||||
}
|
||||
else {
|
||||
TKUnit.assertAreClose(btn.measureWidth, w, delta, "Auto columns should should measure with specific width");
|
||||
TKUnit.assertAreClose(btn.measureWidth, w, delta, "Star columns should measure with specific width");
|
||||
TKUnit.assertAreClose(btn.layoutWidth, w, delta, "Star columns should layout with exact length");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function test_GridLayout_ColumnWidth_when_4stars_and_width_110() {
|
||||
export function test_ColumnWidth_when_4stars_and_width_110() {
|
||||
|
||||
rootLayout.width = 110;
|
||||
rootLayout.addColumn(new layout.ItemSpec(1, layout.GridUnitType.star));
|
||||
@ -449,7 +449,7 @@ export function test_GridLayout_ColumnWidth_when_4stars_and_width_110() {
|
||||
TKUnit.assertAreClose(cols[3].actualLength, 27, delta, "Column[3] actual length should be 27");
|
||||
}
|
||||
|
||||
export function test_GridLayout_margins_and_verticalAlignment_center() {
|
||||
export function test_margins_and_verticalAlignment_center() {
|
||||
|
||||
rootLayout.height = 200;
|
||||
rootLayout.width = 200;
|
||||
@ -472,7 +472,7 @@ export function test_GridLayout_margins_and_verticalAlignment_center() {
|
||||
TKUnit.assertAreClose(btn.layoutLeft, 25 * density, delta, "horizontal margins");
|
||||
}
|
||||
|
||||
export function test_GridLayout_set_columns_in_XML() {
|
||||
export function test_set_columns_in_XML() {
|
||||
var p = <page.Page>builder.parse("<Page><GridLayout columns=\"auto, *, 10*, 100 \"><Button/></GridLayout></Page>");
|
||||
var grid = <layout.GridLayout>p.content;
|
||||
|
||||
@ -491,7 +491,7 @@ export function test_GridLayout_set_columns_in_XML() {
|
||||
TKUnit.assertEqual(columns[3].value, 100, "columns[3].value");
|
||||
};
|
||||
|
||||
export function test_GridLayout_set_rows_in_XML() {
|
||||
export function test_set_rows_in_XML() {
|
||||
var p = <page.Page>builder.parse("<Page><GridLayout rows=\"auto, *, 10*, 100 \"><Button/></GridLayout></Page>");
|
||||
var grid = <layout.GridLayout>p.content;
|
||||
|
||||
@ -510,7 +510,7 @@ export function test_GridLayout_set_rows_in_XML() {
|
||||
TKUnit.assertEqual(rows[3].value, 100, "rows[3].value");
|
||||
};
|
||||
|
||||
export function test_GridLayout_padding() {
|
||||
export function test_padding() {
|
||||
rootLayout.paddingLeft = 10;
|
||||
rootLayout.paddingTop = 20;
|
||||
rootLayout.paddingRight = 30;
|
||||
|
@ -1,6 +1,8 @@
|
||||
import button = require("ui/button");
|
||||
import {StackLayout} from "ui/layouts/stack-layout";
|
||||
import utils = require("utils/utils");
|
||||
import TKUnit = require("../TKUnit");
|
||||
import def = require("./layout-helper");
|
||||
|
||||
var DELTA = 0.1;
|
||||
|
||||
@ -16,6 +18,8 @@ class NativeButton extends android.widget.Button {
|
||||
|
||||
protected onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.owner._oldWidthMeasureSpec = widthMeasureSpec;
|
||||
this.owner._oldHeightMeasureSpec = heightMeasureSpec;
|
||||
|
||||
this.owner._measureWidth = utils.layout.getMeasureSpecSize(widthMeasureSpec);
|
||||
this.owner._measureHeight = utils.layout.getMeasureSpecSize(heightMeasureSpec);
|
||||
@ -33,10 +37,27 @@ class NativeButton extends android.widget.Button {
|
||||
}
|
||||
}
|
||||
|
||||
export class MyButton extends button.Button {
|
||||
export class MyButton extends button.Button implements def.MyButton {
|
||||
private _layout: NativeButton;
|
||||
|
||||
get android(): NativeButton {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
get _nativeView(): NativeButton {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
public _createUI() {
|
||||
this._layout = new NativeButton(this._context, this);
|
||||
}
|
||||
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
_oldWidthMeasureSpec: number = Number.NaN;
|
||||
_oldHeightMeasureSpec: number = Number.NaN;
|
||||
|
||||
_layoutLeft;
|
||||
_layoutTop;
|
||||
_layoutWidth;
|
||||
@ -53,20 +74,6 @@ export class MyButton extends button.Button {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
private _layout: NativeButton;
|
||||
|
||||
get android(): NativeButton {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
get _nativeView(): NativeButton {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
public _createUI() {
|
||||
this._layout = new NativeButton(this._context, this);
|
||||
}
|
||||
|
||||
get measureHeight(): number {
|
||||
return this._measureHeight;
|
||||
}
|
||||
@ -90,6 +97,61 @@ export class MyButton extends button.Button {
|
||||
get layoutTop(): number {
|
||||
return this._layoutTop;
|
||||
}
|
||||
|
||||
_getCurrentMeasureSpecs(): { widthMeasureSpec: number; heightMeasureSpec: number } {
|
||||
return {
|
||||
widthMeasureSpec: this._oldWidthMeasureSpec,
|
||||
heightMeasureSpec: this._oldHeightMeasureSpec
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class NativeStackLayout extends org.nativescript.widgets.StackLayout {
|
||||
|
||||
private owner: MyStackLayout;
|
||||
|
||||
constructor(context: android.content.Context, owner: MyStackLayout) {
|
||||
super(context);
|
||||
this.owner = owner;
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
protected onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.owner.measureCount++;
|
||||
}
|
||||
|
||||
protected onLayout(changed: boolean, left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
this.owner.arrangeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
export class MyStackLayout extends StackLayout implements def.MyStackLayout {
|
||||
private _layout: NativeStackLayout;
|
||||
|
||||
get android(): NativeStackLayout {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
get _nativeView(): NativeStackLayout {
|
||||
return this._layout;
|
||||
}
|
||||
|
||||
public _createUI() {
|
||||
this._layout = new NativeStackLayout(this._context, this);
|
||||
}
|
||||
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
|
||||
public get arranged(): boolean {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
}
|
||||
|
||||
export function assertMeasure(btn: MyButton, width: number, height: number, name?: string) {
|
||||
|
@ -1,9 +1,33 @@
|
||||
import button = require("ui/button");
|
||||
import utils = require("utils/utils");
|
||||
import TKUnit = require("../TKUnit");
|
||||
import {StackLayout} from "ui/layouts/stack-layout";
|
||||
|
||||
var DELTA = 0.1;
|
||||
|
||||
export class MyStackLayout extends StackLayout {
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
|
||||
public get arranged(): boolean {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.measureCount++;
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(left, top, right, bottom);
|
||||
this.arrangeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
export class MyButton extends button.Button {
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
@ -9,32 +9,9 @@ import utils = require("utils/utils");
|
||||
|
||||
var ASYNC = 2;
|
||||
|
||||
export class MyStackLayout extends StackLayout {
|
||||
public measureCount: number = 0;
|
||||
public arrangeCount: number = 0;
|
||||
|
||||
public get measured(): boolean {
|
||||
return this.measureCount > 0;
|
||||
}
|
||||
|
||||
public get arranged(): boolean {
|
||||
return this.arrangeCount > 0;
|
||||
}
|
||||
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
this.measureCount++;
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(left, top, right, bottom);
|
||||
this.arrangeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
var tmp: Button;
|
||||
var newPage: Page;
|
||||
var rootLayout: MyStackLayout;
|
||||
var rootLayout: helper.MyStackLayout;
|
||||
var btn1: helper.MyButton;
|
||||
var btn2: helper.MyButton;
|
||||
|
||||
@ -60,7 +37,7 @@ export function tearDownModule() {
|
||||
}
|
||||
|
||||
export function setUp() {
|
||||
rootLayout = new MyStackLayout();
|
||||
rootLayout = new helper.MyStackLayout();
|
||||
btn1 = new helper.MyButton();
|
||||
btn1.text = "btn1";
|
||||
rootLayout.addChild(btn1);
|
||||
@ -83,7 +60,7 @@ export function test_SetWrongOrientation_ShouldThrowError() {
|
||||
"Setting invalid value for orientation should throw exception.");
|
||||
}
|
||||
|
||||
export function test_StackLayout_Orientation_Change() {
|
||||
export function test_Orientation_Change() {
|
||||
|
||||
TKUnit.waitUntilReady(function () {
|
||||
return rootLayout.arranged;
|
||||
@ -102,7 +79,7 @@ export function test_StackLayout_Orientation_Change() {
|
||||
TKUnit.assertEqual(rootLayout.arrangeCount, 2, "Orientation change should invalidate arrange.");
|
||||
}
|
||||
|
||||
export function test_StackLayout_ShouldMeasureWith_AtMost_OnVertical() {
|
||||
export function test_ShouldMeasureWith_AtMost_OnVertical() {
|
||||
|
||||
TKUnit.waitUntilReady(function () {
|
||||
return btn1.isLayoutValid;
|
||||
@ -117,7 +94,7 @@ export function test_StackLayout_ShouldMeasureWith_AtMost_OnVertical() {
|
||||
TKUnit.assertEqual(utils.layout.getMeasureSpecMode(specs.heightMeasureSpec), utils.layout.AT_MOST, "Layout should measure child with AT_MOST Height in vertical orientation.");
|
||||
}
|
||||
|
||||
export function test_StackLayout_ShouldMeasureWith_AtMost_OnHorizontal() {
|
||||
export function test_ShouldMeasureWith_AtMost_OnHorizontal() {
|
||||
|
||||
rootLayout.orientation = enums.Orientation.horizontal;
|
||||
|
||||
@ -133,7 +110,7 @@ export function test_StackLayout_ShouldMeasureWith_AtMost_OnHorizontal() {
|
||||
TKUnit.assertEqual(utils.layout.getMeasureSpecMode(specs.widthMeasureSpec), utils.layout.AT_MOST, "Layout should measure child with AT_MOST Width in horizontal orientation.");
|
||||
}
|
||||
|
||||
export function test_StackLayout_DesiredSize_Vertical() {
|
||||
export function test_DesiredSize_Vertical() {
|
||||
|
||||
rootLayout.verticalAlignment = enums.VerticalAlignment.top;
|
||||
rootLayout.horizontalAlignment = enums.HorizontalAlignment.left;
|
||||
@ -145,7 +122,7 @@ export function test_StackLayout_DesiredSize_Vertical() {
|
||||
TKUnit.assertEqual(rootLayout.getMeasuredHeight(), (btn1.getMeasuredHeight() + btn2.getMeasuredHeight()), "Layout getMeasuredHeight should be Sum of children getMeasuredHeight");
|
||||
}
|
||||
|
||||
export function test_StackLayout_DesiredSize_Horizontal() {
|
||||
export function test_DesiredSize_Horizontal() {
|
||||
|
||||
rootLayout.horizontalAlignment = enums.HorizontalAlignment.left;
|
||||
rootLayout.verticalAlignment = enums.VerticalAlignment.top;
|
||||
@ -159,7 +136,7 @@ export function test_StackLayout_DesiredSize_Horizontal() {
|
||||
TKUnit.assertEqual(rootLayout.getMeasuredHeight(), Math.max(btn1.getMeasuredHeight(), btn2.getMeasuredHeight()), "Layout getMeasuredHeight should be Max of children getMeasuredHeight");
|
||||
}
|
||||
|
||||
export function test_StackLayout_Padding_Vertical() {
|
||||
export function test_Padding_Vertical() {
|
||||
rootLayout.width = 300;
|
||||
rootLayout.height = 300;
|
||||
|
||||
@ -176,13 +153,13 @@ export function test_StackLayout_Padding_Vertical() {
|
||||
}, ASYNC);
|
||||
|
||||
helper.assertMeasure(btn1, 260, 50);
|
||||
helper.assertMeasure(btn1, 260, 50);
|
||||
helper.assertMeasure(btn2, 260, 50);
|
||||
|
||||
helper.assertLayout(btn1, 10, 20, 260, 50, "btn1");
|
||||
helper.assertLayout(btn2, 10, 70, 260, 50, "btn2");
|
||||
}
|
||||
|
||||
export function test_StackLayout_Padding_Horizontal() {
|
||||
export function test_Padding_Horizontal() {
|
||||
rootLayout.width = 300;
|
||||
rootLayout.height = 300;
|
||||
rootLayout.orientation = enums.Orientation.horizontal;
|
||||
@ -200,7 +177,7 @@ export function test_StackLayout_Padding_Horizontal() {
|
||||
}, ASYNC);
|
||||
|
||||
helper.assertMeasure(btn1, 50, 240);
|
||||
helper.assertMeasure(btn1, 50, 240);
|
||||
helper.assertMeasure(btn2, 50, 240);
|
||||
|
||||
helper.assertLayout(btn1, 10, 20, 50, 240, "btn1");
|
||||
helper.assertLayout(btn2, 60, 20, 50, 240, "btn2");
|
||||
@ -266,4 +243,4 @@ export function test_codesnippets() {
|
||||
// ```
|
||||
|
||||
// </snippet>
|
||||
};
|
||||
}
|
||||
|
@ -64,17 +64,17 @@ export function testHorizontalOrientation() {
|
||||
return wrapLayout.getChildAt(wrapLayout.getChildrenCount() - 1).isLayoutValid;
|
||||
}, 1);
|
||||
|
||||
var actualValue = viewModule.getViewById(wrapLayout, "0")._getCurrentLayoutBounds();
|
||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft");
|
||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom");
|
||||
var actualValue = wrapLayout.getChildAt(0)._getCurrentLayoutBounds();
|
||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 0");
|
||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 0");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 0");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 0");
|
||||
|
||||
actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds();
|
||||
TKUnit.assertEqual(actualValue.left, layoutHelper.dip(100), "ActualLeft");
|
||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(200), "ActualRight");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom");
|
||||
TKUnit.assertEqual(actualValue.left, layoutHelper.dip(100), "ActualLeft on Index 1");
|
||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 1");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(200), "ActualRight on Index 1");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 1");
|
||||
});
|
||||
}
|
||||
|
||||
@ -92,16 +92,16 @@ export function testVerticalOrientation() {
|
||||
}, 1);
|
||||
|
||||
var actualValue = viewModule.getViewById(wrapLayout, "0")._getCurrentLayoutBounds();
|
||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft");
|
||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom");
|
||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 0");
|
||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 0");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 0");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 0");
|
||||
|
||||
actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds();
|
||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft");
|
||||
TKUnit.assertEqual(actualValue.top, layoutHelper.dip(100), "ActualTop");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(200), "ActualBottom");
|
||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 1");
|
||||
TKUnit.assertEqual(actualValue.top, layoutHelper.dip(100), "ActualTop on Index 1");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 1");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(200), "ActualBottom on Index 1");
|
||||
});
|
||||
}
|
||||
|
||||
@ -116,16 +116,16 @@ export function testChangeOrientation() {
|
||||
});
|
||||
|
||||
var actualValue = viewModule.getViewById(wrapLayout, "0")._getCurrentLayoutBounds();
|
||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft");
|
||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom");
|
||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 0");
|
||||
TKUnit.assertEqual(actualValue.top, 0, "ActualTop on Index 0");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 0");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(100), "ActualBottom on Index 0");
|
||||
|
||||
actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds();
|
||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft");
|
||||
TKUnit.assertEqual(actualValue.top, layoutHelper.dip(100), "ActualTop");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(200), "ActualBottom");
|
||||
TKUnit.assertEqual(actualValue.left, 0, "ActualLeft on Index 1");
|
||||
TKUnit.assertEqual(actualValue.top, layoutHelper.dip(100), "ActualTop on Index 1");
|
||||
TKUnit.assertEqual(actualValue.right, layoutHelper.dip(100), "ActualRight on Index 1");
|
||||
TKUnit.assertEqual(actualValue.bottom, layoutHelper.dip(200), "ActualBottom on Index 1");
|
||||
});
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ export function testItemWidth() {
|
||||
}, 1);
|
||||
|
||||
var actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds().left;
|
||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualLeft");
|
||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualLeft on Index 1");
|
||||
});
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ export function testChangeItemWidth() {
|
||||
});
|
||||
|
||||
var actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds().left;
|
||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualLeft");
|
||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualLeft on Index 1");
|
||||
});
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ export function testItemHeight() {
|
||||
}, 1);
|
||||
|
||||
var actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds().top;
|
||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualTop");
|
||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualTop on Index 1");
|
||||
});
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ export function testChangeItemHeight() {
|
||||
});
|
||||
|
||||
var actualValue = viewModule.getViewById(wrapLayout, "1")._getCurrentLayoutBounds().top;
|
||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualTop");
|
||||
TKUnit.assertEqual(actualValue, layoutHelper.dip(50), "ActualTop on Index 1");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,7 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
||||
actualTextSize = testLabel.android.getTextSize();
|
||||
var density = utils.layout.getDisplayDensity();
|
||||
expSize = fontSize * density;
|
||||
TKUnit.assertEqual(actualTextSize, expSize, "Wrong native FontSize");
|
||||
TKUnit.assertAreClose(actualTextSize, expSize, 0.1, "Wrong native FontSize");
|
||||
|
||||
actualColors = testLabel.android.getTextColors();
|
||||
expColor = android.graphics.Color.parseColor(color);
|
||||
|
@ -1,6 +1,4 @@
|
||||
import common = require("ui/button/button-common");
|
||||
import utils = require("utils/utils");
|
||||
import trace = require("trace");
|
||||
|
||||
global.moduleMerge(common, exports);
|
||||
|
||||
@ -36,26 +34,4 @@ export class Button extends common.Button {
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
if (this.android) {
|
||||
var measuredWidth = this.getMeasuredWidth();
|
||||
var measuredHeight = this.getMeasuredHeight();
|
||||
|
||||
var measureSpecs = this._getCurrentMeasureSpecs();
|
||||
var widthModeIsNotExact = utils.layout.getMeasureSpecMode(measureSpecs.widthMeasureSpec) !== utils.layout.EXACTLY;
|
||||
var heightModeIsNotExact = utils.layout.getMeasureSpecMode(measureSpecs.heightMeasureSpec) !== utils.layout.EXACTLY;
|
||||
|
||||
var width = right - left;
|
||||
var height = bottom - top;
|
||||
if ((Math.abs(measuredWidth - width) > 1 && widthModeIsNotExact) || (Math.abs(measuredHeight - height) > 1 && heightModeIsNotExact)) {
|
||||
var widthMeasureSpec = utils.layout.makeMeasureSpec(width, utils.layout.EXACTLY);
|
||||
var heightMeasureSpec = utils.layout.makeMeasureSpec(height, utils.layout.EXACTLY);
|
||||
trace.write(this + ", measuredSize: (" + measuredWidth + ", " + measuredHeight + ")" + ", remeasure with: (" + width + ", " + height + ")", trace.categories.Layout);
|
||||
this.android.measure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
|
||||
super.onLayout(left, top, right, bottom);
|
||||
}
|
||||
}
|
@ -688,13 +688,6 @@ export class View extends proxy.ProxyObject implements definition.View {
|
||||
return utils.layout.makeMeasureSpec(resultSize, resultMode);
|
||||
}
|
||||
|
||||
_getCurrentMeasureSpecs(): { widthMeasureSpec: number; heightMeasureSpec: number } {
|
||||
return {
|
||||
widthMeasureSpec: this._oldWidthMeasureSpec,
|
||||
heightMeasureSpec: this._oldHeightMeasureSpec
|
||||
};
|
||||
}
|
||||
|
||||
_setCurrentMeasureSpecs(widthMeasureSpec: number, heightMeasureSpec: number): boolean {
|
||||
var changed: boolean = this._oldWidthMeasureSpec !== widthMeasureSpec || this._oldHeightMeasureSpec !== heightMeasureSpec;
|
||||
this._oldWidthMeasureSpec = widthMeasureSpec;
|
||||
|
@ -292,6 +292,35 @@ export class View extends viewCommon.View {
|
||||
}
|
||||
}
|
||||
|
||||
_getCurrentLayoutBounds(): { left: number; top: number; right: number; bottom: number } {
|
||||
if (this._nativeView) {
|
||||
return {
|
||||
left: this._nativeView.getLeft(),
|
||||
top: this._nativeView.getTop(),
|
||||
right: this._nativeView.getRight(),
|
||||
bottom: this._nativeView.getBottom()
|
||||
};
|
||||
}
|
||||
|
||||
return super._getCurrentLayoutBounds();
|
||||
}
|
||||
|
||||
public getMeasuredWidth(): number {
|
||||
if (this._nativeView) {
|
||||
return this._nativeView.getMeasuredWidth();
|
||||
}
|
||||
|
||||
return super.getMeasuredWidth();
|
||||
}
|
||||
|
||||
public getMeasuredHeight(): number {
|
||||
if (this._nativeView) {
|
||||
return this._nativeView.getMeasuredHeight();
|
||||
}
|
||||
|
||||
return super.getMeasuredHeight();
|
||||
}
|
||||
|
||||
public focus(): boolean {
|
||||
if (this._nativeView) {
|
||||
return this._nativeView.requestFocus();
|
||||
|
9
ui/core/view.d.ts
vendored
9
ui/core/view.d.ts
vendored
@ -425,17 +425,12 @@ declare module "ui/core/view" {
|
||||
_updateLayout(): void;
|
||||
|
||||
/**
|
||||
* Called my measure method to cache measureSpecs.
|
||||
* Called by measure method to cache measureSpecs.
|
||||
*/
|
||||
_setCurrentMeasureSpecs(widthMeasureSpec: number, heightMeasureSpec: number): boolean;
|
||||
|
||||
/**
|
||||
* Returns view measureSpecs.
|
||||
*/
|
||||
_getCurrentMeasureSpecs(): { widthMeasureSpec: number; heightMeasureSpec: number };
|
||||
|
||||
/**
|
||||
* Called my layout method to cache view bounds.
|
||||
* Called by layout method to cache view bounds.
|
||||
*/
|
||||
_setCurrentLayoutBounds(left: number, top: number, right: number, bottom: number): void;
|
||||
|
||||
|
@ -44,7 +44,7 @@ function setNativeColumnSpanProperty(data: dependencyObservable.PropertyChangeDa
|
||||
(<proxy.PropertyMetadata>common.GridLayout.columnProperty.metadata).onSetNativeValue = setNativeColumnProperty;
|
||||
(<proxy.PropertyMetadata>common.GridLayout.columnSpanProperty.metadata).onSetNativeValue = setNativeColumnSpanProperty;
|
||||
|
||||
function createNativeSpec(itemSpec: common.ItemSpec): org.nativescript.widgets.ItemSpec {
|
||||
function createNativeSpec(itemSpec: ItemSpec): org.nativescript.widgets.ItemSpec {
|
||||
switch (itemSpec.gridUnitType) {
|
||||
case common.GridUnitType.auto:
|
||||
return new org.nativescript.widgets.ItemSpec(itemSpec.value, org.nativescript.widgets.GridUnitType.auto);
|
||||
@ -60,6 +60,18 @@ function createNativeSpec(itemSpec: common.ItemSpec): org.nativescript.widgets.I
|
||||
}
|
||||
}
|
||||
|
||||
export class ItemSpec extends common.ItemSpec {
|
||||
nativeSpec: org.nativescript.widgets.ItemSpec;
|
||||
|
||||
public get actualLength(): number {
|
||||
if (this.nativeSpec) {
|
||||
return this.nativeSpec.getActualLength() / utils.layout.getDisplayDensity();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export class GridLayout extends common.GridLayout {
|
||||
|
||||
private _layout: org.nativescript.widgets.GridLayout;
|
||||
@ -76,29 +88,35 @@ export class GridLayout extends common.GridLayout {
|
||||
this._layout = new org.nativescript.widgets.GridLayout(this._context);
|
||||
|
||||
// Update native GridLayout
|
||||
this.getRows().forEach((itemSpec, index, rows) => { this.onRowAdded(itemSpec); }, this);
|
||||
this.getColumns().forEach((itemSpec, index, rows) => { this.onColumnAdded(itemSpec); }, this);
|
||||
this.getRows().forEach((itemSpec: ItemSpec, index, rows) => { this.onRowAdded(itemSpec); }, this);
|
||||
this.getColumns().forEach((itemSpec: ItemSpec, index, rows) => { this.onColumnAdded(itemSpec); }, this);
|
||||
}
|
||||
|
||||
protected onRowAdded(itemSpec: common.ItemSpec) {
|
||||
protected onRowAdded(itemSpec: ItemSpec) {
|
||||
if (this._layout) {
|
||||
this._layout.addRow(createNativeSpec(itemSpec));
|
||||
var nativeSpec = createNativeSpec(itemSpec);
|
||||
itemSpec.nativeSpec = nativeSpec;
|
||||
this._layout.addRow(nativeSpec);
|
||||
}
|
||||
}
|
||||
|
||||
protected onColumnAdded(itemSpec: common.ItemSpec) {
|
||||
protected onColumnAdded(itemSpec: ItemSpec) {
|
||||
if (this._layout) {
|
||||
this._layout.addColumn(createNativeSpec(itemSpec));
|
||||
var nativeSpec = createNativeSpec(itemSpec);
|
||||
itemSpec.nativeSpec = nativeSpec;
|
||||
this._layout.addColumn(nativeSpec);
|
||||
}
|
||||
}
|
||||
|
||||
protected onRowRemoved(itemSpec: common.ItemSpec, index: number) {
|
||||
protected onRowRemoved(itemSpec: ItemSpec, index: number) {
|
||||
itemSpec.nativeSpec = null;
|
||||
if (this._layout) {
|
||||
this._layout.removeRowAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
protected onColumnRemoved(itemSpec: common.ItemSpec, index: number) {
|
||||
protected onColumnRemoved(itemSpec: ItemSpec, index: number) {
|
||||
itemSpec.nativeSpec = null;
|
||||
if (this._layout) {
|
||||
this._layout.removeColumnAt(index);
|
||||
}
|
||||
|
@ -12,12 +12,7 @@ export class StackLayout extends common.StackLayout {
|
||||
static setNativeOrientationProperty(data: dependencyObservable.PropertyChangeData): void {
|
||||
var stackLayout = <StackLayout>data.object;
|
||||
var nativeView = stackLayout._nativeView;
|
||||
if (data.newValue === enums.Orientation.vertical) {
|
||||
nativeView.setOrientation(org.nativescript.widgets.Orientation.vertical);
|
||||
}
|
||||
else {
|
||||
nativeView.setOrientation(org.nativescript.widgets.Orientation.horzontal);
|
||||
}
|
||||
nativeView.setOrientation(data.newValue === enums.Orientation.vertical ? org.nativescript.widgets.Orientation.vertical : org.nativescript.widgets.Orientation.horzontal);
|
||||
}
|
||||
|
||||
private _layout: org.nativescript.widgets.StackLayout;
|
||||
|
@ -1,6 +1,8 @@
|
||||
import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import common = require("ui/layouts/wrap-layout/wrap-layout-common");
|
||||
import enums = require("ui/enums");
|
||||
import utils = require("utils/utils");
|
||||
|
||||
// merge the exports of the common file with the exports of this file
|
||||
declare var exports;
|
||||
@ -11,19 +13,19 @@ export class WrapLayout extends common.WrapLayout {
|
||||
static setNativeOrientationProperty(data: dependencyObservable.PropertyChangeData): void {
|
||||
var wrapLayout = <WrapLayout>data.object;
|
||||
var nativeView = wrapLayout._nativeView;
|
||||
nativeView.setOrientation(data.newValue);
|
||||
nativeView.setOrientation(data.newValue === enums.Orientation.vertical ? org.nativescript.widgets.Orientation.vertical : org.nativescript.widgets.Orientation.horzontal);
|
||||
}
|
||||
|
||||
static setNativeItemWidthProperty(data: dependencyObservable.PropertyChangeData): void {
|
||||
var wrapLayout = <WrapLayout>data.object;
|
||||
var nativeView = wrapLayout._nativeView;
|
||||
nativeView.setItemWidth(data.newValue);
|
||||
nativeView.setItemWidth(data.newValue * utils.layout.getDisplayDensity());
|
||||
}
|
||||
|
||||
static setNativeItemHeightProperty(data: dependencyObservable.PropertyChangeData): void {
|
||||
var wrapLayout = <WrapLayout>data.object;
|
||||
var nativeView = wrapLayout._nativeView;
|
||||
nativeView.setItemHeight(data.newValue);
|
||||
nativeView.setItemHeight(data.newValue * utils.layout.getDisplayDensity());
|
||||
}
|
||||
|
||||
private _layout: org.nativescript.widgets.WrapLayout;
|
||||
@ -42,5 +44,5 @@ export class WrapLayout extends common.WrapLayout {
|
||||
}
|
||||
|
||||
(<proxy.PropertyMetadata>common.WrapLayout.orientationProperty.metadata).onSetNativeValue = WrapLayout.setNativeOrientationProperty;
|
||||
(<proxy.PropertyMetadata>common.WrapLayout.orientationProperty.metadata).onSetNativeValue = WrapLayout.setNativeItemWidthProperty;
|
||||
(<proxy.PropertyMetadata>common.WrapLayout.orientationProperty.metadata).onSetNativeValue = WrapLayout.setNativeItemHeightProperty;
|
||||
(<proxy.PropertyMetadata>common.WrapLayout.itemWidthProperty.metadata).onSetNativeValue = WrapLayout.setNativeItemWidthProperty;
|
||||
(<proxy.PropertyMetadata>common.WrapLayout.itemHeightProperty.metadata).onSetNativeValue = WrapLayout.setNativeItemHeightProperty;
|
@ -56,8 +56,7 @@ class DataSource extends NSObject implements UITableViewDataSource {
|
||||
if (cellView) {
|
||||
// Arrange cell views. We do it here instead of _layoutCell because _layoutCell is called
|
||||
// from 'tableViewHeightForRowAtIndexPath' method too (in iOS 7.1) and we don't want to arrange the fake cell.
|
||||
var specs = this._owner._getCurrentMeasureSpecs();
|
||||
var width = utils.layout.getMeasureSpecSize(specs.widthMeasureSpec);
|
||||
var width = utils.layout.getMeasureSpecSize(this._owner.widthMeasureSpec);
|
||||
var cellHeight = this._owner.getHeight(indexPath.row);
|
||||
view.View.layoutChild(this._owner, cellView, 0, 0, width, cellHeight);
|
||||
}
|
||||
@ -75,6 +74,7 @@ class UITableViewDelegateImpl extends NSObject implements UITableViewDelegate {
|
||||
|
||||
private _owner: ListView;
|
||||
private _measureCell: UITableViewCell;
|
||||
|
||||
public initWithOwner(owner: ListView): UITableViewDelegateImpl {
|
||||
this._owner = owner;
|
||||
return this;
|
||||
@ -135,6 +135,8 @@ export class ListView extends common.ListView {
|
||||
private _preparingCell: boolean = false;
|
||||
private _isDataDirty: boolean = false;
|
||||
|
||||
widthMeasureSpec: number = 0;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
@ -197,6 +199,7 @@ export class ListView extends common.ListView {
|
||||
}
|
||||
|
||||
public measure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
this.widthMeasureSpec = widthMeasureSpec;
|
||||
var changed = this._setCurrentMeasureSpecs(widthMeasureSpec, heightMeasureSpec);
|
||||
super.measure(widthMeasureSpec, heightMeasureSpec);
|
||||
if (changed) {
|
||||
@ -207,8 +210,7 @@ export class ListView extends common.ListView {
|
||||
private _layoutCell(cellView: view.View, indexPath: NSIndexPath): number {
|
||||
|
||||
if (cellView) {
|
||||
var widthMeasureSpecs = this._getCurrentMeasureSpecs().widthMeasureSpec;
|
||||
var measuredSize = view.View.measureChild(this, cellView, widthMeasureSpecs, infinity);
|
||||
var measuredSize = view.View.measureChild(this, cellView, this.widthMeasureSpec, infinity);
|
||||
var height = measuredSize.measuredHeight;
|
||||
this.setHeight(indexPath.row, height);
|
||||
return height;
|
||||
|
@ -51,7 +51,7 @@ export class ScrollView extends contentView.ContentView implements definition.Sc
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this._android.getScrollableLength();
|
||||
return this._android.getScrollableLength() / utils.layout.getDisplayDensity();
|
||||
}
|
||||
|
||||
get scrollableHeight(): number {
|
||||
@ -59,7 +59,7 @@ export class ScrollView extends contentView.ContentView implements definition.Sc
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this._android.getScrollableLength();
|
||||
return this._android.getScrollableLength() / utils.layout.getDisplayDensity();
|
||||
}
|
||||
|
||||
public scrollToVerticalOffset(value: number, animated: boolean) {
|
||||
|
@ -99,13 +99,18 @@ export class DefaultStyler implements definition.stylers.Styler {
|
||||
(<android.view.View>view._nativeView).setMinimumHeight(0);
|
||||
}
|
||||
|
||||
private static setNativeLayoutParamsProperty(view: view.View, params: style.CommonLayoutParams): void {
|
||||
var nativeView: android.view.View = view._nativeView;
|
||||
|
||||
private static getNativeLayoutParams(nativeView: android.view.View): org.nativescript.widgets.CommonLayoutParams {
|
||||
var lp = <org.nativescript.widgets.CommonLayoutParams>nativeView.getLayoutParams();
|
||||
if (!(lp instanceof org.nativescript.widgets.CommonLayoutParams)) {
|
||||
lp = new org.nativescript.widgets.CommonLayoutParams();
|
||||
}
|
||||
|
||||
return lp;
|
||||
}
|
||||
|
||||
private static setNativeLayoutParamsProperty(view: view.View, params: style.CommonLayoutParams): void {
|
||||
var nativeView: android.view.View = view._nativeView;
|
||||
var lp = DefaultStyler.getNativeLayoutParams(nativeView);
|
||||
|
||||
lp.leftMargin = params.leftMargin * utils.layout.getDisplayDensity();
|
||||
lp.topMargin = params.topMargin * utils.layout.getDisplayDensity();
|
||||
@ -176,15 +181,25 @@ export class DefaultStyler implements definition.stylers.Styler {
|
||||
throw new Error("Invalid verticalAlignment value: " + params.verticalAlignment);
|
||||
}
|
||||
|
||||
lp.gravity = gravity;
|
||||
lp.width = width;
|
||||
lp.height = height;
|
||||
lp.gravity = gravity;
|
||||
|
||||
nativeView.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
private static resetNativeLayoutParamsProperty(view: view.View, nativeValue: any): void {
|
||||
var nativeView: android.view.View = view._nativeView;
|
||||
nativeView.setLayoutParams(new org.nativescript.widgets.CommonLayoutParams());
|
||||
var lp = DefaultStyler.getNativeLayoutParams(nativeView);
|
||||
|
||||
lp.width = -1;
|
||||
lp.height = -1;
|
||||
lp.leftMargin = 0;
|
||||
lp.topMargin = 0;
|
||||
lp.rightMargin = 0;
|
||||
lp.bottomMargin = 0;
|
||||
lp.gravity = android.view.Gravity.FILL_HORIZONTAL | android.view.Gravity.FILL_VERTICAL;
|
||||
nativeView.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
public static registerHandlers() {
|
||||
@ -478,7 +493,7 @@ export class LayoutBaseStyler implements definition.stylers.Styler {
|
||||
public static registerHandlers() {
|
||||
style.registerHandler(style.nativePaddingsProperty, new stylersCommon.StylePropertyChangedHandler(
|
||||
LayoutBaseStyler.setPaddingNativeProperty,
|
||||
LayoutBaseStyler.resetPaddingNativeProperty), "Layout");
|
||||
LayoutBaseStyler.resetPaddingNativeProperty), "LayoutBase");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,6 @@ import dependencyObservable = require("ui/core/dependency-observable");
|
||||
import proxy = require("ui/core/proxy");
|
||||
import formattedString = require("text/formatted-string");
|
||||
import weakEvents = require("ui/core/weak-event-listener");
|
||||
import utils = require("utils/utils");
|
||||
import trace = require("trace");
|
||||
|
||||
var textProperty = new dependencyObservable.Property(
|
||||
"text",
|
||||
@ -115,26 +113,4 @@ export class TextBase extends view.View implements definition.TextBase {
|
||||
}
|
||||
this.setFormattedTextPropertyToNative(data.newValue);
|
||||
}
|
||||
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
if (this.android && this._nativeView) {
|
||||
var measuredWidth = this.getMeasuredWidth();
|
||||
var measuredHeight = this.getMeasuredHeight();
|
||||
|
||||
var measureSpecs = this._getCurrentMeasureSpecs();
|
||||
var widthModeIsNotExact = utils.layout.getMeasureSpecMode(measureSpecs.widthMeasureSpec) !== utils.layout.EXACTLY;
|
||||
var heightModeIsNotExact = utils.layout.getMeasureSpecMode(measureSpecs.heightMeasureSpec) !== utils.layout.EXACTLY;
|
||||
|
||||
var width = right - left;
|
||||
var height = bottom - top;
|
||||
if ((Math.abs(measuredWidth - width) > 1 && widthModeIsNotExact) || (Math.abs(measuredHeight - height) > 1 && heightModeIsNotExact)) {
|
||||
var widthMeasureSpec = utils.layout.makeMeasureSpec(width, utils.layout.EXACTLY);
|
||||
var heightMeasureSpec = utils.layout.makeMeasureSpec(height, utils.layout.EXACTLY);
|
||||
trace.write(this + ", measuredSize: (" + measuredWidth + ", " + measuredHeight + ")" + ", remeasure with: (" + width + ", " + height + ")", trace.categories.Layout);
|
||||
(<android.view.View>this._nativeView).measure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
|
||||
super.onLayout(left, top, right, bottom);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user