Skip to content
Open
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 @@ -31,8 +31,6 @@ bool ParagraphAttributes::operator==(const ParagraphAttributes& rhs) const {
rhs.includeFontPadding,
rhs.android_hyphenationFrequency,
rhs.textAlignVertical) &&
floatEquality(minimumFontSize, rhs.minimumFontSize) &&
floatEquality(maximumFontSize, rhs.maximumFontSize) &&
floatEquality(minimumFontScale, rhs.minimumFontScale);
}

Expand Down Expand Up @@ -61,13 +59,9 @@ SharedDebugStringConvertibleList ParagraphAttributes::getDebugProps() const {
adjustsFontSizeToFit,
paragraphAttributes.adjustsFontSizeToFit),
debugStringConvertibleItem(
"minimumFontSize",
minimumFontSize,
paragraphAttributes.minimumFontSize),
debugStringConvertibleItem(
"maximumFontSize",
maximumFontSize,
paragraphAttributes.maximumFontSize),
"minimumFontScale",
minimumFontScale,
paragraphAttributes.minimumFontScale),
debugStringConvertibleItem(
"includeFontPadding",
includeFontPadding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,11 @@ class ParagraphAttributes : public DebugStringConvertible {
*/
HyphenationFrequency android_hyphenationFrequency{};

/*
* In case of font size adjustment enabled, defines minimum and maximum
* font sizes.
*/
Float minimumFontSize{std::numeric_limits<Float>::quiet_NaN()};
Float maximumFontSize{std::numeric_limits<Float>::quiet_NaN()};

/*
* Specifies the smallest possible scale a font can reach when
* adjustsFontSizeToFit is enabled. (values 0.01-1.0).
*/
Float minimumFontScale{std::numeric_limits<Float>::quiet_NaN()};
Float minimumFontScale{0.0};

/*
* The vertical alignment of the text, causing the glyphs to be vertically
Expand Down Expand Up @@ -105,8 +98,7 @@ struct hash<facebook::react::ParagraphAttributes> {
attributes.ellipsizeMode,
attributes.textBreakStrategy,
attributes.adjustsFontSizeToFit,
attributes.minimumFontSize,
attributes.maximumFontSize,
attributes.minimumFontScale,
attributes.includeFontPadding,
attributes.android_hyphenationFrequency,
attributes.minimumFontScale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -952,18 +952,6 @@ inline ParagraphAttributes convertRawProp(
"minimumFontScale",
sourceParagraphAttributes.minimumFontScale,
defaultParagraphAttributes.minimumFontScale);
paragraphAttributes.minimumFontSize = convertRawProp(
context,
rawProps,
"minimumFontSize",
sourceParagraphAttributes.minimumFontSize,
defaultParagraphAttributes.minimumFontSize);
paragraphAttributes.maximumFontSize = convertRawProp(
context,
rawProps,
"maximumFontSize",
sourceParagraphAttributes.maximumFontSize,
defaultParagraphAttributes.maximumFontSize);
paragraphAttributes.includeFontPadding = convertRawProp(
context,
rawProps,
Expand Down Expand Up @@ -1062,8 +1050,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;
constexpr static MapBuffer::Key PA_KEY_TEXT_ALIGN_VERTICAL = 8;

inline MapBuffer toMapBuffer(const ParagraphAttributes& paragraphAttributes) {
Expand All @@ -1088,9 +1075,7 @@ inline MapBuffer toMapBuffer(const ParagraphAttributes& paragraphAttributes) {
toString(*paragraphAttributes.textAlignVertical));
}
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,6 @@ void BaseParagraphProps::setProp(
paragraphAttributes,
minimumFontScale,
"minimumFontScale");
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
value,
paragraphAttributes,
minimumFontSize,
"minimumFontSize");
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
value,
paragraphAttributes,
maximumFontSize,
"maximumFontSize");
REBUILD_FIELD_SWITCH_CASE(
paDefaults,
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,6 @@ folly::dynamic HostPlatformParagraphProps::getDiffProps(
result["minimumFontScale"] = paragraphAttributes.minimumFontScale;
}

if (!floatEquality(
paragraphAttributes.minimumFontSize,
oldProps->paragraphAttributes.minimumFontSize)) {
result["minimumFontSize"] = paragraphAttributes.minimumFontSize;
}

if (!floatEquality(
paragraphAttributes.maximumFontSize,
oldProps->paragraphAttributes.maximumFontSize)) {
result["maximumFontSize"] = paragraphAttributes.maximumFontSize;
}

if (paragraphAttributes.includeFontPadding !=
oldProps->paragraphAttributes.includeFontPadding) {
result["includeFontPadding"] = paragraphAttributes.includeFontPadding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,9 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
}

if (!floatEquality(
paragraphAttributes.minimumFontSize,
oldProps->paragraphAttributes.minimumFontSize)) {
result["minimumFontSize"] = paragraphAttributes.minimumFontSize;
}

if (!floatEquality(
paragraphAttributes.maximumFontSize,
oldProps->paragraphAttributes.maximumFontSize)) {
result["maximumFontSize"] = paragraphAttributes.maximumFontSize;
paragraphAttributes.minimumFontScale,
oldProps->paragraphAttributes.minimumFontScale)) {
result["minimumFontScale"] = paragraphAttributes.minimumFontScale;
}

if (paragraphAttributes.includeFontPadding !=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,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
Expand All @@ -243,8 +259,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];
}

Expand Down
8 changes: 8 additions & 0 deletions packages/rn-tester/js/examples/Text/TextExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ class AdjustingFontSize extends React.Component<
Shrinking to fit available space is much better!
</Text>

<Text
numberOfLines={1}
adjustsFontSizeToFit={true}
minimumFontScale={0.5}
style={{fontSize: 40, marginVertical: 6}}>
Can limit how small the text becomes with minimumFontScale
</Text>

<Text
adjustsFontSizeToFit={true}
numberOfLines={1}
Expand Down