Fix dp vs dip conversions in iOS for errors of tests

This commit is contained in:
Panayot Cankov
2017-03-07 17:28:55 +02:00
parent 9f1ebc11ca
commit 6d6564af16
7 changed files with 26 additions and 19 deletions

View File

@ -139,8 +139,10 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
if (label.ios) {
this.waitUntilTestElementLayoutIsValid();
const expectedValue = 3;
let expectedValue = NSString.stringWithString("i").sizeWithAttributes(<any>{
[NSFontAttributeName]: UIFont.systemFontOfSize(9)
}).width;
expectedValue = Math.ceil(utils.layout.toDevicePixels(expectedValue));
const measuredWidth = label.getMeasuredWidth();
TKUnit.assertEqual(measuredWidth, expectedValue, "measuredWidth should not be rounded down.");
}

View File

@ -5,6 +5,7 @@ import * as color from "color";
import * as helper from "../helper";
import * as TKUnit from "../../TKUnit";
import * as button from "ui/button";
import * as utils from "utils/utils";
global.moduleMerge(commonTests, exports);
@ -21,7 +22,7 @@ class MyGrid extends grid.GridLayout {
}
export function getUniformNativeBorderWidth(v: view.View): number {
return (<UIView>v.ios).layer.borderWidth;
return utils.layout.toDevicePixels((<UIView>v.ios).layer.borderWidth);
}
export function checkUniformNativeBorderColor(v: view.View): boolean {

View File

@ -189,8 +189,8 @@ export class View extends ViewCommon {
let pointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
return {
x: layout.toDeviceIndependentPixels(pointInWindow.x),
y: layout.toDeviceIndependentPixels(pointInWindow.y),
x: pointInWindow.x,
y: pointInWindow.y
};
}
@ -202,8 +202,8 @@ export class View extends ViewCommon {
let pointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
let pointOnScreen = this.nativeView.window.convertPointToWindow(pointInWindow, null);
return {
x: layout.toDeviceIndependentPixels(pointOnScreen.x),
y: layout.toDeviceIndependentPixels(pointOnScreen.y),
x: pointOnScreen.x,
y: pointOnScreen.y
};
}
@ -217,8 +217,8 @@ export class View extends ViewCommon {
let myPointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
let otherPointInWindow = otherView.nativeView.convertPointToView(otherView.nativeView.bounds.origin, null);
return {
x: layout.toDeviceIndependentPixels(myPointInWindow.x - otherPointInWindow.x),
y: layout.toDeviceIndependentPixels(myPointInWindow.y - otherPointInWindow.y),
x: myPointInWindow.x - otherPointInWindow.x,
y: myPointInWindow.y - otherPointInWindow.y
};
}

View File

@ -6,6 +6,7 @@ import { Page } from "ui/page";
import { FrameBase, View, application, layout, traceEnabled, traceWrite, traceCategories, isCategorySet } from "./frame-common";
import { _createIOSAnimatedTransitioning } from "ui/transition";
import * as uiUtils from "ui/utils";
import * as utils from "utils/utils";
export * from "./frame-common";

View File

@ -174,7 +174,7 @@ export class GridLayout extends GridLayoutBase {
actualLength = offset - roundedOffset;
roundedLength = Math.round(actualLength);
columnGroup.rowOrColumn._actualLength = roundedLength;
columnGroup.rowOrColumn._actualLength = layout.toDeviceIndependentPixels(roundedLength);
roundedOffset += roundedLength;
this.columnOffsets.push(roundedOffset);
@ -191,7 +191,7 @@ export class GridLayout extends GridLayoutBase {
actualLength = offset - roundedOffset;
roundedLength = Math.round(actualLength);
rowGroup.rowOrColumn._actualLength = roundedLength;
rowGroup.rowOrColumn._actualLength = layout.toDeviceIndependentPixels(roundedLength);
roundedOffset += roundedLength;
this.rowOffsets.push(roundedOffset);
@ -417,7 +417,7 @@ class MeasureHelper {
measureSpec.starColumnsCount += columnGroup.rowOrColumn.value;
}
else if (columnGroup.getIsAbsolute()) {
measureSpec.pixelWidth += columnGroup.rowOrColumn.value;
measureSpec.pixelWidth += layout.toDevicePixels(columnGroup.rowOrColumn.value);
}
}
@ -442,7 +442,7 @@ class MeasureHelper {
measureSpec.starRowsCount += rowGroup.rowOrColumn.value;
}
else if (rowGroup.getIsAbsolute()) {
measureSpec.pixelHeight += rowGroup.rowOrColumn.value;
measureSpec.pixelHeight += layout.toDevicePixels(rowGroup.rowOrColumn.value);
}
}

View File

@ -141,7 +141,7 @@ class UITableViewDelegateImpl extends NSObject implements UITableViewDelegate {
height = owner._prepareCell(cell, indexPath);
}
return height;
return layout.toDeviceIndependentPixels(height);
}
}

View File

@ -18,8 +18,8 @@ class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate
owner.notify(<ScrollEventData>{
object: owner,
eventName: ScrollViewBase.scrollEvent,
scrollX: owner.horizontalOffset / layout.getDisplayDensity(),
scrollY: owner.verticalOffset / layout.getDisplayDensity()
scrollX: owner.horizontalOffset,
scrollY: owner.verticalOffset
});
}
}
@ -60,7 +60,7 @@ export class ScrollView extends ScrollViewBase {
return 0;
}
return Math.max(0, this.nativeView.contentSize.width - this.nativeView.bounds.size.width) / layout.getDisplayDensity();
return Math.max(0, this.nativeView.contentSize.width - this.nativeView.bounds.size.width);
}
get scrollableHeight(): number {
@ -68,7 +68,7 @@ export class ScrollView extends ScrollViewBase {
return 0;
}
return Math.max(0, this.nativeView.contentSize.height - this.nativeView.bounds.size.height) / layout.getDisplayDensity();
return Math.max(0, this.nativeView.contentSize.height - this.nativeView.bounds.size.height);
}
get ios(): UIView {
@ -116,7 +116,10 @@ export class ScrollView extends ScrollViewBase {
childSize = View.measureChild(this, child, layout.makeMeasureSpec(0, layout.UNSPECIFIED), heightMeasureSpec);
}
this.nativeView.contentSize = CGSizeMake(childSize.measuredWidth, childSize.measuredHeight);
let w = layout.toDeviceIndependentPixels(childSize.measuredWidth);
let h = layout.toDeviceIndependentPixels(childSize.measuredHeight);
this.nativeView.contentSize = CGSizeMake(w, h);
this._contentMeasuredWidth = Math.max(childSize.measuredWidth, this.effectiveMinWidth * density);
this._contentMeasuredHeight = Math.max(childSize.measuredHeight, this.effectiveMinHeight * density);
}