Skip to content

Commit

Permalink
Fix letter-spacing not being cleared when reusing ReactTextView (#42258)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #42258

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D52693975

fbshipit-source-id: b26d8350068eda25c78fbd05d71452395e79fc2d
  • Loading branch information
javache authored and facebook-github-bot committed Jan 12, 2024
1 parent 9bd357e commit 0dd27f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public void setLineHeight(float lineHeight) {
markUpdated();
}

@ReactProp(name = ViewProps.LETTER_SPACING, defaultFloat = Float.NaN)
@ReactProp(name = ViewProps.LETTER_SPACING, defaultFloat = 0.f)
public void setLetterSpacing(float letterSpacing) {
mTextAttributes.setLetterSpacing(letterSpacing);
markUpdated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void setFontSize(ReactTextView view, float fontSize) {
view.setFontSize(fontSize);
}

@ReactProp(name = ViewProps.LETTER_SPACING, defaultFloat = Float.NaN)
@ReactProp(name = ViewProps.LETTER_SPACING, defaultFloat = 0.f)
public void setLetterSpacing(ReactTextView view, float letterSpacing) {
view.setLetterSpacing(letterSpacing);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
private static final ViewGroup.LayoutParams EMPTY_LAYOUT_PARAMS =
new ViewGroup.LayoutParams(0, 0);

// https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/widget/TextView.java#L854
private static final int DEFAULT_GRAVITY = Gravity.TOP | Gravity.START;

private boolean mContainsImages;
private final int mDefaultGravityHorizontal;
private final int mDefaultGravityVertical;
private int mNumberOfLines;
private TextUtils.TruncateAt mEllipsizeLocation;
private boolean mAdjustsFontSizeToFit;
private float mFontSize = Float.NaN;
private float mLetterSpacing = Float.NaN;
private float mFontSize;
private float mLetterSpacing;
private int mLinkifyMaskType;
private boolean mNotifyOnInlineViewLayout;
private boolean mTextIsSelectable;
Expand All @@ -69,11 +70,6 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie

public ReactTextView(Context context) {
super(context);

// Get these defaults only during the constructor - these should never be set otherwise
mDefaultGravityHorizontal = getGravityHorizontal();
mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;

initView();
}

Expand All @@ -96,6 +92,8 @@ private void initView() {
mNotifyOnInlineViewLayout = false;
mTextIsSelectable = false;
mEllipsizeLocation = TextUtils.TruncateAt.END;
mFontSize = Float.NaN;
mLetterSpacing = 0.f;

mSpanned = null;
}
Expand All @@ -115,10 +113,10 @@ private void initView() {
// reset text
setLayoutParams(EMPTY_LAYOUT_PARAMS);
super.setText(null);
applyTextAttributes();

// Call setters to ensure that any super setters are called
setGravityHorizontal(mDefaultGravityHorizontal);
setGravityVertical(mDefaultGravityVertical);
setGravity(DEFAULT_GRAVITY);
setNumberOfLines(mNumberOfLines);
setAdjustFontSizeToFit(mAdjustsFontSizeToFit);
setLinkifyMask(mLinkifyMaskType);
Expand Down Expand Up @@ -555,7 +553,9 @@ public boolean hasOverlappingRendering() {

/* package */ void setGravityHorizontal(int gravityHorizontal) {
if (gravityHorizontal == 0) {
gravityHorizontal = mDefaultGravityHorizontal;
gravityHorizontal =
DEFAULT_GRAVITY
& (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK);
}
setGravity(
(getGravity()
Expand All @@ -566,7 +566,7 @@ public boolean hasOverlappingRendering() {

/* package */ void setGravityVertical(int gravityVertical) {
if (gravityVertical == 0) {
gravityVertical = mDefaultGravityVertical;
gravityVertical = DEFAULT_GRAVITY & Gravity.VERTICAL_GRAVITY_MASK;
}
setGravity((getGravity() & ~Gravity.VERTICAL_GRAVITY_MASK) | gravityVertical);
}
Expand Down

0 comments on commit 0dd27f2

Please sign in to comment.