Fix RCTText crashing when negative width is passed to measure

Reviewed By: sriramramani

Differential Revision: D3038767

fb-gh-sync-id: ad3fde7cf4b73aad786bdf1dc3cea24862d656b8
shipit-source-id: ad3fde7cf4b73aad786bdf1dc3cea24862d656b8
This commit is contained in:
Denis Koroskin 2016-03-10 17:18:49 -08:00 committed by Facebook Github Bot 7
parent 3833c1b751
commit c42fc61a2a
1 changed files with 6 additions and 2 deletions

View File

@ -205,8 +205,12 @@ public class ReactTextShadowNode extends LayoutShadowNode {
float desiredWidth = boring == null ? float desiredWidth = boring == null ?
Layout.getDesiredWidth(text, textPaint) : Float.NaN; Layout.getDesiredWidth(text, textPaint) : Float.NaN;
// technically, width should never be negative, but there is currently a bug in
// LayoutEngine where a negative value can be passed.
boolean unconstrainedWidth = CSSConstants.isUndefined(width) || width < 0;
if (boring == null && if (boring == null &&
(CSSConstants.isUndefined(width) || (unconstrainedWidth ||
(!CSSConstants.isUndefined(desiredWidth) && desiredWidth <= width))) { (!CSSConstants.isUndefined(desiredWidth) && desiredWidth <= width))) {
// Is used when the width is not known and the text is not boring, ie. if it contains // Is used when the width is not known and the text is not boring, ie. if it contains
// unicode characters. // unicode characters.
@ -218,7 +222,7 @@ public class ReactTextShadowNode extends LayoutShadowNode {
1, 1,
0, 0,
true); true);
} else if (boring != null && (CSSConstants.isUndefined(width) || boring.width <= width)) { } else if (boring != null && (unconstrainedWidth || boring.width <= width)) {
// Is used for single-line, boring text when the width is either unknown or bigger // Is used for single-line, boring text when the width is either unknown or bigger
// than the width of the text. // than the width of the text.
layout = BoringLayout.make( layout = BoringLayout.make(