mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Add support for 'px' on Length in iOS
This commit is contained in:
@@ -248,8 +248,8 @@ export class ActionBar extends ActionBarBase {
|
||||
let navBarSize = navBar.sizeThatFits(CGSizeMake(
|
||||
(widthMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : width,
|
||||
(heightMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : height));
|
||||
navBarWidth = navBarSize.width;
|
||||
navBarHeight = navBarSize.height;
|
||||
navBarWidth = layout.toDevicePixels(navBarSize.width);
|
||||
navBarHeight = layout.toDevicePixels(navBarSize.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,8 +120,8 @@ export class View extends ViewCommon {
|
||||
}
|
||||
|
||||
let nativeSize = view.sizeThatFits(CGSizeMake(width, height));
|
||||
nativeWidth = nativeSize.width;
|
||||
nativeHeight = nativeSize.height;
|
||||
nativeWidth = layout.toDevicePixels(nativeSize.width);
|
||||
nativeHeight = layout.toDevicePixels(nativeSize.height);
|
||||
}
|
||||
|
||||
let measureWidth = Math.max(nativeWidth, this.effectiveMinWidth);
|
||||
@@ -165,7 +165,7 @@ export class View extends ViewCommon {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ export class Frame extends FrameBase {
|
||||
!this._ios.controller ||
|
||||
!this._ios.controller.navigationBar ||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -380,10 +380,10 @@ export class Frame extends FrameBase {
|
||||
this._ios.controller.navigationBar.autoresizingMask = UIViewAutoresizing.None;
|
||||
this._ios.controller.navigationBar.removeConstraints((<any>this)._ios.controller.navigationBar.constraints);
|
||||
this._ios.controller.navigationBar.frame = CGRectMake(
|
||||
this._ios.controller.navigationBar.frame.origin.x,
|
||||
statusBarHeight,
|
||||
this._ios.controller.navigationBar.frame.size.width,
|
||||
this._ios.controller.navigationBar.frame.size.height);
|
||||
utils.layout.toDeviceIndependentPixels(this._ios.controller.navigationBar.frame.origin.x),
|
||||
utils.layout.toDeviceIndependentPixels(statusBarHeight),
|
||||
utils.layout.toDeviceIndependentPixels(this._ios.controller.navigationBar.frame.size.width),
|
||||
utils.layout.toDeviceIndependentPixels(this._ios.controller.navigationBar.frame.size.height));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,11 +45,11 @@ export class HtmlView extends HtmlViewBase {
|
||||
}
|
||||
|
||||
let nativeSize = nativeView.sizeThatFits(CGSizeMake(width, height));
|
||||
let labelWidth = nativeSize.width;
|
||||
let labelWidth = layout.toDevicePixels(nativeSize.width);
|
||||
|
||||
labelWidth = Math.min(labelWidth, width);
|
||||
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 heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
||||
|
||||
@@ -85,14 +85,14 @@ export class Label extends TextBase implements LabelDefinition {
|
||||
| (heightMode === layout.EXACTLY ? FixedSize.HEIGHT : FixedSize.NONE);
|
||||
|
||||
let nativeSize = nativeView.sizeThatFits(CGSizeMake(width, height));
|
||||
let labelWidth = nativeSize.width;
|
||||
let labelWidth = layout.toDevicePixels(nativeSize.width);
|
||||
|
||||
if (this.textWrap) {
|
||||
labelWidth = Math.min(labelWidth, width);
|
||||
}
|
||||
|
||||
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 heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
||||
|
||||
@@ -36,7 +36,7 @@ export module ios {
|
||||
const layer = nativeView.layer;
|
||||
const borderColor = background.getUniformBorderColor();
|
||||
layer.borderColor = !borderColor ? undefined : borderColor.ios.CGColor;
|
||||
layer.borderWidth = background.getUniformBorderWidth();
|
||||
layer.borderWidth = layout.toDeviceIndependentPixels(background.getUniformBorderWidth());
|
||||
layer.cornerRadius = background.getUniformBorderRadius();
|
||||
}
|
||||
else {
|
||||
@@ -177,10 +177,10 @@ function drawNonUniformBorders(nativeView: NativeView, background: Background) {
|
||||
right: layerSize.width
|
||||
};
|
||||
|
||||
const top = background.borderTopWidth;
|
||||
const right = background.borderRightWidth;
|
||||
const bottom = background.borderBottomWidth;
|
||||
const left = background.borderLeftWidth;
|
||||
const top = layout.toDeviceIndependentPixels(background.borderTopWidth);
|
||||
const right = layout.toDeviceIndependentPixels(background.borderRightWidth);
|
||||
const bottom = layout.toDeviceIndependentPixels(background.borderBottomWidth);
|
||||
const left = layout.toDeviceIndependentPixels(background.borderLeftWidth);
|
||||
|
||||
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
|
||||
|
||||
@@ -56,8 +56,8 @@ export class Switch extends SwitchBase {
|
||||
this.width = nativeSize.width;
|
||||
this.height = nativeSize.height;
|
||||
|
||||
let widthAndState = layout.makeMeasureSpec(nativeSize.width, layout.EXACTLY);
|
||||
let heightAndState = layout.makeMeasureSpec(nativeSize.height, layout.EXACTLY);
|
||||
let widthAndState = layout.makeMeasureSpec(layout.toDevicePixels(nativeSize.width), layout.EXACTLY);
|
||||
let heightAndState = layout.makeMeasureSpec(layout.toDevicePixels(nativeSize.height), layout.EXACTLY);
|
||||
this.setMeasuredDimension(widthAndState, heightAndState);
|
||||
}
|
||||
|
||||
|
||||
@@ -347,9 +347,10 @@ export class TabView extends TabViewBase {
|
||||
}
|
||||
|
||||
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,
|
||||
(heightMode === layout.UNSPECIFIED) ? Number.POSITIVE_INFINITY : height));
|
||||
return { width: layout.toDevicePixels(size.width), height: layout.toDevicePixels(size.height) };
|
||||
}
|
||||
|
||||
private _updateIOSTabBarColorsAndFonts(): void {
|
||||
|
||||
@@ -18,7 +18,8 @@ export module ios {
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -27,8 +28,8 @@ export module ios {
|
||||
}
|
||||
|
||||
let size = parentBounds.size;
|
||||
let width = size.width;
|
||||
let height = size.height;
|
||||
let width = utils.layout.toDevicePixels(size.width);
|
||||
let height = utils.layout.toDevicePixels(size.height);
|
||||
|
||||
var superview = (<UIView>rootView._nativeView).superview;
|
||||
var superViewRotationRadians;
|
||||
@@ -38,8 +39,8 @@ export module ios {
|
||||
|
||||
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.
|
||||
width = size.height;
|
||||
height = size.width;
|
||||
width = utils.layout.toDevicePixels(size.width);
|
||||
height = utils.layout.toDevicePixels(size.height);
|
||||
}
|
||||
|
||||
var origin = parentBounds.origin;
|
||||
|
||||
@@ -5,6 +5,8 @@ import {
|
||||
|
||||
export * from "./utils-common";
|
||||
|
||||
let mainScreenScale;
|
||||
|
||||
function isOrientationLandscape(orientation: number) {
|
||||
return orientation === UIDeviceOrientation.LandscapeLeft || orientation === UIDeviceOrientation.LandscapeRight;
|
||||
}
|
||||
@@ -18,15 +20,15 @@ export module layout {
|
||||
}
|
||||
|
||||
export function getDisplayDensity(): number {
|
||||
return 1;
|
||||
return mainScreenScale;
|
||||
}
|
||||
|
||||
export function toDevicePixels(value: number): number {
|
||||
return value * getDisplayDensity();
|
||||
return value * mainScreenScale;
|
||||
}
|
||||
|
||||
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 {
|
||||
return this.getViewController().view.frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mainScreenScale = ios.getter(UIScreen, UIScreen.mainScreen).scale;
|
||||
Reference in New Issue
Block a user