@@ -138,7 +138,7 @@ class LabelUITextViewDelegateImpl extends NSObject implements UITextViewDelegate
138
138
textViewDidChange ?( textView : UITextView ) {
139
139
const owner = this . _owner . get ( ) ;
140
140
if ( owner ) {
141
- owner . textViewDidChange ( textView ) ;
141
+ owner . textViewDidChange ( textView , undefined , undefined , true ) ;
142
142
}
143
143
}
144
144
}
@@ -412,10 +412,9 @@ export class Label extends LabelBase {
412
412
const height = layout . getMeasureSpecSize ( heightMeasureSpec ) ;
413
413
const heightMode = layout . getMeasureSpecMode ( heightMeasureSpec ) ;
414
414
if ( this . autoFontSize ) {
415
- const finiteWidth : boolean = widthMode === layout . EXACTLY ;
416
- const finiteHeight : boolean = heightMode === layout . EXACTLY ;
415
+ const finiteWidth = widthMode === layout . EXACTLY ;
416
+ const finiteHeight = heightMode === layout . EXACTLY ;
417
417
if ( ! finiteWidth || ! finiteHeight ) {
418
- this . needsAutoFontSize = true ;
419
418
this . textViewDidChange (
420
419
nativeView ,
421
420
layout . toDeviceIndependentPixels ( width ) ,
@@ -437,6 +436,12 @@ export class Label extends LabelBase {
437
436
this . setMeasuredDimension ( widthAndState , heightAndState ) ;
438
437
}
439
438
}
439
+ _onSizeChanged ( ) {
440
+ super . _onSizeChanged ( ) ;
441
+ if ( this . autoFontSize ) {
442
+ this . textViewDidChange ( this . nativeTextViewProtected ) ;
443
+ }
444
+ }
440
445
// _htmlTappable = false;
441
446
// _htmlTapGestureRecognizer;
442
447
@@ -560,26 +565,18 @@ export class Label extends LabelBase {
560
565
}
561
566
@needFormattedStringComputation
562
567
[ htmlProperty . setNative ] ( value : string ) {
563
- this . fontSizeRatio = 1 ;
564
- this . needsAutoFontSize = this . autoFontSize ;
565
568
this . updateHTMLString ( ) ;
566
569
}
567
570
@needFormattedStringComputation
568
571
[ formattedTextProperty . setNative ] ( value : string ) {
569
- this . fontSizeRatio = 1 ;
570
- this . needsAutoFontSize = this . autoFontSize ;
571
572
super [ formattedTextProperty . setNative ] ( value ) ;
572
573
}
573
574
@needFormattedStringComputation
574
575
[ letterSpacingProperty . setNative ] ( value : number ) {
575
- this . fontSizeRatio = 1 ;
576
- this . needsAutoFontSize = this . autoFontSize ;
577
576
super [ letterSpacingProperty . setNative ] ( value ) ;
578
577
}
579
578
@needFormattedStringComputation
580
579
[ lineHeightProperty . setNative ] ( value : number ) {
581
- this . fontSizeRatio = 1 ;
582
- this . needsAutoFontSize = this . autoFontSize ;
583
580
super [ lineHeightProperty . setNative ] ( value ) ;
584
581
}
585
582
// @needFormattedStringComputation
@@ -588,8 +585,6 @@ export class Label extends LabelBase {
588
585
// }
589
586
[ fontInternalProperty . setNative ] ( value : any ) {
590
587
const nativeView = this . nativeTextViewProtected ;
591
- this . fontSizeRatio = 1 ;
592
- this . needsAutoFontSize = this . autoFontSize ;
593
588
const newFont : UIFont = value instanceof Font ? value . getUIFont ( nativeView . font ) : value ;
594
589
if ( ! this . formattedText && ! this . html ) {
595
590
nativeView . font = newFont ;
@@ -914,10 +909,9 @@ export class Label extends LabelBase {
914
909
}
915
910
916
911
fontSizeRatio = 1 ;
917
- needsAutoFontSize = false ;
918
- textViewDidChange ( textView : UITextView , width ?, height ?) {
919
- if ( this . autoFontSize && this . needsAutoFontSize ) {
920
- this . needsAutoFontSize = false ;
912
+ _lastAutoSizeKey : string ;
913
+ textViewDidChange ( textView : UITextView , width ?, height ?, force = false ) {
914
+ if ( textView && this . autoFontSize ) {
921
915
if (
922
916
( ! textView . attributedText && ! textView . text ) ||
923
917
( width === undefined && height === undefined && CGSizeEqualToSize ( textView . bounds . size , CGSizeZero ) )
@@ -926,11 +920,16 @@ export class Label extends LabelBase {
926
920
}
927
921
928
922
const textViewSize = textView . frame . size ;
929
- const fixedWidth = width !== undefined ? width : textViewSize . width ;
930
- const fixedHeight = height !== undefined ? height : textViewSize . height ;
923
+ const fixedWidth = Math . floor ( width !== undefined ? width : textViewSize . width ) ;
924
+ const fixedHeight = Math . floor ( height !== undefined ? height : textViewSize . height ) ;
931
925
if ( fixedWidth === 0 || fixedHeight === 0 ) {
932
926
return ;
933
927
}
928
+ const autoSizeKey = fixedWidth + '_' + fixedHeight ;
929
+ if ( ! force && autoSizeKey === this . _lastAutoSizeKey ) {
930
+ return ;
931
+ }
932
+ this . _lastAutoSizeKey = autoSizeKey ;
934
933
const nbLines = textView . textContainer . maximumNumberOfLines ;
935
934
// we need to reset verticalTextAlignment or computation will be wrong
936
935
this . updateTextContainerInset ( false ) ;
@@ -1002,10 +1001,10 @@ export class Label extends LabelBase {
1002
1001
}
1003
1002
}
1004
1003
[ autoFontSizeProperty . setNative ] ( value : boolean ) {
1005
- if ( value && ( this . text || this . html || this . formattedText ) ) {
1006
- this . fontSizeRatio = 1 ;
1007
- this . needsAutoFontSize = true ;
1008
- this . textViewDidChange ( this . nativeTextViewProtected ) ;
1004
+ if ( value ) {
1005
+ if ( this . isLayoutValid && ( this . text || this . html || this . formattedText ) ) {
1006
+ this . textViewDidChange ( this . nativeTextViewProtected , undefined , undefined , true ) ;
1007
+ }
1009
1008
} else {
1010
1009
this [ fontInternalProperty . setNative ] ( this . style . fontInternal ) ;
1011
1010
}
0 commit comments