mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
Fix dp vs dip conversions in iOS for errors of tests
This commit is contained in:
@ -139,8 +139,10 @@ export class LabelTest extends testModule.UITest<LabelModule.Label> {
|
|||||||
|
|
||||||
if (label.ios) {
|
if (label.ios) {
|
||||||
this.waitUntilTestElementLayoutIsValid();
|
this.waitUntilTestElementLayoutIsValid();
|
||||||
|
let expectedValue = NSString.stringWithString("i").sizeWithAttributes(<any>{
|
||||||
const expectedValue = 3;
|
[NSFontAttributeName]: UIFont.systemFontOfSize(9)
|
||||||
|
}).width;
|
||||||
|
expectedValue = Math.ceil(utils.layout.toDevicePixels(expectedValue));
|
||||||
const measuredWidth = label.getMeasuredWidth();
|
const measuredWidth = label.getMeasuredWidth();
|
||||||
TKUnit.assertEqual(measuredWidth, expectedValue, "measuredWidth should not be rounded down.");
|
TKUnit.assertEqual(measuredWidth, expectedValue, "measuredWidth should not be rounded down.");
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import * as color from "color";
|
|||||||
import * as helper from "../helper";
|
import * as helper from "../helper";
|
||||||
import * as TKUnit from "../../TKUnit";
|
import * as TKUnit from "../../TKUnit";
|
||||||
import * as button from "ui/button";
|
import * as button from "ui/button";
|
||||||
|
import * as utils from "utils/utils";
|
||||||
|
|
||||||
global.moduleMerge(commonTests, exports);
|
global.moduleMerge(commonTests, exports);
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ class MyGrid extends grid.GridLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getUniformNativeBorderWidth(v: view.View): number {
|
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 {
|
export function checkUniformNativeBorderColor(v: view.View): boolean {
|
||||||
|
@ -189,8 +189,8 @@ export class View extends ViewCommon {
|
|||||||
|
|
||||||
let pointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
|
let pointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
|
||||||
return {
|
return {
|
||||||
x: layout.toDeviceIndependentPixels(pointInWindow.x),
|
x: pointInWindow.x,
|
||||||
y: layout.toDeviceIndependentPixels(pointInWindow.y),
|
y: pointInWindow.y
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,8 +202,8 @@ export class View extends ViewCommon {
|
|||||||
let pointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
|
let pointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
|
||||||
let pointOnScreen = this.nativeView.window.convertPointToWindow(pointInWindow, null);
|
let pointOnScreen = this.nativeView.window.convertPointToWindow(pointInWindow, null);
|
||||||
return {
|
return {
|
||||||
x: layout.toDeviceIndependentPixels(pointOnScreen.x),
|
x: pointOnScreen.x,
|
||||||
y: layout.toDeviceIndependentPixels(pointOnScreen.y),
|
y: pointOnScreen.y
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,8 +217,8 @@ export class View extends ViewCommon {
|
|||||||
let myPointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
|
let myPointInWindow = this.nativeView.convertPointToView(this.nativeView.bounds.origin, null);
|
||||||
let otherPointInWindow = otherView.nativeView.convertPointToView(otherView.nativeView.bounds.origin, null);
|
let otherPointInWindow = otherView.nativeView.convertPointToView(otherView.nativeView.bounds.origin, null);
|
||||||
return {
|
return {
|
||||||
x: layout.toDeviceIndependentPixels(myPointInWindow.x - otherPointInWindow.x),
|
x: myPointInWindow.x - otherPointInWindow.x,
|
||||||
y: layout.toDeviceIndependentPixels(myPointInWindow.y - otherPointInWindow.y),
|
y: myPointInWindow.y - otherPointInWindow.y
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import { Page } from "ui/page";
|
|||||||
import { FrameBase, View, application, layout, traceEnabled, traceWrite, traceCategories, isCategorySet } from "./frame-common";
|
import { FrameBase, View, application, layout, traceEnabled, traceWrite, traceCategories, isCategorySet } from "./frame-common";
|
||||||
import { _createIOSAnimatedTransitioning } from "ui/transition";
|
import { _createIOSAnimatedTransitioning } from "ui/transition";
|
||||||
import * as uiUtils from "ui/utils";
|
import * as uiUtils from "ui/utils";
|
||||||
|
import * as utils from "utils/utils";
|
||||||
|
|
||||||
export * from "./frame-common";
|
export * from "./frame-common";
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ export class GridLayout extends GridLayoutBase {
|
|||||||
|
|
||||||
actualLength = offset - roundedOffset;
|
actualLength = offset - roundedOffset;
|
||||||
roundedLength = Math.round(actualLength);
|
roundedLength = Math.round(actualLength);
|
||||||
columnGroup.rowOrColumn._actualLength = roundedLength;
|
columnGroup.rowOrColumn._actualLength = layout.toDeviceIndependentPixels(roundedLength);
|
||||||
roundedOffset += roundedLength;
|
roundedOffset += roundedLength;
|
||||||
|
|
||||||
this.columnOffsets.push(roundedOffset);
|
this.columnOffsets.push(roundedOffset);
|
||||||
@ -191,7 +191,7 @@ export class GridLayout extends GridLayoutBase {
|
|||||||
|
|
||||||
actualLength = offset - roundedOffset;
|
actualLength = offset - roundedOffset;
|
||||||
roundedLength = Math.round(actualLength);
|
roundedLength = Math.round(actualLength);
|
||||||
rowGroup.rowOrColumn._actualLength = roundedLength;
|
rowGroup.rowOrColumn._actualLength = layout.toDeviceIndependentPixels(roundedLength);
|
||||||
roundedOffset += roundedLength;
|
roundedOffset += roundedLength;
|
||||||
|
|
||||||
this.rowOffsets.push(roundedOffset);
|
this.rowOffsets.push(roundedOffset);
|
||||||
@ -417,7 +417,7 @@ class MeasureHelper {
|
|||||||
measureSpec.starColumnsCount += columnGroup.rowOrColumn.value;
|
measureSpec.starColumnsCount += columnGroup.rowOrColumn.value;
|
||||||
}
|
}
|
||||||
else if (columnGroup.getIsAbsolute()) {
|
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;
|
measureSpec.starRowsCount += rowGroup.rowOrColumn.value;
|
||||||
}
|
}
|
||||||
else if (rowGroup.getIsAbsolute()) {
|
else if (rowGroup.getIsAbsolute()) {
|
||||||
measureSpec.pixelHeight += rowGroup.rowOrColumn.value;
|
measureSpec.pixelHeight += layout.toDevicePixels(rowGroup.rowOrColumn.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ class UITableViewDelegateImpl extends NSObject implements UITableViewDelegate {
|
|||||||
height = owner._prepareCell(cell, indexPath);
|
height = owner._prepareCell(cell, indexPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return height;
|
return layout.toDeviceIndependentPixels(height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ class UIScrollViewDelegateImpl extends NSObject implements UIScrollViewDelegate
|
|||||||
owner.notify(<ScrollEventData>{
|
owner.notify(<ScrollEventData>{
|
||||||
object: owner,
|
object: owner,
|
||||||
eventName: ScrollViewBase.scrollEvent,
|
eventName: ScrollViewBase.scrollEvent,
|
||||||
scrollX: owner.horizontalOffset / layout.getDisplayDensity(),
|
scrollX: owner.horizontalOffset,
|
||||||
scrollY: owner.verticalOffset / layout.getDisplayDensity()
|
scrollY: owner.verticalOffset
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ export class ScrollView extends ScrollViewBase {
|
|||||||
return 0;
|
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 {
|
get scrollableHeight(): number {
|
||||||
@ -68,7 +68,7 @@ export class ScrollView extends ScrollViewBase {
|
|||||||
return 0;
|
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 {
|
get ios(): UIView {
|
||||||
@ -116,7 +116,10 @@ export class ScrollView extends ScrollViewBase {
|
|||||||
childSize = View.measureChild(this, child, layout.makeMeasureSpec(0, layout.UNSPECIFIED), heightMeasureSpec);
|
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._contentMeasuredWidth = Math.max(childSize.measuredWidth, this.effectiveMinWidth * density);
|
||||||
this._contentMeasuredHeight = Math.max(childSize.measuredHeight, this.effectiveMinHeight * density);
|
this._contentMeasuredHeight = Math.max(childSize.measuredHeight, this.effectiveMinHeight * density);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user