mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor RCTText to take advantage of learnings from components
Summary: Made some improvements to RCTText based on some of our learnings from components for android. This now resembles diffusion/FBS/browse/master/fbandroid/java/com/facebook/components/widget/TextSpec.java Things that have improved: - Calculation of text width is now faster (we noticed in components that .getWith() on the layout is all that is needed and it is much faster) - Use text layout builder to abstract away a lot of the low level details of static / boring layouts and text measurements - Handle MeasureMode correctly, previously AT_MOST was not supported. - Better handling of RTL text by using TextLayoutBuilder where I made changes to support RTL text in components. Specifically RTL text measured with UNSPECIFIED or AT_MOST. - There was an incorrect assumption being made that when measure() was not called the text had to be boring. This is incorrect, Arabic text is never boring for example. Also multiline text is not boring either and may have exact sizing. Reviewed By: ahmedre Differential Revision: D3374752
This commit is contained in:
committed by
Ahmed El-Helw
parent
754d2848a4
commit
5f3f9caceb
@@ -12,6 +12,8 @@ package com.facebook.react.flat;
|
||||
import android.graphics.Canvas;
|
||||
import android.text.Layout;
|
||||
|
||||
import com.facebook.fbui.widget.text.LayoutMeasureUtil;
|
||||
|
||||
/**
|
||||
* DrawTextLayout is a DrawCommand that draw {@link Layout}.
|
||||
*/
|
||||
@@ -19,6 +21,7 @@ import android.text.Layout;
|
||||
|
||||
private Layout mLayout;
|
||||
private float mLayoutWidth;
|
||||
private float mLayoutHeight;
|
||||
|
||||
/* package */ DrawTextLayout(Layout layout) {
|
||||
setLayout(layout);
|
||||
@@ -29,15 +32,8 @@ import android.text.Layout;
|
||||
*/
|
||||
public void setLayout(Layout layout) {
|
||||
mLayout = layout;
|
||||
|
||||
// determine how wide we actually are
|
||||
float maxLineWidth = 0;
|
||||
int lineCount = layout.getLineCount();
|
||||
for (int i = 0; i != lineCount; ++i) {
|
||||
maxLineWidth = Math.max(maxLineWidth, layout.getLineMax(i));
|
||||
}
|
||||
|
||||
mLayoutWidth = maxLineWidth;
|
||||
mLayoutWidth = layout.getWidth();
|
||||
mLayoutHeight = LayoutMeasureUtil.getHeight(layout);
|
||||
}
|
||||
|
||||
public Layout getLayout() {
|
||||
@@ -50,7 +46,7 @@ import android.text.Layout;
|
||||
}
|
||||
|
||||
public float getLayoutHeight() {
|
||||
return mLayout.getHeight();
|
||||
return mLayoutHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user