Skip to content

Commit 0b3a811

Browse files
generatedunixname89002005232357huntie
authored andcommitted
Revert D49509633: Multisect successfully blamed "D49509633: [react-native][PR] fix: Text cut off issues when adjusting text size and font weight in system settings" for test or build failures
Summary: This diff is reverting D49509633 D49509633: [react-native][PR] fix: Text cut off issues when adjusting text size and font weight in system settings by ryancat has been identified to be causing the following test or build failures: Tests affected: - [xplat/endtoend/jest-e2e/apps/facebook_xplat/ReactNativeTTRCTester/__tests__/ReactNativeTTRCTester-errorReportedManually-android-e2e.js](https://www.internalfb.com/intern/test/281475019301157/) Here's the Multisect link: https://www.internalfb.com/multisect/3131615 Here are the tasks that are relevant to this breakage: We're generating a revert to back out the changes in this diff, please note the backout may land if someone accepts it. If you believe this diff has been generated in error you may Commandeer and Abandon it. Reviewed By: NickGerleman Differential Revision: D49645585 fbshipit-source-id: 414531e067cffa109d0663d6af185dcaf8fb9c4e
1 parent d2517af commit 0b3a811

File tree

2 files changed

+33
-48
lines changed

2 files changed

+33
-48
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextAnchorViewManager.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,6 @@ public void setAdjustFontSizeToFit(ReactTextView view, boolean adjustsFontSizeTo
7575
view.setAdjustFontSizeToFit(adjustsFontSizeToFit);
7676
}
7777

78-
@ReactProp(name = ViewProps.ALLOW_FONT_SCALING, defaultBoolean = true)
79-
public void setAllowFontScaling(ReactTextView view, boolean allowFontScaling) {
80-
view.setAllowFontScaling(allowFontScaling);
81-
}
82-
83-
@ReactProp(name = ViewProps.MAX_FONT_SIZE_MULTIPLIER, defaultFloat = Float.NaN)
84-
public void setMaxFontSizeMultiplier(ReactTextView view, float maxFontSizeMultiplier) {
85-
view.setMaxFontSizeMultiplier(maxFontSizeMultiplier);
86-
}
87-
8878
@ReactProp(name = ViewProps.FONT_SIZE)
8979
public void setFontSize(ReactTextView view, float fontSize) {
9080
view.setFontSize(fontSize);

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,15 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
5858
private int mNumberOfLines;
5959
private TextUtils.TruncateAt mEllipsizeLocation;
6060
private boolean mAdjustsFontSizeToFit;
61+
private float mFontSize = Float.NaN;
62+
private float mLetterSpacing = Float.NaN;
6163
private int mLinkifyMaskType;
6264
private boolean mNotifyOnInlineViewLayout;
6365
private boolean mTextIsSelectable;
6466

6567
private ReactViewBackgroundManager mReactBackgroundManager;
6668
private Spannable mSpanned;
6769

68-
/**
69-
* Used to collect some text size affecting attributes to fix some text cut-off issues when users
70-
* adjust text size and font weight to the max value in system font settings.
71-
*/
72-
private TextAttributes mTextAttributes;
73-
7470
public ReactTextView(Context context) {
7571
super(context);
7672

@@ -102,7 +98,6 @@ private void initView() {
10298
mEllipsizeLocation = TextUtils.TruncateAt.END;
10399

104100
mSpanned = null;
105-
mTextAttributes = new TextAttributes();
106101
}
107102

108103
/* package */ void recycleView() {
@@ -592,6 +587,29 @@ public void setAdjustFontSizeToFit(boolean adjustsFontSizeToFit) {
592587
mAdjustsFontSizeToFit = adjustsFontSizeToFit;
593588
}
594589

590+
public void setFontSize(float fontSize) {
591+
mFontSize =
592+
mAdjustsFontSizeToFit
593+
? (float) Math.ceil(PixelUtil.toPixelFromSP(fontSize))
594+
: (float) Math.ceil(PixelUtil.toPixelFromDIP(fontSize));
595+
596+
applyTextAttributes();
597+
}
598+
599+
public void setLetterSpacing(float letterSpacing) {
600+
if (Float.isNaN(letterSpacing)) {
601+
return;
602+
}
603+
604+
float letterSpacingPixels = PixelUtil.toPixelFromDIP(letterSpacing);
605+
606+
// `letterSpacingPixels` and `getEffectiveFontSize` are both in pixels,
607+
// yielding an accurate em value.
608+
mLetterSpacing = letterSpacingPixels / mFontSize;
609+
610+
applyTextAttributes();
611+
}
612+
595613
public void setEllipsizeLocation(TextUtils.TruncateAt ellipsizeLocation) {
596614
mEllipsizeLocation = ellipsizeLocation;
597615
}
@@ -607,8 +625,6 @@ public void updateView() {
607625
? null
608626
: mEllipsizeLocation;
609627
setEllipsize(ellipsizeLocation);
610-
611-
applyTextAttributes();
612628
}
613629

614630
@Override
@@ -664,37 +680,16 @@ protected boolean dispatchHoverEvent(MotionEvent event) {
664680
return super.dispatchHoverEvent(event);
665681
}
666682

667-
public void setLetterSpacing(float letterSpacing) {
668-
mTextAttributes.setLetterSpacing(letterSpacing);
669-
}
670-
671-
public void setAllowFontScaling(boolean allowFontScaling) {
672-
if (mTextAttributes.getAllowFontScaling() != allowFontScaling) {
673-
mTextAttributes.setAllowFontScaling(allowFontScaling);
674-
}
675-
}
676-
677-
public void setFontSize(float fontSize) {
678-
mTextAttributes.setFontSize(fontSize);
679-
}
680-
681-
public void setMaxFontSizeMultiplier(float maxFontSizeMultiplier) {
682-
if (maxFontSizeMultiplier != mTextAttributes.getMaxFontSizeMultiplier()) {
683-
mTextAttributes.setMaxFontSizeMultiplier(maxFontSizeMultiplier);
684-
}
685-
}
686-
687683
private void applyTextAttributes() {
688-
// In general, the `getEffective*` functions return `Float.NaN` if the
689-
// property hasn't been set.
690-
691-
// `getEffectiveFontSize` always returns a value so don't need to check for anything like
692-
// `Float.NaN`.
693-
setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextAttributes.getEffectiveFontSize());
684+
// Workaround for an issue where text can be cut off with an ellipsis when
685+
// using certain font sizes and padding. Sets the provided text size and
686+
// letter spacing to ensure consistent rendering and prevent cut-off.
687+
if (!Float.isNaN(mFontSize)) {
688+
setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
689+
}
694690

695-
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
696-
if (!Float.isNaN(effectiveLetterSpacing)) {
697-
super.setLetterSpacing(effectiveLetterSpacing);
691+
if (!Float.isNaN(mLetterSpacing)) {
692+
super.setLetterSpacing(mLetterSpacing);
698693
}
699694
}
700695
}

0 commit comments

Comments
 (0)