Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix letter-spacing not being cleared when reusing ReactTextView #42258

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading