mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
-10
@@ -75,16 +75,6 @@ public abstract class ReactTextAnchorViewManager<T extends View, C extends React
|
||||
view.setAdjustFontSizeToFit(adjustsFontSizeToFit);
|
||||
}
|
||||
|
||||
@ReactProp(name = ViewProps.ALLOW_FONT_SCALING, defaultBoolean = true)
|
||||
public void setAllowFontScaling(ReactTextView view, boolean allowFontScaling) {
|
||||
view.setAllowFontScaling(allowFontScaling);
|
||||
}
|
||||
|
||||
@ReactProp(name = ViewProps.MAX_FONT_SIZE_MULTIPLIER, defaultFloat = Float.NaN)
|
||||
public void setMaxFontSizeMultiplier(ReactTextView view, float maxFontSizeMultiplier) {
|
||||
view.setMaxFontSizeMultiplier(maxFontSizeMultiplier);
|
||||
}
|
||||
|
||||
@ReactProp(name = ViewProps.FONT_SIZE)
|
||||
public void setFontSize(ReactTextView view, float fontSize) {
|
||||
view.setFontSize(fontSize);
|
||||
|
||||
+33
-38
@@ -58,6 +58,8 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
private int mNumberOfLines;
|
||||
private TextUtils.TruncateAt mEllipsizeLocation;
|
||||
private boolean mAdjustsFontSizeToFit;
|
||||
private float mFontSize = Float.NaN;
|
||||
private float mLetterSpacing = Float.NaN;
|
||||
private int mLinkifyMaskType;
|
||||
private boolean mNotifyOnInlineViewLayout;
|
||||
private boolean mTextIsSelectable;
|
||||
@@ -65,12 +67,6 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
private ReactViewBackgroundManager mReactBackgroundManager;
|
||||
private Spannable mSpanned;
|
||||
|
||||
/**
|
||||
* Used to collect some text size affecting attributes to fix some text cut-off issues when users
|
||||
* adjust text size and font weight to the max value in system font settings.
|
||||
*/
|
||||
private TextAttributes mTextAttributes;
|
||||
|
||||
public ReactTextView(Context context) {
|
||||
super(context);
|
||||
|
||||
@@ -102,7 +98,6 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
mEllipsizeLocation = TextUtils.TruncateAt.END;
|
||||
|
||||
mSpanned = null;
|
||||
mTextAttributes = new TextAttributes();
|
||||
}
|
||||
|
||||
/* package */ void recycleView() {
|
||||
@@ -592,6 +587,29 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
mAdjustsFontSizeToFit = adjustsFontSizeToFit;
|
||||
}
|
||||
|
||||
public void setFontSize(float fontSize) {
|
||||
mFontSize =
|
||||
mAdjustsFontSizeToFit
|
||||
? (float) Math.ceil(PixelUtil.toPixelFromSP(fontSize))
|
||||
: (float) Math.ceil(PixelUtil.toPixelFromDIP(fontSize));
|
||||
|
||||
applyTextAttributes();
|
||||
}
|
||||
|
||||
public void setLetterSpacing(float letterSpacing) {
|
||||
if (Float.isNaN(letterSpacing)) {
|
||||
return;
|
||||
}
|
||||
|
||||
float letterSpacingPixels = PixelUtil.toPixelFromDIP(letterSpacing);
|
||||
|
||||
// `letterSpacingPixels` and `getEffectiveFontSize` are both in pixels,
|
||||
// yielding an accurate em value.
|
||||
mLetterSpacing = letterSpacingPixels / mFontSize;
|
||||
|
||||
applyTextAttributes();
|
||||
}
|
||||
|
||||
public void setEllipsizeLocation(TextUtils.TruncateAt ellipsizeLocation) {
|
||||
mEllipsizeLocation = ellipsizeLocation;
|
||||
}
|
||||
@@ -607,8 +625,6 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
? null
|
||||
: mEllipsizeLocation;
|
||||
setEllipsize(ellipsizeLocation);
|
||||
|
||||
applyTextAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -664,37 +680,16 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
return super.dispatchHoverEvent(event);
|
||||
}
|
||||
|
||||
public void setLetterSpacing(float letterSpacing) {
|
||||
mTextAttributes.setLetterSpacing(letterSpacing);
|
||||
}
|
||||
|
||||
public void setAllowFontScaling(boolean allowFontScaling) {
|
||||
if (mTextAttributes.getAllowFontScaling() != allowFontScaling) {
|
||||
mTextAttributes.setAllowFontScaling(allowFontScaling);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFontSize(float fontSize) {
|
||||
mTextAttributes.setFontSize(fontSize);
|
||||
}
|
||||
|
||||
public void setMaxFontSizeMultiplier(float maxFontSizeMultiplier) {
|
||||
if (maxFontSizeMultiplier != mTextAttributes.getMaxFontSizeMultiplier()) {
|
||||
mTextAttributes.setMaxFontSizeMultiplier(maxFontSizeMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyTextAttributes() {
|
||||
// In general, the `getEffective*` functions return `Float.NaN` if the
|
||||
// property hasn't been set.
|
||||
// Workaround for an issue where text can be cut off with an ellipsis when
|
||||
// using certain font sizes and padding. Sets the provided text size and
|
||||
// letter spacing to ensure consistent rendering and prevent cut-off.
|
||||
if (!Float.isNaN(mFontSize)) {
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, mFontSize);
|
||||
}
|
||||
|
||||
// `getEffectiveFontSize` always returns a value so don't need to check for anything like
|
||||
// `Float.NaN`.
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextAttributes.getEffectiveFontSize());
|
||||
|
||||
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
|
||||
if (!Float.isNaN(effectiveLetterSpacing)) {
|
||||
super.setLetterSpacing(effectiveLetterSpacing);
|
||||
if (!Float.isNaN(mLetterSpacing)) {
|
||||
super.setLetterSpacing(mLetterSpacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user