Fabric: Returning zero size on attempt to measure an empty string in RCTTextLayoutManager

Summary:
Sometimes, very irregularly, measuring an empty string crashes/freezes iOS internal text infrastructure. This is our last line of defense.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC, mdvacca

Differential Revision: D18802308

fbshipit-source-id: addf523b31b78b0777be7eeaeee140ac8416393b
This commit is contained in:
Valentin Shergin
2019-12-04 18:36:49 -08:00
committed by Facebook Github Bot
parent d12385cae6
commit 42f2ded900
@@ -36,6 +36,13 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(EllipsizeMode ellipsi
paragraphAttributes:(ParagraphAttributes)paragraphAttributes
layoutConstraints:(LayoutConstraints)layoutConstraints
{
if (attributedString.length == 0) {
// This is not really an optimization because that should be checked much earlier on the call stack.
// Sometimes, very irregularly, measuring an empty string crashes/freezes iOS internal text infrastructure.
// This is our last line of defense.
return layoutConstraints.clamp({0, 0});
}
CGSize maximumSize = CGSize{layoutConstraints.maximumSize.width,
layoutConstraints.maximumSize.height};
NSTextStorage *textStorage = [self _textStorageAndLayoutManagerWithAttributesString:attributedString