@@ -139,7 +139,7 @@ class LabelUITextViewDelegateImpl extends NSObject implements UITextViewDelegate
139
139
textViewDidChange ?( textView : UITextView ) {
140
140
const owner = this . _owner . get ( ) ;
141
141
if ( owner ) {
142
- owner . textViewDidChange ( textView , undefined , undefined , true ) ;
142
+ owner . textViewDidChange ( textView ) ;
143
143
}
144
144
}
145
145
}
@@ -326,19 +326,24 @@ export class Label extends LabelBase {
326
326
327
327
const height = layout . getMeasureSpecSize ( heightMeasureSpec ) ;
328
328
const heightMode = layout . getMeasureSpecMode ( heightMeasureSpec ) ;
329
+ let resetFont ;
329
330
if ( this . autoFontSize ) {
330
331
const finiteWidth = widthMode === layout . EXACTLY ;
331
332
const finiteHeight = heightMode === layout . EXACTLY ;
332
333
if ( ! finiteWidth || ! finiteHeight ) {
333
- this . textViewDidChange (
334
- nativeView ,
335
- layout . toDeviceIndependentPixels ( width ) ,
336
- layout . toDeviceIndependentPixels ( height )
337
- ) ;
334
+ resetFont = this . updateAutoFontSize ( {
335
+ textView : nativeView ,
336
+ width : layout . toDeviceIndependentPixels ( width ) ,
337
+ height : layout . toDeviceIndependentPixels ( height ) ,
338
+ onlyMeasure : true
339
+ } ) ;
338
340
}
339
341
}
340
342
341
343
const desiredSize = layout . measureNativeView ( nativeView , width , widthMode , height , heightMode ) ;
344
+ if ( resetFont ) {
345
+ nativeView . font = resetFont ;
346
+ }
342
347
343
348
const labelWidth = widthMode === layout . AT_MOST ? Math . min ( desiredSize . width , width ) : desiredSize . width ;
344
349
// const labelHeight = heightMode === layout.AT_MOST ? Math.min(desiredSize.height, height) : desiredSize.height;
@@ -354,7 +359,7 @@ export class Label extends LabelBase {
354
359
_onSizeChanged ( ) {
355
360
super . _onSizeChanged ( ) ;
356
361
if ( this . autoFontSize ) {
357
- this . textViewDidChange ( this . nativeTextViewProtected ) ;
362
+ this . updateAutoFontSize ( { textView : this . nativeTextViewProtected } ) ;
358
363
}
359
364
}
360
365
// _htmlTappable = false;
@@ -753,25 +758,39 @@ export class Label extends LabelBase {
753
758
754
759
fontSizeRatio = 1 ;
755
760
_lastAutoSizeKey : string ;
756
- textViewDidChange ( textView : UITextView , width ?, height ?, force = false ) {
761
+
762
+ updateAutoFontSize ( {
763
+ textView,
764
+ width,
765
+ height,
766
+ force = false ,
767
+ onlyMeasure = false
768
+ } : {
769
+ textView : UITextView ;
770
+ width ?;
771
+ height ?;
772
+ force ?: boolean ;
773
+ onlyMeasure ?: boolean ;
774
+ } ) {
775
+ let currentFont ;
757
776
if ( textView && this . autoFontSize ) {
758
777
if (
759
778
( ! textView . attributedText && ! textView . text ) ||
760
779
( width === undefined && height === undefined && CGSizeEqualToSize ( textView . bounds . size , CGSizeZero ) )
761
780
) {
762
- return ;
781
+ return currentFont ;
763
782
}
764
-
765
783
const textViewSize = textView . frame . size ;
766
784
const fixedWidth = Math . floor ( width !== undefined ? width : textViewSize . width ) ;
767
785
const fixedHeight = Math . floor ( height !== undefined ? height : textViewSize . height ) ;
768
786
if ( fixedWidth === 0 || fixedHeight === 0 ) {
769
- return ;
787
+ return currentFont ;
770
788
}
771
789
const autoSizeKey = fixedWidth + '_' + fixedHeight ;
772
790
if ( ! force && autoSizeKey === this . _lastAutoSizeKey ) {
773
- return ;
791
+ return null ;
774
792
}
793
+ currentFont = textView . font ;
775
794
this . _lastAutoSizeKey = autoSizeKey ;
776
795
const nbLines = textView . textContainer . maximumNumberOfLines ;
777
796
// we need to reset verticalTextAlignment or computation will be wrong
@@ -839,14 +858,21 @@ export class Label extends LabelBase {
839
858
}
840
859
}
841
860
}
842
- this . fontSizeRatio = expectFont . pointSize / fontSize ;
861
+ if ( ! onlyMeasure ) {
862
+ this . fontSizeRatio = expectFont . pointSize / fontSize ;
863
+ }
864
+
843
865
this . updateTextContainerInset ( ) ;
844
866
}
867
+ return currentFont ;
868
+ }
869
+ textViewDidChange ( textView : UITextView ) {
870
+ this . updateAutoFontSize ( { textView, force : true } ) ;
845
871
}
846
872
[ autoFontSizeProperty . setNative ] ( value : boolean ) {
847
873
if ( value ) {
848
874
if ( this . isLayoutValid && ( this . text || this . html || this . formattedText ) ) {
849
- this . textViewDidChange ( this . nativeTextViewProtected , undefined , undefined , true ) ;
875
+ this . updateAutoFontSize ( { textView : this . nativeTextViewProtected , force : true } ) ;
850
876
}
851
877
} else {
852
878
this [ fontInternalProperty . setNative ] ( this . style . fontInternal ) ;
0 commit comments