diff --git a/node_modules/react-native/ReactAndroid/api/ReactAndroid.api b/node_modules/react-native/ReactAndroid/api/ReactAndroid.api index f5b324d..6eb004e 100644 --- a/node_modules/react-native/ReactAndroid/api/ReactAndroid.api +++ b/node_modules/react-native/ReactAndroid/api/ReactAndroid.api @@ -7375,7 +7375,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 @@ -7560,7 +7560,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 deleteCachedSpannableForTag (I)V diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java index cb735fc..a7d73d8 100644 --- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java +++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java @@ -70,7 +70,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 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie mShouldAdjustSpannableFontSize = false; mEllipsizeLocation = TextUtils.TruncateAt.END; mFontSize = Float.NaN; - mMinimumFontSize = Float.NaN; + mMinimumFontScale = 0.f; mLetterSpacing = 0.f; mOverflow = Overflow.VISIBLE; mSpanned = null; @@ -374,7 +374,7 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie YogaMeasureMode.EXACTLY, getHeight(), YogaMeasureMode.EXACTLY, - mMinimumFontSize, + mMinimumFontScale, mNumberOfLines, getIncludeFontPadding(), getBreakStrategy(), @@ -640,8 +640,8 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie applyTextAttributes(); } - public void setMinimumFontSize(float minimumFontSize) { - mMinimumFontSize = minimumFontSize; + public void setMinimumFontScale(float minimumFontScale) { + mMinimumFontScale = minimumFontScale; mShouldAdjustSpannableFontSize = true; } diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java index 51955ac..4d9395a 100644 --- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java +++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java @@ -158,11 +158,11 @@ public class ReactTextViewManager 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/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index 3d420f8..84a9577 100644 --- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -84,8 +84,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; @@ -550,10 +549,10 @@ public class TextLayoutManager { int justificationMode = getTextJustificationMode(alignmentAttr); 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, @@ -561,7 +560,7 @@ public class TextLayoutManager { YogaMeasureMode.EXACTLY, height, YogaMeasureMode.UNDEFINED, - minimumFontSize, + minimumFontScale, maximumNumberOfLines, includeFontPadding, textBreakStrategy, @@ -590,7 +589,7 @@ public class TextLayoutManager { YogaMeasureMode widthYogaMeasureMode, float height, YogaMeasureMode heightYogaMeasureMode, - double minimumFontSizeAttr, + double minimumFontScaleAttr, int maximumNumberOfLines, boolean includeFontPadding, int textBreakStrategy, @@ -612,18 +611,15 @@ public class TextLayoutManager { justificationMode, paint); - // 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 diff --git a/node_modules/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp b/node_modules/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp index f2317ba..2365023 100644 --- a/node_modules/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp +++ b/node_modules/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp @@ -29,8 +29,7 @@ bool ParagraphAttributes::operator==(const ParagraphAttributes& rhs) const { rhs.adjustsFontSizeToFit, rhs.includeFontPadding, rhs.android_hyphenationFrequency) && - floatEquality(minimumFontSize, rhs.minimumFontSize) && - floatEquality(maximumFontSize, rhs.maximumFontSize); + floatEquality(minimumFontScale, rhs.minimumFontScale); } bool ParagraphAttributes::operator!=(const ParagraphAttributes& rhs) const { @@ -46,8 +45,7 @@ SharedDebugStringConvertibleList ParagraphAttributes::getDebugProps() const { debugStringConvertibleItem("ellipsizeMode", ellipsizeMode), debugStringConvertibleItem("textBreakStrategy", textBreakStrategy), debugStringConvertibleItem("adjustsFontSizeToFit", adjustsFontSizeToFit), - debugStringConvertibleItem("minimumFontSize", minimumFontSize), - debugStringConvertibleItem("maximumFontSize", maximumFontSize), + debugStringConvertibleItem("minimumFontScale", minimumFontScale), debugStringConvertibleItem("includeFontPadding", includeFontPadding), debugStringConvertibleItem( "android_hyphenationFrequency", android_hyphenationFrequency)}; diff --git a/node_modules/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h b/node_modules/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h index d73f863..7db6e69 100644 --- a/node_modules/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h +++ b/node_modules/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h @@ -64,11 +64,10 @@ class ParagraphAttributes : public DebugStringConvertible { HyphenationFrequency android_hyphenationFrequency{}; /* - * In case of font size adjustment enabled, defines minimum and maximum - * font sizes. + * Specifies smallest possible scale a font can reach when adjustsFontSizeToFit + * is enabled. (values 0.01-1.0). */ - Float minimumFontSize{std::numeric_limits::quiet_NaN()}; - Float maximumFontSize{std::numeric_limits::quiet_NaN()}; + Float minimumFontScale{0.0}; bool operator==(const ParagraphAttributes&) const; bool operator!=(const ParagraphAttributes&) const; @@ -93,8 +92,7 @@ struct hash { attributes.ellipsizeMode, attributes.textBreakStrategy, attributes.adjustsFontSizeToFit, - attributes.minimumFontSize, - attributes.maximumFontSize, + attributes.minimumFontScale, attributes.includeFontPadding, attributes.android_hyphenationFrequency); } diff --git a/node_modules/react-native/ReactCommon/react/renderer/attributedstring/conversions.h b/node_modules/react-native/ReactCommon/react/renderer/attributedstring/conversions.h index de53360..9aa4ba1 100644 --- a/node_modules/react-native/ReactCommon/react/renderer/attributedstring/conversions.h +++ b/node_modules/react-native/ReactCommon/react/renderer/attributedstring/conversions.h @@ -815,18 +815,12 @@ inline ParagraphAttributes convertRawProp( "adjustsFontSizeToFit", sourceParagraphAttributes.adjustsFontSizeToFit, defaultParagraphAttributes.adjustsFontSizeToFit); - paragraphAttributes.minimumFontSize = convertRawProp( + paragraphAttributes.minimumFontScale = convertRawProp( context, rawProps, - "minimumFontSize", - sourceParagraphAttributes.minimumFontSize, - defaultParagraphAttributes.minimumFontSize); - paragraphAttributes.maximumFontSize = convertRawProp( - context, - rawProps, - "maximumFontSize", - sourceParagraphAttributes.maximumFontSize, - defaultParagraphAttributes.maximumFontSize); + "minimumFontScale", + sourceParagraphAttributes.minimumFontScale, + defaultParagraphAttributes.minimumFontScale); paragraphAttributes.includeFontPadding = convertRawProp( context, rawProps, @@ -919,8 +913,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(); @@ -939,9 +932,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(); } diff --git a/node_modules/react-native/ReactCommon/react/renderer/components/text/ParagraphProps.cpp b/node_modules/react-native/ReactCommon/react/renderer/components/text/ParagraphProps.cpp index 12e1b97..c46ba64 100644 --- a/node_modules/react-native/ReactCommon/react/renderer/components/text/ParagraphProps.cpp +++ b/node_modules/react-native/ReactCommon/react/renderer/components/text/ParagraphProps.cpp @@ -100,14 +100,8 @@ void ParagraphProps::setProp( paDefaults, value, paragraphAttributes, - minimumFontSize, - "minimumFontSize"); - REBUILD_FIELD_SWITCH_CASE( - paDefaults, - value, - paragraphAttributes, - maximumFontSize, - "maximumFontSize"); + minimumFontScale, + "minimumFontScale"); REBUILD_FIELD_SWITCH_CASE( paDefaults, value, diff --git a/node_modules/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp b/node_modules/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp index 80cbdc5..21e3ba8 100644 --- a/node_modules/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp +++ b/node_modules/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp @@ -169,14 +169,8 @@ void BaseTextInputProps::setProp( paDefaults, value, paragraphAttributes, - minimumFontSize, - "minimumFontSize"); - REBUILD_FIELD_SWITCH_CASE( - paDefaults, - value, - paragraphAttributes, - maximumFontSize, - "maximumFontSize"); + minimumFontScale, + "minimumFontScale"); REBUILD_FIELD_SWITCH_CASE( paDefaults, value, diff --git a/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm b/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm index cc080f5..d45c030 100644 --- a/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm +++ b/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm @@ -228,6 +228,22 @@ - (LinesMeasurements)getLinesForAttributedString:(facebook::react::AttributedStr return paragraphLines; } +- (CGFloat)_maximumFontSizeInAttributedString:(NSAttributedString *)attributedString +{ + __block CGFloat maximumFontSize = 0.0; + [attributedString enumerateAttribute:NSFontAttributeName + inRange:NSMakeRange(0, attributedString.length) + options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired + usingBlock:^(id _Nullable value, NSRange range, BOOL *_Nonnull stop) { + CGFloat fontSize = ((UIFont *)value).pointSize; + if (fontSize > maximumFontSize) { + maximumFontSize = fontSize; + } + }]; + + return maximumFontSize; +} + - (NSTextStorage *)_textStorageAndLayoutManagerWithAttributesString:(NSAttributedString *)attributedString paragraphAttributes:(ParagraphAttributes)paragraphAttributes size:(CGSize)size @@ -251,8 +267,8 @@ - (NSTextStorage *)_textStorageAndLayoutManagerWithAttributesString:(NSAttribute [textStorage addLayoutManager:layoutManager]; if (paragraphAttributes.adjustsFontSizeToFit) { - CGFloat minimumFontSize = !isnan(paragraphAttributes.minimumFontSize) ? paragraphAttributes.minimumFontSize : 4.0; - CGFloat maximumFontSize = !isnan(paragraphAttributes.maximumFontSize) ? paragraphAttributes.maximumFontSize : 96.0; + CGFloat maximumFontSize = [self _maximumFontSizeInAttributedString:attributedString]; + CGFloat minimumFontSize = MAX(paragraphAttributes.minimumFontScale * maximumFontSize, 4.0); [textStorage scaleFontSizeToFitSize:size minimumFontSize:minimumFontSize maximumFontSize:maximumFontSize]; }