diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index cad0f20e2ba377..a17e7cbd46e7c4 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7390,7 +7390,7 @@ public class com/facebook/react/views/text/ReactTextView : androidx/appcompat/wi public fun setIncludeFontPadding (Z)V public fun setLetterSpacing (F)V public fun setLinkifyMask (I)V - public fun setMinimumFontSize (F)V + public fun setMinimumFontScale (F)V public fun setNotifyOnInlineViewLayout (Z)V public fun setNumberOfLines (I)V public fun setOverflow (Ljava/lang/String;)V @@ -7606,7 +7606,7 @@ public class com/facebook/react/views/text/TextLayoutManager { public static final field PA_KEY_INCLUDE_FONT_PADDING S public static final field PA_KEY_MAXIMUM_FONT_SIZE S public static final field PA_KEY_MAX_NUMBER_OF_LINES S - public static final field PA_KEY_MINIMUM_FONT_SIZE S + public static final field PA_KEY_MINIMUM_FONT_SCALE S public static final field PA_KEY_TEXT_BREAK_STRATEGY S public fun ()V public static fun adjustSpannableFontToFit (Landroid/text/Spannable;FLcom/facebook/yoga/YogaMeasureMode;FLcom/facebook/yoga/YogaMeasureMode;DIZIILandroid/text/Layout$Alignment;)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java index 424160192fc16b..8727f4d1f96c09 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java @@ -63,7 +63,7 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie private TextUtils.TruncateAt mEllipsizeLocation; private boolean mAdjustsFontSizeToFit; private float mFontSize; - private float mMinimumFontSize; + private float mMinimumFontScale; private float mLetterSpacing; private int mLinkifyMaskType; private boolean mNotifyOnInlineViewLayout; @@ -99,7 +99,7 @@ private void initView() { mShouldAdjustSpannableFontSize = false; mEllipsizeLocation = TextUtils.TruncateAt.END; mFontSize = Float.NaN; - mMinimumFontSize = Float.NaN; + mMinimumFontScale = 0.f; mLetterSpacing = 0.f; mSpanned = null; @@ -371,7 +371,7 @@ protected void onDraw(Canvas canvas) { YogaMeasureMode.EXACTLY, getHeight(), YogaMeasureMode.EXACTLY, - mMinimumFontSize, + mMinimumFontScale, mNumberOfLines, getIncludeFontPadding(), getBreakStrategy(), @@ -623,8 +623,8 @@ public void setFontSize(float fontSize) { applyTextAttributes(); } - public void setMinimumFontSize(float minimumFontSize) { - mMinimumFontSize = minimumFontSize; + public void setMinimumFontScale(float minimumFontScale) { + mMinimumFontScale = minimumFontScale; mShouldAdjustSpannableFontSize = true; } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java index 8ca3155b31a674..edcf05043bb1a4 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java @@ -154,11 +154,11 @@ private Object getReactTextUpdate(ReactTextView view, ReactStylesDiffMap props, view.setSpanned(spanned); try { - float minimumFontSize = - (float) paragraphAttributes.getDouble(TextLayoutManager.PA_KEY_MINIMUM_FONT_SIZE); - view.setMinimumFontSize(minimumFontSize); + float minimumFontScale = + (float) paragraphAttributes.getDouble(TextLayoutManager.PA_KEY_MINIMUM_FONT_SCALE); + view.setMinimumFontScale(minimumFontScale); } catch (IllegalArgumentException e) { - // T190482857: We see rare crash with MapBuffer without PA_KEY_MINIMUM_FONT_SIZE entry + // T190482857: We see rare crash with MapBuffer without PA_KEY_MINIMUM_FONT_SCALE entry FLog.e( TAG, "Paragraph Attributes: %s", diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index 2921f84140d1d4..2ee409e02b1fbb 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -77,8 +77,7 @@ public class TextLayoutManager { public static final short PA_KEY_ADJUST_FONT_SIZE_TO_FIT = 3; public static final short PA_KEY_INCLUDE_FONT_PADDING = 4; public static final short PA_KEY_HYPHENATION_FREQUENCY = 5; - public static final short PA_KEY_MINIMUM_FONT_SIZE = 6; - public static final short PA_KEY_MAXIMUM_FONT_SIZE = 7; + public static final short PA_KEY_MINIMUM_FONT_SCALE = 6; private static final boolean ENABLE_MEASURE_LOGGING = ReactBuildConfig.DEBUG && false; @@ -428,7 +427,7 @@ public static void adjustSpannableFontToFit( YogaMeasureMode widthYogaMeasureMode, float height, YogaMeasureMode heightYogaMeasureMode, - double minimumFontSizeAttr, + double minimumFontScaleAttr, int maximumNumberOfLines, boolean includeFontPadding, int textBreakStrategy, @@ -446,18 +445,15 @@ public static void adjustSpannableFontToFit( hyphenationFrequency, alignment); - // Minimum font size is 4pts to match the iOS implementation. - int minimumFontSize = - (int) - (Double.isNaN(minimumFontSizeAttr) ? PixelUtil.toPixelFromDIP(4) : minimumFontSizeAttr); - - // Find the largest font size used in the spannable to use as a starting point. - int currentFontSize = minimumFontSize; + // Find the largest font size used in the spanable to use as a starting point. + int currentFontSize = 0; ReactAbsoluteSizeSpan[] spans = text.getSpans(0, text.length(), ReactAbsoluteSizeSpan.class); for (ReactAbsoluteSizeSpan span : spans) { currentFontSize = Math.max(currentFontSize, span.getSize()); } + // Minimum font size is 4pts to match the iOS implementation. + int minimumFontSize = (int) Math.max(minimumFontScaleAttr * currentFontSize, PixelUtil.toPixelFromDIP(4)); int initialFontSize = currentFontSize; while (currentFontSize > minimumFontSize && ((maximumNumberOfLines != ReactConstants.UNSET @@ -534,10 +530,10 @@ public static long measureText( Layout.Alignment alignment = getTextAlignment(attributedString, text); if (adjustFontSizeToFit) { - double minimumFontSize = - paragraphAttributes.contains(PA_KEY_MINIMUM_FONT_SIZE) - ? paragraphAttributes.getDouble(PA_KEY_MINIMUM_FONT_SIZE) - : Double.NaN; + double minimumFontScale = + paragraphAttributes.contains(PA_KEY_MINIMUM_FONT_SCALE) + ? paragraphAttributes.getDouble(PA_KEY_MINIMUM_FONT_SCALE) + : 0.0; adjustSpannableFontToFit( text, @@ -545,7 +541,7 @@ public static long measureText( widthYogaMeasureMode, height, heightYogaMeasureMode, - minimumFontSize, + minimumFontScale, maximumNumberOfLines, includeFontPadding, textBreakStrategy, @@ -743,10 +739,10 @@ public static WritableArray measureLines( Layout.Alignment alignment = getTextAlignment(attributedString, text); if (adjustFontSizeToFit) { - double minimumFontSize = - paragraphAttributes.contains(PA_KEY_MINIMUM_FONT_SIZE) - ? paragraphAttributes.getDouble(PA_KEY_MINIMUM_FONT_SIZE) - : Double.NaN; + double minimumFontScale = + paragraphAttributes.contains(PA_KEY_MINIMUM_FONT_SCALE) + ? paragraphAttributes.getDouble(PA_KEY_MINIMUM_FONT_SCALE) + : 0.0; adjustSpannableFontToFit( text, @@ -754,7 +750,7 @@ public static WritableArray measureLines( YogaMeasureMode.EXACTLY, height, YogaMeasureMode.UNDEFINED, - minimumFontSize, + minimumFontScale, maximumNumberOfLines, includeFontPadding, textBreakStrategy, diff --git a/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h b/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h index 61f21f52dbd107..52e2e9609f3118 100644 --- a/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h +++ b/packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h @@ -858,8 +858,7 @@ constexpr static MapBuffer::Key PA_KEY_TEXT_BREAK_STRATEGY = 2; constexpr static MapBuffer::Key PA_KEY_ADJUST_FONT_SIZE_TO_FIT = 3; constexpr static MapBuffer::Key PA_KEY_INCLUDE_FONT_PADDING = 4; constexpr static MapBuffer::Key PA_KEY_HYPHENATION_FREQUENCY = 5; -constexpr static MapBuffer::Key PA_KEY_MINIMUM_FONT_SIZE = 6; -constexpr static MapBuffer::Key PA_KEY_MAXIMUM_FONT_SIZE = 7; +constexpr static MapBuffer::Key PA_KEY_MINIMUM_FONT_SCALE = 6; inline MapBuffer toMapBuffer(const ParagraphAttributes& paragraphAttributes) { auto builder = MapBufferBuilder(); @@ -878,9 +877,7 @@ inline MapBuffer toMapBuffer(const ParagraphAttributes& paragraphAttributes) { PA_KEY_HYPHENATION_FREQUENCY, toString(paragraphAttributes.android_hyphenationFrequency)); builder.putDouble( - PA_KEY_MINIMUM_FONT_SIZE, paragraphAttributes.minimumFontSize); - builder.putDouble( - PA_KEY_MAXIMUM_FONT_SIZE, paragraphAttributes.maximumFontSize); + PA_KEY_MINIMUM_FONT_SCALE, paragraphAttributes.minimumFontScale); return builder.build(); }