mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Eliminate rounding errors
This commit is contained in:
@ -723,7 +723,7 @@ export var test_getLocationOnScreen_IsUndefinedWhenNotInTheVisualTree = function
|
|||||||
TKUnit.assertNull(label.getLocationOnScreen());
|
TKUnit.assertNull(label.getLocationOnScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
var delta = 0.5;
|
var delta = 0.1;
|
||||||
export var test_getLocationRelativeToOtherView = function () {
|
export var test_getLocationRelativeToOtherView = function () {
|
||||||
var a1 = new absoluteLayoutModule.AbsoluteLayout();
|
var a1 = new absoluteLayoutModule.AbsoluteLayout();
|
||||||
a1.width = 200;
|
a1.width = 200;
|
||||||
|
@ -1149,16 +1149,7 @@ export class View extends ProxyObject implements definition.View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getLocationRelativeTo(otherView: definition.View): definition.Point {
|
public getLocationRelativeTo(otherView: definition.View): definition.Point {
|
||||||
var my = this.getLocationInWindow();
|
return undefined;
|
||||||
var other = otherView.getLocationInWindow();
|
|
||||||
if (!my || !other) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
x: my.x - other.x,
|
|
||||||
y: my.y - other.y
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getActualSize(): definition.Size {
|
public getActualSize(): definition.Size {
|
||||||
|
@ -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 = (<any>Array).create("int", 2);
|
||||||
|
this._nativeView.getLocationOnScreen(myArray);
|
||||||
|
var otherArray = (<any>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 {
|
public static resolveSizeAndState(size: number, specSize: number, specMode: number, childMeasuredState: number): number {
|
||||||
var result = size;
|
var result = size;
|
||||||
switch (specMode) {
|
switch (specMode) {
|
||||||
|
@ -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() {
|
private _onSizeChanged() {
|
||||||
this.style._sizeChanged();
|
this.style._sizeChanged();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user