mirror of
https://github.com/status-im/react-native.git
synced 2025-01-16 12:34:17 +00:00
Implement numberOfLines support in React flat rendering.
Summary: Support numberOfLines in React with flat rendering. Differential Revision: D2746855
This commit is contained in:
parent
c5d0cb70d7
commit
12023b7953
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user