diff --git a/tests/app/ui/label/label-tests.ts b/tests/app/ui/label/label-tests.ts index b5a608dc7..ef9c6db8f 100644 --- a/tests/app/ui/label/label-tests.ts +++ b/tests/app/ui/label/label-tests.ts @@ -139,8 +139,10 @@ export class LabelTest extends testModule.UITest { if (label.ios) { this.waitUntilTestElementLayoutIsValid(); - - const expectedValue = 3; + let expectedValue = NSString.stringWithString("i").sizeWithAttributes({ + [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."); } diff --git a/tests/app/ui/view/view-tests.ios.ts b/tests/app/ui/view/view-tests.ios.ts index 7828bd018..3c5f86dfd 100644 --- a/tests/app/ui/view/view-tests.ios.ts +++ b/tests/app/ui/view/view-tests.ios.ts @@ -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 (v.ios).layer.borderWidth; + return utils.layout.toDevicePixels((v.ios).layer.borderWidth); } export function checkUniformNativeBorderColor(v: view.View): boolean { diff --git a/tns-core-modules/ui/core/view/view.ios.ts b/tns-core-modules/ui/core/view/view.ios.ts index 4ecfd03bc..2a608a620 100644 --- a/tns-core-modules/ui/core/view/view.ios.ts +++ b/tns-core-modules/ui/core/view/view.ios.ts @@ -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 }; } diff --git a/tns-core-modules/ui/frame/frame.ios.ts b/tns-core-modules/ui/frame/frame.ios.ts index 3dfa636e2..324db1933 100644 --- a/tns-core-modules/ui/frame/frame.ios.ts +++ b/tns-core-modules/ui/frame/frame.ios.ts @@ -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"; diff --git a/tns-core-modules/ui/layouts/grid-layout/grid-layout.ios.ts b/tns-core-modules/ui/layouts/grid-layout/grid-layout.ios.ts index fd2a8e088..a7e0907cd 100644 --- a/tns-core-modules/ui/layouts/grid-layout/grid-layout.ios.ts +++ b/tns-core-modules/ui/layouts/grid-layout/grid-layout.ios.ts @@ -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); } } diff --git a/tns-core-modules/ui/list-view/list-view.ios.ts b/tns-core-modules/ui/list-view/list-view.ios.ts index 60665854a..d19c36993 100644 --- a/tns-core-modules/ui/list-view/list-view.ios.ts +++ b/tns-core-modules/ui/list-view/list-view.ios.ts @@ -141,7 +141,7 @@ class UITableViewDelegateImpl extends NSObject implements UITableViewDelegate { height = owner._prepareCell(cell, indexPath); } - return height; + return layout.toDeviceIndependentPixels(height); } } diff --git a/tns-core-modules/ui/scroll-view/scroll-view.ios.ts b/tns-core-modules/ui/scroll-view/scroll-view.ios.ts index 1065bfaa0..e769991d1 100644 --- a/tns-core-modules/ui/scroll-view/scroll-view.ios.ts +++ b/tns-core-modules/ui/scroll-view/scroll-view.ios.ts @@ -18,8 +18,8 @@ class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate owner.notify({ 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); }