(widthMeasureSpec: number, heightMeasureSpec: number)
| 63 | } |
| 64 | |
| 65 | public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void { |
| 66 | const nativeView = this.nativeTextViewProtected; |
| 67 | if (nativeView) { |
| 68 | const width = layout.getMeasureSpecSize(widthMeasureSpec); |
| 69 | const widthMode = layout.getMeasureSpecMode(widthMeasureSpec); |
| 70 | |
| 71 | const height = layout.getMeasureSpecSize(heightMeasureSpec); |
| 72 | const heightMode = layout.getMeasureSpecMode(heightMeasureSpec); |
| 73 | |
| 74 | this._fixedSize = (widthMode === layout.EXACTLY ? FixedSize.WIDTH : FixedSize.NONE) | (heightMode === layout.EXACTLY ? FixedSize.HEIGHT : FixedSize.NONE); |
| 75 | |
| 76 | let nativeSize; |
| 77 | if (this.textWrap) { |
| 78 | // https://github.com/NativeScript/NativeScript/issues/4834 |
| 79 | // NOTE: utils.measureNativeView(...) relies on UIView.sizeThatFits(...) that |
| 80 | // seems to have various issues when laying out UILabel instances. |
| 81 | // We use custom measure logic here that relies on overriden |
| 82 | // UILabel.textRectForBounds:limitedToNumberOfLines: in TNSLabel widget. |
| 83 | nativeSize = this._measureNativeView(width, widthMode, height, heightMode); |
| 84 | } else { |
| 85 | // https://github.com/NativeScript/NativeScript/issues/6059 |
| 86 | // NOTE: _measureNativeView override breaks a scenario with StackLayout that arranges |
| 87 | // labels horizontally (with textWrap=false) e.g. we are measuring label #2 within 356px, |
| 88 | // label #2 needs more, and decides to show ellipsis(...) but because of this its native size |
| 89 | // returned from UILabel.textRectForBounds:limitedToNumberOfLines: logic becomes 344px, so |
| 90 | // StackLayout tries to measure label #3 within the remaining 12px which is wrong; |
| 91 | // label #2 with ellipsis should take the whole 356px and label #3 should not be visible at all. |
| 92 | nativeSize = layout.measureNativeView(nativeView, width, widthMode, height, heightMode); |
| 93 | } |
| 94 | |
| 95 | let labelWidth = nativeSize.width; |
| 96 | |
| 97 | if (this.textWrap && widthMode === layout.AT_MOST) { |
| 98 | labelWidth = Math.min(labelWidth, width); |
| 99 | } |
| 100 | |
| 101 | const measureWidth = Math.max(labelWidth, this.effectiveMinWidth); |
| 102 | const measureHeight = Math.max(nativeSize.height, this.effectiveMinHeight); |
| 103 | |
| 104 | const widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0); |
| 105 | const heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0); |
| 106 | |
| 107 | this.setMeasuredDimension(widthAndState, heightAndState); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | private _measureNativeView(width: number, widthMode: number, height: number, heightMode: number): { width: number; height: number } { |
| 112 | const view = this.nativeTextViewProtected; |
nothing calls this directly
no test coverage detected