From d80bc5fc811313b9d085a3fb0eb6016bf021d54d Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Mon, 21 Mar 2016 13:05:17 +0200 Subject: [PATCH] Eliminate rounding errors --- apps/tests/ui/view/view-tests-common.ts | 2 +- ui/core/view-common.ts | 11 +---------- ui/core/view.android.ts | 17 +++++++++++++++++ ui/core/view.ios.ts | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/apps/tests/ui/view/view-tests-common.ts b/apps/tests/ui/view/view-tests-common.ts index ddf475b99..5a70d3b9b 100644 --- a/apps/tests/ui/view/view-tests-common.ts +++ b/apps/tests/ui/view/view-tests-common.ts @@ -723,7 +723,7 @@ export var test_getLocationOnScreen_IsUndefinedWhenNotInTheVisualTree = function TKUnit.assertNull(label.getLocationOnScreen()); } -var delta = 0.5; +var delta = 0.1; export var test_getLocationRelativeToOtherView = function () { var a1 = new absoluteLayoutModule.AbsoluteLayout(); a1.width = 200; diff --git a/ui/core/view-common.ts b/ui/core/view-common.ts index 9d15cc10b..3d9ed55af 100644 --- a/ui/core/view-common.ts +++ b/ui/core/view-common.ts @@ -1149,16 +1149,7 @@ export class View extends ProxyObject implements definition.View { } public getLocationRelativeTo(otherView: definition.View): definition.Point { - var my = this.getLocationInWindow(); - var other = otherView.getLocationInWindow(); - if (!my || !other) { - return undefined; - } - - return { - x: my.x - other.x, - y: my.y - other.y - } + return undefined; } public getActualSize(): definition.Size { diff --git a/ui/core/view.android.ts b/ui/core/view.android.ts index 93b13caea..b8eb91672 100644 --- a/ui/core/view.android.ts +++ b/ui/core/view.android.ts @@ -389,6 +389,23 @@ export class View extends viewCommon.View { } } + public getLocationRelativeTo(otherView: viewDefinition.View): viewDefinition.Point { + if (!this._nativeView || !this._nativeView.getWindowToken() || + !otherView._nativeView || !otherView._nativeView.getWindowToken() || + this._nativeView.getWindowToken() !== otherView._nativeView.getWindowToken()) { + return undefined; + } + + var myArray = (Array).create("int", 2); + this._nativeView.getLocationOnScreen(myArray); + var otherArray = (Array).create("int", 2); + otherView._nativeView.getLocationOnScreen(otherArray); + return { + x: utils.layout.toDeviceIndependentPixels(myArray[0] - otherArray[0]), + y: utils.layout.toDeviceIndependentPixels(myArray[1] - otherArray[1]), + } + } + public static resolveSizeAndState(size: number, specSize: number, specMode: number, childMeasuredState: number): number { var result = size; switch (specMode) { diff --git a/ui/core/view.ios.ts b/ui/core/view.ios.ts index 6c411913e..644862cf1 100644 --- a/ui/core/view.ios.ts +++ b/ui/core/view.ios.ts @@ -278,6 +278,21 @@ export class View extends viewCommon.View { } } + public getLocationRelativeTo(otherView: viewDefinition.View): viewDefinition.Point { + if (!this._nativeView || !this._nativeView.window || + !otherView._nativeView || !otherView._nativeView.window || + this._nativeView.window !== otherView._nativeView.window) { + return undefined; + } + + var myPointInWindow = this._nativeView.convertPointToView(this._nativeView.bounds.origin, null); + var otherPointInWindow = otherView._nativeView.convertPointToView(otherView._nativeView.bounds.origin, null); + return { + x: utils.layout.toDeviceIndependentPixels(myPointInWindow.x - otherPointInWindow.x), + y: utils.layout.toDeviceIndependentPixels(myPointInWindow.y - otherPointInWindow.y), + } + } + private _onSizeChanged() { this.style._sizeChanged(); }