Label textWrap fix for iOS (#3842)

This commit is contained in:
Hristo Hristov
2017-03-21 15:33:52 +02:00
committed by GitHub
parent 9b47fff54a
commit f8b13acce6
6 changed files with 33 additions and 34 deletions

View File

@@ -14,21 +14,21 @@ export class Border extends ContentView implements BorderDefinition {
}
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
let width = layout.getMeasureSpecSize(widthMeasureSpec);
let widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
const width = layout.getMeasureSpecSize(widthMeasureSpec);
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
let height = layout.getMeasureSpecSize(heightMeasureSpec);
let heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
const height = layout.getMeasureSpecSize(heightMeasureSpec);
const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
let horizontalBorderLength = this.effectiveBorderLeftWidth + this.effectiveBorderRightWidth;
let verticalBorderLength = this.effectiveBorderTopWidth + this.effectiveBorderBottomWidth;
const horizontalBorderLength = this.effectiveBorderLeftWidth + this.effectiveBorderRightWidth;
const verticalBorderLength = this.effectiveBorderTopWidth + this.effectiveBorderBottomWidth;
let result = View.measureChild(this, this.layoutView,
const result = View.measureChild(this, this.layoutView,
layout.makeMeasureSpec(width - horizontalBorderLength, widthMode),
layout.makeMeasureSpec(height - verticalBorderLength, heightMode));
let widthAndState = View.resolveSizeAndState(result.measuredWidth + horizontalBorderLength, width, widthMode, 0);
let heightAndState = View.resolveSizeAndState(result.measuredHeight + verticalBorderLength, height, heightMode, 0);
const widthAndState = View.resolveSizeAndState(result.measuredWidth + horizontalBorderLength, width, widthMode, 0);
const heightAndState = View.resolveSizeAndState(result.measuredHeight + verticalBorderLength, height, heightMode, 0);
this.setMeasuredDimension(widthAndState, heightAndState);
}

View File

@@ -69,19 +69,19 @@ export class ContentView extends CustomLayoutView implements ContentViewDefiniti
// This method won't be called in Android because we use the native android layout.
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
let result = View.measureChild(this, this.layoutView, widthMeasureSpec, heightMeasureSpec);
const result = View.measureChild(this, this.layoutView, widthMeasureSpec, heightMeasureSpec);
let width = layout.getMeasureSpecSize(widthMeasureSpec);
let widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
const width = layout.getMeasureSpecSize(widthMeasureSpec);
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
let height = layout.getMeasureSpecSize(heightMeasureSpec);
let heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
const height = layout.getMeasureSpecSize(heightMeasureSpec);
const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
let measureWidth = Math.max(result.measuredWidth, this.effectiveMinWidth);
let measureHeight = Math.max(result.measuredHeight, this.effectiveMinHeight);
const measureWidth = Math.max(result.measuredWidth, this.effectiveMinWidth);
const measureHeight = Math.max(result.measuredHeight, this.effectiveMinHeight);
let widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
let heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
const widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
const heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
this.setMeasuredDimension(widthAndState, heightAndState);
}

View File

@@ -459,21 +459,21 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
let result = size;
switch (specMode) {
case layout.UNSPECIFIED:
result = size;
result = Math.ceil(size);
break;
case layout.AT_MOST:
if (specSize < size) {
result = Math.round(specSize + 0.499) | layout.MEASURED_STATE_TOO_SMALL;
result = Math.ceil(specSize) | layout.MEASURED_STATE_TOO_SMALL;
}
break;
case layout.EXACTLY:
result = specSize;
result = Math.ceil(specSize);
break;
}
return Math.round(result + 0.499) | (childMeasuredState & layout.MEASURED_STATE_MASK);
return result | (childMeasuredState & layout.MEASURED_STATE_MASK);
}
public static combineMeasuredStates(curState: number, newState): number {

View File

@@ -29,7 +29,6 @@ export class HtmlView extends HtmlViewBase {
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
var nativeView = this._nativeView;
if (nativeView) {
const width = layout.getMeasureSpecSize(widthMeasureSpec);
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
@@ -38,7 +37,7 @@ export class HtmlView extends HtmlViewBase {
const desiredSize = layout.measureNativeView(nativeView, width, widthMode, height, heightMode);
const labelWidth = Math.min(desiredSize.width, width);
const labelWidth = widthMode === layout.AT_MOST ? Math.min(desiredSize.width, width) : desiredSize.width;
const measureWidth = Math.max(labelWidth, this.effectiveMinWidth);
const measureHeight = Math.max(desiredSize.height, this.effectiveMinHeight);

View File

@@ -67,11 +67,11 @@ export class Label extends TextBase implements LabelDefinition {
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
let nativeView = this.nativeView;
if (nativeView) {
let width = layout.getMeasureSpecSize(widthMeasureSpec);
let widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
const width = layout.getMeasureSpecSize(widthMeasureSpec);
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
let height = layout.getMeasureSpecSize(heightMeasureSpec);
let heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
const height = layout.getMeasureSpecSize(heightMeasureSpec);
const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
this._fixedSize = (widthMode === layout.EXACTLY ? FixedSize.WIDTH : FixedSize.NONE)
| (heightMode === layout.EXACTLY ? FixedSize.HEIGHT : FixedSize.NONE);
@@ -79,15 +79,15 @@ export class Label extends TextBase implements LabelDefinition {
const nativeSize = layout.measureNativeView(nativeView, width, widthMode, height, heightMode);
let labelWidth = nativeSize.width;
if (this.textWrap) {
if (this.textWrap && widthMode === layout.AT_MOST) {
labelWidth = Math.min(labelWidth, width);
}
let measureWidth = Math.max(labelWidth, this.effectiveMinWidth);
let measureHeight = Math.max(nativeSize.height, this.effectiveMinHeight);
const measureWidth = Math.max(labelWidth, this.effectiveMinWidth);
const measureHeight = Math.max(nativeSize.height, this.effectiveMinHeight);
let widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
let heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
const widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
const heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
this.setMeasuredDimension(widthAndState, heightAndState);
}

View File

@@ -16,7 +16,7 @@ export module layout {
var MODE_MASK = 0x3 << MODE_SHIFT;
export function makeMeasureSpec(size: number, mode: number): number {
return (Math.round(size) & ~MODE_MASK) | (mode & MODE_MASK);
return (Math.round(Math.max(0, size)) & ~MODE_MASK) | (mode & MODE_MASK);
}
export function getDisplayDensity(): number {