Skip to content

Commit

Permalink
Fix font size changing on hot reload
Browse files Browse the repository at this point in the history
  • Loading branch information
j-piasecki committed Apr 15, 2024
1 parent 7579c96 commit 7c2f944
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
private int mLinkifyMaskType;
private boolean mNotifyOnInlineViewLayout;
private boolean mTextIsSelectable;
private boolean mShouldAdjustSpannableFontSize;

private ReactViewBackgroundManager mReactBackgroundManager;
private Spannable mSpanned;
Expand Down Expand Up @@ -97,6 +98,7 @@ private void initView() {
mLinkifyMaskType = 0;
mNotifyOnInlineViewLayout = false;
mTextIsSelectable = false;
mShouldAdjustSpannableFontSize = false;
mEllipsizeLocation = TextUtils.TruncateAt.END;
mFontSize = Float.NaN;
mMinimumFontSize = Float.NaN;
Expand Down Expand Up @@ -363,10 +365,9 @@ public int compare(Object o1, Object o2) {
}

@Override
public void layout(int l, int t, int r, int b) {
super.layout(l, t, r, b);

if (this.mAdjustsFontSizeToFit && this.getSpanned() != null) {
protected void onDraw(Canvas canvas) {
if (this.mAdjustsFontSizeToFit && this.getSpanned() != null && mShouldAdjustSpannableFontSize) {
mShouldAdjustSpannableFontSize = false;
TextLayoutManagerMapBuffer.adjustSpannableFontToFit(
this.getSpanned(),
this.getWidth(),
Expand All @@ -382,6 +383,8 @@ public void layout(int l, int t, int r, int b) {
);
this.setText(this.getSpanned());
}

super.onDraw(canvas);
}

public void setText(ReactTextUpdate update) {
Expand Down Expand Up @@ -685,6 +688,7 @@ public void setBorderStyle(@Nullable String style) {

public void setSpanned(Spannable spanned) {
mSpanned = spanned;
mShouldAdjustSpannableFontSize = true;
}

public Spannable getSpanned() {
Expand Down

0 comments on commit 7c2f944

Please sign in to comment.