Add support for 'px' on Length in iOS

This commit is contained in:
Panayot Cankov
2017-03-06 13:19:57 +02:00
parent b45cbe929b
commit 9f1ebc11ca
10 changed files with 37 additions and 31 deletions

View File

@@ -248,8 +248,8 @@ export class ActionBar extends ActionBarBase {
let navBarSize = navBar.sizeThatFits(CGSizeMake( let navBarSize = navBar.sizeThatFits(CGSizeMake(
(widthMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : width, (widthMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : width,
(heightMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : height)); (heightMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : height));
navBarWidth = navBarSize.width; navBarWidth = layout.toDevicePixels(navBarSize.width);
navBarHeight = navBarSize.height; navBarHeight = layout.toDevicePixels(navBarSize.height);
} }
} }

View File

@@ -120,8 +120,8 @@ export class View extends ViewCommon {
} }
let nativeSize = view.sizeThatFits(CGSizeMake(width, height)); let nativeSize = view.sizeThatFits(CGSizeMake(width, height));
nativeWidth = nativeSize.width; nativeWidth = layout.toDevicePixels(nativeSize.width);
nativeHeight = nativeSize.height; nativeHeight = layout.toDevicePixels(nativeSize.height);
} }
let measureWidth = Math.max(nativeWidth, this.effectiveMinWidth); let measureWidth = Math.max(nativeWidth, this.effectiveMinWidth);
@@ -165,7 +165,7 @@ export class View extends ViewCommon {
let nativeView = this.nativeView; let nativeView = this.nativeView;
let frame = CGRectMake(left, top, right - left, bottom - top); let frame = CGRectMake(layout.toDeviceIndependentPixels(left), layout.toDeviceIndependentPixels(top), layout.toDeviceIndependentPixels(right - left), layout.toDeviceIndependentPixels(bottom - top));
this._setNativeViewFrame(nativeView, frame); this._setNativeViewFrame(nativeView, frame);
} }

View File

@@ -369,7 +369,7 @@ export class Frame extends FrameBase {
!this._ios.controller || !this._ios.controller ||
!this._ios.controller.navigationBar || !this._ios.controller.navigationBar ||
this._ios.controller.navigationBar.hidden || this._ios.controller.navigationBar.hidden ||
this._ios.controller.navigationBar.frame.origin.y === statusBarHeight) { utils.layout.toDevicePixels(this._ios.controller.navigationBar.frame.origin.y) === statusBarHeight) {
return; return;
} }
@@ -380,10 +380,10 @@ export class Frame extends FrameBase {
this._ios.controller.navigationBar.autoresizingMask = UIViewAutoresizing.None; this._ios.controller.navigationBar.autoresizingMask = UIViewAutoresizing.None;
this._ios.controller.navigationBar.removeConstraints((<any>this)._ios.controller.navigationBar.constraints); this._ios.controller.navigationBar.removeConstraints((<any>this)._ios.controller.navigationBar.constraints);
this._ios.controller.navigationBar.frame = CGRectMake( this._ios.controller.navigationBar.frame = CGRectMake(
this._ios.controller.navigationBar.frame.origin.x, utils.layout.toDeviceIndependentPixels(this._ios.controller.navigationBar.frame.origin.x),
statusBarHeight, utils.layout.toDeviceIndependentPixels(statusBarHeight),
this._ios.controller.navigationBar.frame.size.width, utils.layout.toDeviceIndependentPixels(this._ios.controller.navigationBar.frame.size.width),
this._ios.controller.navigationBar.frame.size.height); utils.layout.toDeviceIndependentPixels(this._ios.controller.navigationBar.frame.size.height));
} }
} }

View File

@@ -45,11 +45,11 @@ export class HtmlView extends HtmlViewBase {
} }
let nativeSize = nativeView.sizeThatFits(CGSizeMake(width, height)); let nativeSize = nativeView.sizeThatFits(CGSizeMake(width, height));
let labelWidth = nativeSize.width; let labelWidth = layout.toDevicePixels(nativeSize.width);
labelWidth = Math.min(labelWidth, width); labelWidth = Math.min(labelWidth, width);
let measureWidth = Math.max(labelWidth, this.effectiveMinWidth); let measureWidth = Math.max(labelWidth, this.effectiveMinWidth);
let measureHeight = Math.max(nativeSize.height, this.effectiveMinHeight); let measureHeight = Math.max(layout.toDevicePixels(nativeSize.height), this.effectiveMinHeight);
let widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0); let widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
let heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0); let heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);

View File

@@ -85,14 +85,14 @@ export class Label extends TextBase implements LabelDefinition {
| (heightMode === layout.EXACTLY ? FixedSize.HEIGHT : FixedSize.NONE); | (heightMode === layout.EXACTLY ? FixedSize.HEIGHT : FixedSize.NONE);
let nativeSize = nativeView.sizeThatFits(CGSizeMake(width, height)); let nativeSize = nativeView.sizeThatFits(CGSizeMake(width, height));
let labelWidth = nativeSize.width; let labelWidth = layout.toDevicePixels(nativeSize.width);
if (this.textWrap) { if (this.textWrap) {
labelWidth = Math.min(labelWidth, width); labelWidth = Math.min(labelWidth, width);
} }
let measureWidth = Math.max(labelWidth, this.effectiveMinWidth); let measureWidth = Math.max(labelWidth, this.effectiveMinWidth);
let measureHeight = Math.max(nativeSize.height, this.effectiveMinHeight); let measureHeight = Math.max(layout.toDevicePixels(nativeSize.height), this.effectiveMinHeight);
let widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0); let widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
let heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0); let heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);

View File

@@ -36,7 +36,7 @@ export module ios {
const layer = nativeView.layer; const layer = nativeView.layer;
const borderColor = background.getUniformBorderColor(); const borderColor = background.getUniformBorderColor();
layer.borderColor = !borderColor ? undefined : borderColor.ios.CGColor; layer.borderColor = !borderColor ? undefined : borderColor.ios.CGColor;
layer.borderWidth = background.getUniformBorderWidth(); layer.borderWidth = layout.toDeviceIndependentPixels(background.getUniformBorderWidth());
layer.cornerRadius = background.getUniformBorderRadius(); layer.cornerRadius = background.getUniformBorderRadius();
} }
else { else {
@@ -177,10 +177,10 @@ function drawNonUniformBorders(nativeView: NativeView, background: Background) {
right: layerSize.width right: layerSize.width
}; };
const top = background.borderTopWidth; const top = layout.toDeviceIndependentPixels(background.borderTopWidth);
const right = background.borderRightWidth; const right = layout.toDeviceIndependentPixels(background.borderRightWidth);
const bottom = background.borderBottomWidth; const bottom = layout.toDeviceIndependentPixels(background.borderBottomWidth);
const left = background.borderLeftWidth; const left = layout.toDeviceIndependentPixels(background.borderLeftWidth);
const lto: Point = { x: nativeViewLayerBounds.left, y: nativeViewLayerBounds.top };// left-top-outside const lto: Point = { x: nativeViewLayerBounds.left, y: nativeViewLayerBounds.top };// left-top-outside
const lti: Point = { x: nativeViewLayerBounds.left + left, y: nativeViewLayerBounds.top + top }; // left-top-inside const lti: Point = { x: nativeViewLayerBounds.left + left, y: nativeViewLayerBounds.top + top }; // left-top-inside

View File

@@ -56,8 +56,8 @@ export class Switch extends SwitchBase {
this.width = nativeSize.width; this.width = nativeSize.width;
this.height = nativeSize.height; this.height = nativeSize.height;
let widthAndState = layout.makeMeasureSpec(nativeSize.width, layout.EXACTLY); let widthAndState = layout.makeMeasureSpec(layout.toDevicePixels(nativeSize.width), layout.EXACTLY);
let heightAndState = layout.makeMeasureSpec(nativeSize.height, layout.EXACTLY); let heightAndState = layout.makeMeasureSpec(layout.toDevicePixels(nativeSize.height), layout.EXACTLY);
this.setMeasuredDimension(widthAndState, heightAndState); this.setMeasuredDimension(widthAndState, heightAndState);
} }

View File

@@ -347,9 +347,10 @@ export class TabView extends TabViewBase {
} }
private static measureHelper(nativeView: UIView, width: number, widthMode: number, height: number, heightMode: number): CGSize { private static measureHelper(nativeView: UIView, width: number, widthMode: number, height: number, heightMode: number): CGSize {
return nativeView.sizeThatFits(CGSizeMake( const size = nativeView.sizeThatFits(CGSizeMake(
(widthMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : width, (widthMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : width,
(heightMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : height)); (heightMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : height));
return { width: layout.toDevicePixels(size.width), height: layout.toDevicePixels(size.height) };
} }
private _updateIOSTabBarColorsAndFonts(): void { private _updateIOSTabBarColorsAndFonts(): void {

View File

@@ -18,7 +18,8 @@ export module ios {
} }
var statusFrame = app.statusBarFrame; var statusFrame = app.statusBarFrame;
return Math.min(statusFrame.size.width, statusFrame.size.height); let min = Math.min(statusFrame.size.width, statusFrame.size.height);
return utils.layout.toDevicePixels(min);
} }
export function _layoutRootView(rootView: View, parentBounds: CGRect) { export function _layoutRootView(rootView: View, parentBounds: CGRect) {
@@ -27,8 +28,8 @@ export module ios {
} }
let size = parentBounds.size; let size = parentBounds.size;
let width = size.width; let width = utils.layout.toDevicePixels(size.width);
let height = size.height; let height = utils.layout.toDevicePixels(size.height);
var superview = (<UIView>rootView._nativeView).superview; var superview = (<UIView>rootView._nativeView).superview;
var superViewRotationRadians; var superViewRotationRadians;
@@ -38,8 +39,8 @@ export module ios {
if (utils.ios.MajorVersion < 8 && utils.ios.isLandscape() && !superViewRotationRadians) { if (utils.ios.MajorVersion < 8 && utils.ios.isLandscape() && !superViewRotationRadians) {
// in iOS 7 when in landscape we switch width with height because on device they don't change even when rotated. // in iOS 7 when in landscape we switch width with height because on device they don't change even when rotated.
width = size.height; width = utils.layout.toDevicePixels(size.width);
height = size.width; height = utils.layout.toDevicePixels(size.height);
} }
var origin = parentBounds.origin; var origin = parentBounds.origin;

View File

@@ -5,6 +5,8 @@ import {
export * from "./utils-common"; export * from "./utils-common";
let mainScreenScale;
function isOrientationLandscape(orientation: number) { function isOrientationLandscape(orientation: number) {
return orientation === UIDeviceOrientation.LandscapeLeft || orientation === UIDeviceOrientation.LandscapeRight; return orientation === UIDeviceOrientation.LandscapeLeft || orientation === UIDeviceOrientation.LandscapeRight;
} }
@@ -18,15 +20,15 @@ export module layout {
} }
export function getDisplayDensity(): number { export function getDisplayDensity(): number {
return 1; return mainScreenScale;
} }
export function toDevicePixels(value: number): number { export function toDevicePixels(value: number): number {
return value * getDisplayDensity(); return value * mainScreenScale;
} }
export function toDeviceIndependentPixels(value: number): number { export function toDeviceIndependentPixels(value: number): number {
return value / getDisplayDensity(); return value / mainScreenScale;
} }
} }
@@ -119,4 +121,6 @@ class UIDocumentInteractionControllerDelegateImpl extends NSObject implements UI
public documentInteractionControllerRectForPreview(controller: UIDocumentInteractionController): CGRect { public documentInteractionControllerRectForPreview(controller: UIDocumentInteractionController): CGRect {
return this.getViewController().view.frame; return this.getViewController().view.frame;
} }
} }
mainScreenScale = ios.getter(UIScreen, UIScreen.mainScreen).scale;