From 8eda2ea2cf0fe19e74951b04a7c4617948a4c6e9 Mon Sep 17 00:00:00 2001 From: hshristov Date: Thu, 3 Sep 2015 14:10:26 +0300 Subject: [PATCH 1/4] Fix iOS layout in modal pages. --- CrossPlatformModules.csproj | 18 ++++++++++++++++++ ui/page/page.ios.ts | 24 +++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/CrossPlatformModules.csproj b/CrossPlatformModules.csproj index 8dbbe83f4..3ceaec96c 100644 --- a/CrossPlatformModules.csproj +++ b/CrossPlatformModules.csproj @@ -150,6 +150,15 @@ + + page21.xml + + + page20.xml + + + page19.xml + @@ -157,6 +166,15 @@ + + Designer + + + Designer + + + Designer + diff --git a/ui/page/page.ios.ts b/ui/page/page.ios.ts index bd8e081d0..cf46a2741 100644 --- a/ui/page/page.ios.ts +++ b/ui/page/page.ios.ts @@ -21,7 +21,7 @@ class UIViewControllerImpl extends UIViewController { public didRotateFromInterfaceOrientation(fromInterfaceOrientation: number) { trace.write(this._owner + " didRotateFromInterfaceOrientation(" + fromInterfaceOrientation + ")", trace.categories.ViewHierarchy); - if ((this._owner)._isModal) { + if (this._owner._isModal) { var parentBounds = (this._owner)._UIModalPresentationFormSheet ? (this._owner._nativeView).superview.bounds : UIScreen.mainScreen().bounds; utils.ios._layoutRootView(this._owner, parentBounds); } @@ -35,7 +35,13 @@ class UIViewControllerImpl extends UIViewController { public viewDidLayoutSubviews() { trace.write(this._owner + " viewDidLayoutSubviews, isLoaded = " + this._owner.isLoaded, trace.categories.ViewHierarchy); - this._owner._updateLayout(); + if (this._owner._isModal) { + var parentBounds = (this._owner)._UIModalPresentationFormSheet ? this._owner._nativeView.superview.bounds : UIScreen.mainScreen().bounds; + utils.ios._layoutRootView(this._owner, parentBounds); + } + else { + this._owner._updateLayout(); + } } public viewWillAppear() { @@ -56,12 +62,20 @@ class UIViewControllerImpl extends UIViewController { export class Page extends pageCommon.Page { private _ios: UIViewController; public _enableLoadedEvents: boolean; + public _isModal: boolean = false; constructor(options?: definition.Options) { super(options); this._ios = UIViewControllerImpl.new().initWithOwner(this); } + public requestLayout(): void { + super.requestLayout(); + if (!this.parent && this.ios && this._nativeView) { + this._nativeView.setNeedsLayout(); + } + } + public _onContentChanged(oldView: viewModule.View, newView: viewModule.View) { super._onContentChanged(oldView, newView); this._removeNativeView(oldView); @@ -110,12 +124,12 @@ export class Page extends pageCommon.Page { return this._ios; } - get _nativeView(): any { + get _nativeView(): UIView { return this.ios.view; } protected _showNativeModalView(parent: Page, context: any, closeCallback: Function, fullscreen?: boolean) { - (this)._isModal = true; + this._isModal = true; if (!parent.ios.view.window) { throw new Error("Parent page is not part of the window hierarchy. Close the current modal page before showing another one!"); @@ -143,7 +157,7 @@ export class Page extends pageCommon.Page { protected _hideNativeModalView(parent: Page) { parent._ios.dismissModalViewControllerAnimated(false); - (this)._isModal = false; + this._isModal = false; (this)._UIModalPresentationFormSheet = false; } From f250943d3e9453e70d0f85086f0e14f8a27ed622 Mon Sep 17 00:00:00 2001 From: hshristov Date: Fri, 4 Sep 2015 11:01:58 +0300 Subject: [PATCH 2/4] Add commented unittest - will need to check later why android tests fails after this new one. --- CrossPlatformModules.csproj | 4 ++- CrossPlatformModules.sln | 4 +-- apps/tests/TKUnit.ts | 6 ++++ apps/tests/ui/page/page-tests-common.ts | 39 ++++++++++++++++++++++++- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/CrossPlatformModules.csproj b/CrossPlatformModules.csproj index 3ceaec96c..0cd8ef78a 100644 --- a/CrossPlatformModules.csproj +++ b/CrossPlatformModules.csproj @@ -151,6 +151,7 @@ + page21.xml @@ -166,7 +167,7 @@ - + Designer @@ -1982,6 +1983,7 @@ + \ No newline at end of file diff --git a/CrossPlatformModules.sln b/CrossPlatformModules.sln index 065ae6bab..646061d34 100644 --- a/CrossPlatformModules.sln +++ b/CrossPlatformModules.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.22310.1 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30501.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrossPlatformModules", "CrossPlatformModules.csproj", "{2313F1BF-1F2D-4F11-806A-87927FA6A7C0}" EndProject diff --git a/apps/tests/TKUnit.ts b/apps/tests/TKUnit.ts index 2e11ce19f..119986f1e 100644 --- a/apps/tests/TKUnit.ts +++ b/apps/tests/TKUnit.ts @@ -156,6 +156,12 @@ export function assert(test: any, message?: string) { } }; +export function assertTrue(test: boolean, message?: string) { + if (test !== true) { + throw new Error(message); + } +}; + export function assertNotEqual(actual: any, expected: any, message?: string) { var equals = false; diff --git a/apps/tests/ui/page/page-tests-common.ts b/apps/tests/ui/page/page-tests-common.ts index 30ff43f16..9bd3e3e9d 100644 --- a/apps/tests/ui/page/page-tests-common.ts +++ b/apps/tests/ui/page/page-tests-common.ts @@ -366,4 +366,41 @@ export function test_page_backgroundColor_is_white() { var page = views[0]; TKUnit.assertEqual(page.style.backgroundColor.hex.toLowerCase(), "#ffffff", "page background-color"); }); -} \ No newline at end of file +} + +//export function test_ModalPage_Layout_is_Correct() { +// var testPage: PageModule.Page; +// var label: LabelModule.Label; +// var pageFactory = function () { +// testPage = new PageModule.Page(); +// label = new LabelModule.Label(); +// label.text = "Will Show modal page"; +// testPage.content = label; +// return testPage; +// }; + +// helper.navigate(pageFactory); +// var basePath = "ui/page/"; +// testPage.showModal(basePath + "page21", testPage, () => { }, false); + +// // TODO: Remove this once navigate and showModal returns Promise. +// TKUnit.wait(0.350); +// var childPage = (testPage).childPage; +// var closeCallback: Function = (testPage).close; + +// try { +// var layout = childPage.content; +// var repeater = layout.getChildAt(1); +// TKUnit.assertTrue(repeater.isLayoutValid, "layout should be valid."); +// var bounds = repeater._getCurrentLayoutBounds(); +// var height = bounds.bottom - bounds.top; +// TKUnit.assertTrue(height > 0, "Layout should be >0."); + +// closeCallback(); +// TKUnit.wait(0.150); +// } +// finally { +// helper.goBack +// helper.goBack(); +// } +//} \ No newline at end of file From 510a10afe26d803d360405e71e92aea4af545e94 Mon Sep 17 00:00:00 2001 From: hshristov Date: Fri, 4 Sep 2015 11:06:37 +0300 Subject: [PATCH 3/4] add missing files --- apps/tests/pages/page19.ts | 8 ++++++++ apps/tests/pages/page19.xml | 3 +++ apps/tests/pages/page20.ts | 11 +++++++++++ apps/tests/pages/page20.xml | 5 +++++ apps/tests/ui/page/page21.ts | 10 ++++++++++ apps/tests/ui/page/page21.xml | 6 ++++++ 6 files changed, 43 insertions(+) create mode 100644 apps/tests/pages/page19.ts create mode 100644 apps/tests/pages/page19.xml create mode 100644 apps/tests/pages/page20.ts create mode 100644 apps/tests/pages/page20.xml create mode 100644 apps/tests/ui/page/page21.ts create mode 100644 apps/tests/ui/page/page21.xml diff --git a/apps/tests/pages/page19.ts b/apps/tests/pages/page19.ts new file mode 100644 index 000000000..8499afb35 --- /dev/null +++ b/apps/tests/pages/page19.ts @@ -0,0 +1,8 @@ +import observable = require("data/observable"); +import trace = require("trace"); +trace.addCategories(trace.categories.Layout); +trace.enable(); + +export function onLoaded(args: observable.EventData) { + (args.object).bindingContext = [0, 1]; +} \ No newline at end of file diff --git a/apps/tests/pages/page19.xml b/apps/tests/pages/page19.xml new file mode 100644 index 000000000..b97ad13a0 --- /dev/null +++ b/apps/tests/pages/page19.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/apps/tests/pages/page20.ts b/apps/tests/pages/page20.ts new file mode 100644 index 000000000..96700ff74 --- /dev/null +++ b/apps/tests/pages/page20.ts @@ -0,0 +1,11 @@ +import observable = require("data/observable"); +import trace = require("trace"); +import {Button} from "ui/button"; +import {Page} from "ui/page"; +trace.addCategories(trace.categories.Layout); +trace.enable(); + +export function onTap(args: observable.EventData) { + var btn =