@@ -404,8 +404,8 @@ export class Label extends LabelBase {
404
404
if ( this . autoFontSize ) {
405
405
this . textViewDidChange (
406
406
nativeView ,
407
- Math . floor ( layout . toDeviceIndependentPixels ( width ) ) ,
408
- Math . floor ( layout . toDeviceIndependentPixels ( height ) )
407
+ layout . toDeviceIndependentPixels ( width ) ,
408
+ layout . toDeviceIndependentPixels ( height )
409
409
) ;
410
410
}
411
411
@@ -823,12 +823,16 @@ export class Label extends LabelBase {
823
823
) {
824
824
return ;
825
825
}
826
- const nbLines = textView . textContainer . maximumNumberOfLines ;
827
- // we need to reset verticalTextAlignment or computation will be wrong
828
- this . updateTextContainerInset ( false ) ;
826
+
829
827
const textViewSize = textView . frame . size ;
830
828
const fixedWidth = width || textViewSize . width ;
831
829
const fixedHeight = height || textViewSize . height ;
830
+ if ( fixedWidth === 0 && fixedHeight === 0 ) {
831
+ return ;
832
+ }
833
+ const nbLines = textView . textContainer . maximumNumberOfLines ;
834
+ // we need to reset verticalTextAlignment or computation will be wrong
835
+ this . updateTextContainerInset ( false ) ;
832
836
833
837
const fontSize = this . style . fontSize || 17 ;
834
838
let expectFont : UIFont = ( this . style . fontInternal || Font . default ) . getUIFont ( UIFont . systemFontOfSize ( fontSize ) ) ;
@@ -843,15 +847,15 @@ export class Label extends LabelBase {
843
847
}
844
848
} ;
845
849
size ( ) ;
846
- if ( expectSize . height > textViewSize . height || expectSize . width > textViewSize . width ) {
850
+ if ( expectSize . height > fixedHeight || expectSize . width > fixedWidth ) {
847
851
while (
848
- ( expectSize . height > textViewSize . height || expectSize . width > textViewSize . width ) &&
852
+ ( expectSize . height > fixedHeight || expectSize . width > fixedWidth ) &&
849
853
expectFont . pointSize > ( this . minFontSize || 12 )
850
854
) {
851
855
const newFont = expectFont . fontWithSize ( expectFont . pointSize - 1 ) ;
852
856
textView . font = newFont ;
853
857
size ( ) ;
854
- if ( expectSize . height >= textViewSize . height || expectSize . width >= textViewSize . width ) {
858
+ if ( expectSize . height >= fixedHeight || expectSize . width >= fixedWidth ) {
855
859
expectFont = newFont ;
856
860
} else {
857
861
textView . font = newFont ;
@@ -860,14 +864,14 @@ export class Label extends LabelBase {
860
864
}
861
865
} else {
862
866
while (
863
- ( expectSize . height < textViewSize . height || expectSize . width < textViewSize . width ) &&
867
+ ( expectSize . height < fixedHeight || expectSize . width < fixedWidth ) &&
864
868
expectFont . pointSize < ( this . maxFontSize || 200 )
865
869
) {
866
870
const newFont = expectFont . fontWithSize ( expectFont . pointSize + 1 ) ;
867
871
textView . font = newFont ;
868
872
size ( ) ;
869
873
870
- if ( expectSize . height <= textViewSize . height || expectSize . width <= textViewSize . width ) {
874
+ if ( expectSize . height <= fixedHeight || expectSize . width <= fixedWidth ) {
871
875
expectFont = newFont ;
872
876
} else {
873
877
textView . font = newFont ;
@@ -878,16 +882,6 @@ export class Label extends LabelBase {
878
882
this . updateTextContainerInset ( ) ;
879
883
}
880
884
}
881
- _onSizeChanged ( ) : void {
882
- const nativeView = this . nativeViewProtected ;
883
- if ( ! nativeView ) {
884
- return ;
885
- }
886
- super . _onSizeChanged ( ) ;
887
- if ( this . autoFontSize ) {
888
- this . textViewDidChange ( nativeView ) ;
889
- }
890
- }
891
885
[ autoFontSizeProperty . setNative ] ( value : boolean ) {
892
886
if ( value && this . text ) {
893
887
this . textViewDidChange ( this . nativeTextViewProtected ) ;
0 commit comments