From 6f93030b5d13f8d55cacfbf2ad3c1db63a4f6492 Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Wed, 10 Feb 2016 16:17:33 +0200 Subject: [PATCH] grid-layout distribute remaining space over stars but preserve their aspect. ts lint errors fixed android scroll-view tests fixed for different device density added grid-layout test --- apps/tests/layouts/grid-layout-tests.ts | 33 ++-- .../tests/ui/scroll-view/scroll-view-tests.ts | 161 ++++-------------- ui/layouts/grid-layout/grid-layout.ios.ts | 4 +- 3 files changed, 53 insertions(+), 145 deletions(-) diff --git a/apps/tests/layouts/grid-layout-tests.ts b/apps/tests/layouts/grid-layout-tests.ts index 9a263107b..7b2bc7995 100644 --- a/apps/tests/layouts/grid-layout-tests.ts +++ b/apps/tests/layouts/grid-layout-tests.ts @@ -689,25 +689,36 @@ export class GridLayoutTest extends testModule.UITest { } public test_columns_widths() { - this.testView.width = layoutHelper.dp(300); - this.testView.height = layoutHelper.dp(500); + this.testView.width = layoutHelper.dp(400); + this.testView.height = layoutHelper.dp(600); - this.testView.addColumn(new ItemSpec(1, GridUnitType.star)); - this.testView.addColumn(new ItemSpec(layoutHelper.dp(100), GridUnitType.pixel)); - this.testView.addColumn(new ItemSpec(2, GridUnitType.star)); - - this.testView.addRow(new ItemSpec(1, GridUnitType.star)); - this.testView.addRow(new ItemSpec(layoutHelper.dp(100), GridUnitType.pixel)); - this.testView.addRow(new ItemSpec(2, GridUnitType.star)); + let grid = new GridLayout(); + this.testView.addChild(grid); + grid.horizontalAlignment = enums.HorizontalAlignment.left; + grid.verticalAlignment = enums.VerticalAlignment.top; + + grid.addColumn(new ItemSpec(1, GridUnitType.star)); + grid.addColumn(new ItemSpec(layoutHelper.dp(100), GridUnitType.pixel)); + grid.addColumn(new ItemSpec(2, GridUnitType.star)); + + grid.addRow(new ItemSpec(1, GridUnitType.star)); + grid.addRow(new ItemSpec(layoutHelper.dp(100), GridUnitType.pixel)); + grid.addRow(new ItemSpec(2, GridUnitType.star)); + let btn = new Button(); + btn.width = layoutHelper.dp(300); + btn.height = layoutHelper.dp(500); + grid.addChild(btn); + GridLayout.setColumnSpan(btn, 3); + GridLayout.setRowSpan(btn, 3); this.waitUntilTestElementLayoutIsValid(); - var cols = this.testView.getColumns(); + var cols = grid.getColumns(); TKUnit.assertAreClose(cols[0].actualLength, layoutHelper.dp(67), DELTA, "Column[0] actual length should be 67"); TKUnit.assertAreClose(cols[1].actualLength, layoutHelper.dp(100), DELTA, "Column[1] actual length should be 100"); TKUnit.assertAreClose(cols[2].actualLength, layoutHelper.dp(133), DELTA, "Column[2] actual length should be 133"); - var rows = this.testView.getRows(); + var rows = grid.getRows(); TKUnit.assertAreClose(rows[0].actualLength, layoutHelper.dp(133), DELTA, "Row[0] actual length should be 133"); TKUnit.assertAreClose(rows[1].actualLength, layoutHelper.dp(100), DELTA, "Row[1] actual length should be 100"); TKUnit.assertAreClose(rows[2].actualLength, layoutHelper.dp(267), DELTA, "Row[2] actual length should be 267"); diff --git a/apps/tests/ui/scroll-view/scroll-view-tests.ts b/apps/tests/ui/scroll-view/scroll-view-tests.ts index 8ff74fbfd..3eba7778e 100644 --- a/apps/tests/ui/scroll-view/scroll-view-tests.ts +++ b/apps/tests/ui/scroll-view/scroll-view-tests.ts @@ -27,8 +27,21 @@ import scrollViewModule = require("ui/scroll-view"); //  class ScrollLayoutTest extends testModule.UITest { + public create(): scrollViewModule.ScrollView { - return new scrollViewModule.ScrollView(); + let scrollView = new scrollViewModule.ScrollView(); + scrollView.orientation = enums.Orientation.vertical; + + scrollView.width = layoutHelper.dp(200); + scrollView.height = layoutHelper.dp(300); + + let btn = new button.Button(); + btn.text = "test"; + btn.width = layoutHelper.dp(500); + btn.height = layoutHelper.dp(500); + scrollView.content = btn; + + return scrollView; } public test_snippets() { @@ -69,78 +82,38 @@ class ScrollLayoutTest extends testModule.UITest { } public test_scrollabeHeight_vertical_orientation_when_content_is_small() { - this.testView.orientation = enums.Orientation.vertical; - this.testView.width = 200; - this.testView.height = 300; - - let btn = new button.Button(); - btn.text = "test"; - btn.height = 100; - this.testView.content = btn; - + this.testView.content.height = 100; this.waitUntilTestElementLayoutIsValid(); + TKUnit.assertEqual(this.testView.scrollableHeight, 0, "this.testView.scrollableHeight"); TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth"); } public test_scrollabeHeight_vertical_orientation_when_content_is_big() { - this.testView.orientation = enums.Orientation.vertical; - - this.testView.width = 200; - this.testView.height = 300; - - let btn = new button.Button(); - btn.text = "test"; - btn.height = 500; - this.testView.content = btn; - this.waitUntilTestElementLayoutIsValid(); - TKUnit.assertAreClose(this.testView.scrollableHeight, 200, 0.4, "this.testView.scrollableHeight"); - TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth"); + TKUnit.assertAreClose(layoutHelper.dip(this.testView.scrollableHeight), 200, 0.4, "this.testView.scrollableHeight"); + TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth"); } public test_scrollabeWidth_horizontal_orientation_when_content_is_small() { - this.testView.orientation = enums.Orientation.vertical; - this.testView.width = 200; - this.testView.height = 300; - - let btn = new button.Button(); - btn.text = "test"; - btn.width = 100; - this.testView.content = btn; - + this.testView.orientation = enums.Orientation.horizontal; + this.testView.content.width = 100; this.waitUntilTestElementLayoutIsValid(); + TKUnit.assertEqual(this.testView.scrollableHeight, 0, "this.testView.scrollableHeight"); TKUnit.assertEqual(this.testView.scrollableWidth, 0, "this.testView.scrollableWidth"); } public test_scrollabeWidth_horizontal_orientation_when_content_is_big() { this.testView.orientation = enums.Orientation.horizontal; - - this.testView.width = 200; - this.testView.height = 300; - - let btn = new button.Button(); - btn.text = "test"; - btn.width = 500; - this.testView.content = btn; - this.waitUntilTestElementLayoutIsValid(); + TKUnit.assertEqual(this.testView.scrollableHeight, 0, "this.testView.scrollableHeight"); - TKUnit.assertAreClose(this.testView.scrollableWidth, 300, 0.4, "this.testView.scrollableWidth"); + TKUnit.assertAreClose(layoutHelper.dip(this.testView.scrollableWidth), 300, 0.4, "this.testView.scrollableWidth"); } public test_scrollToVerticalOffset_no_animation() { - this.testView.orientation = enums.Orientation.vertical; - - this.testView.width = 200; - this.testView.height = 300; - - let btn = new button.Button(); - btn.text = "test"; - btn.height = 500; - this.testView.content = btn; this.waitUntilTestElementLayoutIsValid(); TKUnit.assertEqual(this.testView.verticalOffset, 0, "this.testView.verticalOffset"); @@ -149,15 +122,6 @@ class ScrollLayoutTest extends testModule.UITest { } public test_scrollToVerticalOffset_with_animation() { - this.testView.orientation = enums.Orientation.vertical; - - this.testView.width = 200; - this.testView.height = 300; - - let btn = new button.Button(); - btn.text = "test"; - btn.height = 500; - this.testView.content = btn; this.waitUntilTestElementLayoutIsValid(); TKUnit.assertEqual(this.testView.verticalOffset, 0, "this.testView.verticalOffset"); @@ -174,14 +138,6 @@ class ScrollLayoutTest extends testModule.UITest { public test_scrollToHorizontalOffset_no_animation() { this.testView.orientation = enums.Orientation.horizontal; - - this.testView.width = 200; - this.testView.height = 300; - - let btn = new button.Button(); - btn.text = "test"; - btn.width = 500; - this.testView.content = btn; this.waitUntilTestElementLayoutIsValid(); TKUnit.assertEqual(this.testView.horizontalOffset, 0, "this.testView.horizontalOffset"); @@ -191,14 +147,6 @@ class ScrollLayoutTest extends testModule.UITest { public test_scrollToHorizontalOffset_with_animation() { this.testView.orientation = enums.Orientation.horizontal; - - this.testView.width = 200; - this.testView.height = 300; - - let btn = new button.Button(); - btn.text = "test"; - btn.width = 500; - this.testView.content = btn; this.waitUntilTestElementLayoutIsValid(); TKUnit.assertEqual(this.testView.horizontalOffset, 0, "this.testView.horizontalOffset"); @@ -214,19 +162,9 @@ class ScrollLayoutTest extends testModule.UITest { } public test_scrollView_persistsState_vertical() { - this.testView.orientation = enums.Orientation.vertical; - - this.testView.width = 200; - this.testView.height = 300; - - var btn = new button.Button(); - btn.text = "test"; - btn.height = 500; - this.testView.content = btn; this.waitUntilTestElementLayoutIsValid(); this.testView.scrollToVerticalOffset(layoutHelper.dp(100), false); - TKUnit.assertAreClose(layoutHelper.dip(this.testView.verticalOffset), 100, 0.1, "this.testView.verticalOffset before navigation"); helper.do_PageTest_WithButton((t) => { @@ -242,14 +180,6 @@ class ScrollLayoutTest extends testModule.UITest { public test_scrollView_persistsState_horizontal() { this.testView.orientation = enums.Orientation.horizontal; - - this.testView.width = 200; - this.testView.height = 300; - - var btn = new button.Button(); - btn.text = "test"; - btn.width = 500; - this.testView.content = btn; this.waitUntilTestElementLayoutIsValid(); this.testView.scrollToHorizontalOffset(layoutHelper.dp(100), false); @@ -268,23 +198,14 @@ class ScrollLayoutTest extends testModule.UITest { } public test_scrollView_vertical_raised_scroll_event() { - this.testView.orientation = enums.Orientation.vertical; - var scrollY: number; this.testView.on(scrollViewModule.ScrollView.scrollEvent, (args: scrollViewModule.ScrollEventData) => { scrollY = args.scrollY; }); - this.testView.width = 200; - this.testView.height = 300; - - var btn = new button.Button(); - btn.text = "test"; - btn.height = 500; - this.testView.content = btn; this.waitUntilTestElementLayoutIsValid(); - this.testView.scrollToVerticalOffset(100, false); + this.testView.scrollToVerticalOffset(layoutHelper.dp(100), false); TKUnit.waitUntilReady(function () { return scrollY > 0; }); TKUnit.assertEqual(scrollY, this.testView.verticalOffset); } @@ -297,23 +218,14 @@ class ScrollLayoutTest extends testModule.UITest { scrollX = args.scrollX; }); - this.testView.width = 200; - this.testView.height = 300; - - var btn = new button.Button(); - btn.text = "test"; - btn.width = 500; - this.testView.content = btn; this.waitUntilTestElementLayoutIsValid(); - this.testView.scrollToHorizontalOffset(100, false); + this.testView.scrollToHorizontalOffset(layoutHelper.dp(100), false); TKUnit.waitUntilReady(function () { return scrollX > 0; }); TKUnit.assertEqual(scrollX, this.testView.horizontalOffset); } public test_scrollView_vertical_raised_scroll_event_after_loaded() { - this.testView.orientation = enums.Orientation.vertical; - this.waitUntilTestElementIsLoaded(); var scrollY: number; @@ -321,23 +233,14 @@ class ScrollLayoutTest extends testModule.UITest { scrollY = args.scrollY; }); - this.testView.width = 200; - this.testView.height = 300; - - var btn = new button.Button(); - btn.text = "test"; - btn.height = 500; - this.testView.content = btn; - this.waitUntilTestElementLayoutIsValid(); - - this.testView.scrollToVerticalOffset(100, false); + this.testView.scrollToVerticalOffset(layoutHelper.dp(100), false); TKUnit.waitUntilReady(function () { return scrollY > 0; }); TKUnit.assertEqual(scrollY, this.testView.verticalOffset); + TKUnit.assertEqual(scrollY, layoutHelper.dp(100)); } public test_scrollView_horizontal_raised_scroll_event_after_loaded() { this.testView.orientation = enums.Orientation.horizontal; - this.waitUntilTestElementIsLoaded(); var scrollX: number; @@ -345,18 +248,12 @@ class ScrollLayoutTest extends testModule.UITest { scrollX = args.scrollX; }); - this.testView.width = 200; - this.testView.height = 300; - - var btn = new button.Button(); - btn.text = "test"; - btn.width = 500; - this.testView.content = btn; this.waitUntilTestElementLayoutIsValid(); - this.testView.scrollToHorizontalOffset(100, false); + this.testView.scrollToHorizontalOffset(layoutHelper.dp(100), false); TKUnit.waitUntilReady(function () { return scrollX > 0; }); TKUnit.assertEqual(scrollX, this.testView.horizontalOffset); + TKUnit.assertEqual(scrollX, layoutHelper.dp(100)); } } diff --git a/ui/layouts/grid-layout/grid-layout.ios.ts b/ui/layouts/grid-layout/grid-layout.ios.ts index c10354487..a8d46defc 100644 --- a/ui/layouts/grid-layout/grid-layout.ios.ts +++ b/ui/layouts/grid-layout/grid-layout.ios.ts @@ -749,13 +749,13 @@ class MeasureHelper { // If we are not stretched and minColumnStarValue is less than maxColumnStarValue // we need to reduce the width of star columns. - if (!this.stretchedHorizontally && this.minColumnStarValue != -1 && this.minColumnStarValue < this.maxColumnStarValue) { + if (!this.stretchedHorizontally && this.minColumnStarValue !== -1 && this.minColumnStarValue < this.maxColumnStarValue) { MeasureHelper.updateStarLength(this.columns, this.minColumnStarValue); } // If we are not stretched and minRowStarValue is less than maxRowStarValue // we need to reduce the height of star maxRowStarValue. - if (!this.stretchedVertically && this.minRowStarValue != -1 && this.minRowStarValue < this.maxRowStarValue) { + if (!this.stretchedVertically && this.minRowStarValue !== -1 && this.minRowStarValue < this.maxRowStarValue) { MeasureHelper.updateStarLength(this.rows, this.minRowStarValue); }