@@ -68,7 +68,11 @@ export class Label extends TextBase implements LabelDefinition {
6868 this . _fixedSize = ( widthMode === layout . EXACTLY ? FixedSize . WIDTH : FixedSize . NONE )
6969 | ( heightMode === layout . EXACTLY ? FixedSize . HEIGHT : FixedSize . NONE ) ;
7070
71- const nativeSize = layout . measureNativeView ( nativeView , width , widthMode , height , heightMode ) ;
71+ // NOTE: utils.measureNativeView(...) relies on UIView.sizeThatFits(...) that
72+ // seems to have various issues when laying out UILabel instances.
73+ // We use custom measure logic here that relies on overriden
74+ // UILabel.textRectForBounds:limitedToNumberOfLines: in TNSLabel widget.
75+ const nativeSize = this . _measureNativeView ( width , widthMode , height , heightMode ) ;
7276 let labelWidth = nativeSize . width ;
7377
7478 if ( this . textWrap && widthMode === layout . AT_MOST ) {
@@ -85,6 +89,22 @@ export class Label extends TextBase implements LabelDefinition {
8589 }
8690 }
8791
92+ private _measureNativeView ( width : number , widthMode : number , height : number , heightMode : number ) : { width : number , height : number } {
93+ const view = < UILabel > this . nativeViewProtected ;
94+
95+ const nativeSize = view . textRectForBoundsLimitedToNumberOfLines (
96+ CGRectMake (
97+ 0 ,
98+ 0 ,
99+ widthMode === 0 /* layout.UNSPECIFIED */ ? Number . POSITIVE_INFINITY : layout . toDeviceIndependentPixels ( width ) ,
100+ heightMode === 0 /* layout.UNSPECIFIED */ ? Number . POSITIVE_INFINITY : layout . toDeviceIndependentPixels ( height )
101+ ) , 0 ) . size ;
102+
103+ nativeSize . width = layout . round ( layout . toDevicePixels ( nativeSize . width ) ) ;
104+ nativeSize . height = layout . round ( layout . toDevicePixels ( nativeSize . height ) ) ;
105+ return nativeSize ;
106+ }
107+
88108 [ whiteSpaceProperty . setNative ] ( value : WhiteSpace ) {
89109 const nativeView = this . nativeViewProtected ;
90110 switch ( value ) {
0 commit comments