Skip to content

Commit b1cdfd7

Browse files
author
farfromrefug
committed
fix(android): prevent enableAutoSize to be called before min and max font size are set
1 parent 6de8016 commit b1cdfd7

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

Diff for: src/label.android.ts

+29-10
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,14 @@ abstract class LabelBase extends View implements LabelViewDefinition {
127127
@cssProperty paddingLeft: CoreTypes.LengthType;
128128

129129
// for now code is duplicated as Android version is a full rewrite
130-
mCanChangeText = true;
130+
mInResumeNativeUpdates = false;
131131
mNeedSetText = false;
132+
mNeedSetAutoSize = false;
132133
public onResumeNativeUpdates(): void {
133134
// {N} suspends properties update on `_suspendNativeUpdates`. So we only need to do this in onResumeNativeUpdates
134-
this.mCanChangeText = false;
135+
this.mInResumeNativeUpdates = true;
135136
super.onResumeNativeUpdates();
136-
this.mCanChangeText = true;
137+
this.mInResumeNativeUpdates = false;
137138
if (this.mNeedSetText) {
138139
this.mNeedSetText = false;
139140
this._setNativeText();
@@ -355,21 +356,39 @@ export class Label extends LabelBase {
355356
Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0)
356357
);
357358
}
358-
[maxFontSizeProperty.setNative](value) {
359-
if (this.mAutoFontSize) {
360-
this.enableAutoSize();
359+
360+
// for now code is duplicated as Android version is a full rewrite
361+
mNeedSetAutoSize = false;
362+
public onResumeNativeUpdates(): void {
363+
super.onResumeNativeUpdates();
364+
if (this.mNeedSetAutoSize) {
365+
this.mNeedSetAutoSize = false;
366+
if (this.autoFontSize) {
367+
this.enableAutoSize();
368+
} else {
369+
this.disableAutoSize();
370+
}
361371
}
362372
}
373+
[maxFontSizeProperty.setNative](value) {
374+
this.enableAutoSize();
375+
}
363376
[minFontSizeProperty.setNative](value) {
364-
if (this.mAutoFontSize) {
365-
this.enableAutoSize();
366-
}
377+
this.enableAutoSize();
367378
}
368379

369380
protected enableAutoSize() {
381+
if (this.mInResumeNativeUpdates) {
382+
this.mNeedSetAutoSize = true;
383+
return;
384+
}
370385
this.nativeViewProtected.enableAutoSize(this.minFontSize || 10, this.maxFontSize || 200, this.autoFontSizeStep || 1);
371386
}
372387
protected disableAutoSize() {
388+
if (this.mInResumeNativeUpdates) {
389+
this.mNeedSetAutoSize = true;
390+
return;
391+
}
373392
this.nativeViewProtected.disableAutoSize();
374393
}
375394
[autoFontSizeProperty.setNative](value: boolean) {
@@ -434,7 +453,7 @@ export class Label extends LabelBase {
434453

435454
@profile
436455
_setNativeText(reset: boolean = false): void {
437-
if (!this.mCanChangeText) {
456+
if (this.mInResumeNativeUpdates) {
438457
this.mNeedSetText = true;
439458
return;
440459
}

0 commit comments

Comments
 (0)