From 12023b7953e70d05d43bb11094d1f3375bdb2bb4 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Mon, 21 Dec 2015 16:27:28 -0800 Subject: [PATCH] Implement numberOfLines support in React flat rendering. Summary: Support numberOfLines in React with flat rendering. Differential Revision: D2746855 --- .../java/com/facebook/react/flat/RCTText.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java index e6413b470..6ee2931bd 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTText.java @@ -20,6 +20,7 @@ import android.text.TextUtils; import com.facebook.csslayout.CSSNode; import com.facebook.csslayout.MeasureOutput; +import com.facebook.fbui.widget.text.staticlayouthelper.StaticLayoutHelper; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.ReactProp; import com.facebook.react.uimanager.ViewDefaults; @@ -45,6 +46,7 @@ import com.facebook.react.uimanager.ViewProps; private @Nullable BoringLayout.Metrics mBoringLayoutMetrics; private float mSpacingMult = 1.0f; private float mSpacingAdd = 0.0f; + private int mNumberOfLines = Integer.MAX_VALUE; public RCTText() { setMeasureFunction(this); @@ -105,14 +107,20 @@ import com.facebook.react.uimanager.ViewProps; int maximumWidth = Float.isNaN(width) ? Integer.MAX_VALUE : (int) width; // at this point we need to create a StaticLayout to measure the text - StaticLayout layout = new StaticLayout( + StaticLayout layout = StaticLayoutHelper.make( text, + 0, + text.length(), PAINT, maximumWidth, Layout.Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, - INCLUDE_PADDING); + INCLUDE_PADDING, + TextUtils.TruncateAt.END, + maximumWidth, + mNumberOfLines, + false); // determine how wide we actually are float maxLineWidth = 0; @@ -196,6 +204,12 @@ import com.facebook.react.uimanager.ViewProps; notifyChanged(true); } + @ReactProp(name = ViewProps.NUMBER_OF_LINES, defaultInt = Integer.MAX_VALUE) + public void setNumberOfLines(int numberOfLines) { + mNumberOfLines = numberOfLines; + notifyChanged(true); + } + @Override /* package */ void updateNodeRegion(float left, float top, float right, float bottom) { if (mDrawCommand == null) {