mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-13 22:43:59 +08:00
Restructured inheritance around ReactTextViewManager and co.
Summary: Abstract class `ReactBaseTextShadowNode` was decoupled from `ReactTextShadowNode` to separate two goals/roles: * `ReactBaseTextShadowNode` represents spanned `<Text>` nodes, which can bear text attributes (both `RCTText` and `RCTVirtualText`); * `ReactTextShadowNode` represents anchor `<Text>` view in Yoga terms, which can bear layout attributes (`RCTText` and `RCTTextInput`). `ReactVirtualTextShadowNode` now inherits `ReactBaseTextShadowNode`. The same architectural changes was applited to view managers. Why? * This is just a better architecture which represents the nature of this objects. * Bunch of "negative" logic which turn off excessive features for some suclasses was removed. * Memory efficiency. * Now we can improve `<TextInput>` component using right inheritance. Yay! Reviewed By: achen1 Differential Revision: D5715830 fbshipit-source-id: ecc0764a03b5b7586fe77ad31f149cd840f4da41
This commit is contained in:
committed by
Facebook Github Bot
parent
80027ce6db
commit
6114f863c3
@@ -35,7 +35,7 @@ import com.facebook.react.bridge.ReactTestHelper;
|
||||
import com.facebook.react.modules.core.ChoreographerCompat;
|
||||
import com.facebook.react.modules.core.ReactChoreographer;
|
||||
import com.facebook.react.views.text.ReactRawTextManager;
|
||||
import com.facebook.react.views.text.ReactTextShadowNode;
|
||||
import com.facebook.react.views.text.ReactRawTextShadowNode;
|
||||
import com.facebook.react.views.text.ReactTextViewManager;
|
||||
import com.facebook.react.views.view.ReactViewGroup;
|
||||
import com.facebook.react.views.view.ReactViewManager;
|
||||
@@ -134,7 +134,7 @@ public class UIManagerModuleTest {
|
||||
uiManager.updateView(
|
||||
rawTextTag,
|
||||
ReactRawTextManager.REACT_CLASS,
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "New text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "New text"));
|
||||
|
||||
uiManager.onBatchComplete();
|
||||
executePendingFrameCallbacks();
|
||||
@@ -672,7 +672,7 @@ public class UIManagerModuleTest {
|
||||
rawTextTag,
|
||||
ReactRawTextManager.REACT_CLASS,
|
||||
rootTag,
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, text, "collapsable", false));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, text, "collapsable", false));
|
||||
|
||||
uiManager.manageChildren(
|
||||
textTag,
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.facebook.react.uimanager.UIImplementationProvider;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.react.uimanager.ViewProps;
|
||||
import com.facebook.react.views.text.ReactRawTextShadowNode;
|
||||
import com.facebook.react.views.view.ReactViewBackgroundDrawable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -100,7 +101,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_SIZE, 21.0),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
AbsoluteSizeSpan sizeSpan = getSingleSpan(
|
||||
(TextView) rootView.getChildAt(0), AbsoluteSizeSpan.class);
|
||||
@@ -114,7 +115,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "bold"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -129,7 +130,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "500"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -144,7 +145,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -159,7 +160,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "bold", ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -174,7 +175,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "normal"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -188,7 +189,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_WEIGHT, "200"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -202,7 +203,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_STYLE, "normal"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -216,7 +217,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -232,7 +233,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif", ViewProps.FONT_WEIGHT, "bold"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -248,7 +249,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.FONT_FAMILY, "sans-serif", ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -267,7 +268,7 @@ public class ReactTextTest {
|
||||
ViewProps.FONT_FAMILY, "sans-serif",
|
||||
ViewProps.FONT_WEIGHT, "500",
|
||||
ViewProps.FONT_STYLE, "italic"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
CustomStyleSpan customStyleSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), CustomStyleSpan.class);
|
||||
@@ -283,7 +284,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
Spanned text = (Spanned) textView.getText();
|
||||
@@ -301,7 +302,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "line-through"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
Spanned text = (Spanned) textView.getText();
|
||||
@@ -320,7 +321,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.TEXT_DECORATION_LINE, "underline line-through"),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
UnderlineSpan underlineSpan =
|
||||
getSingleSpan((TextView) rootView.getChildAt(0), UnderlineSpan.class);
|
||||
@@ -337,7 +338,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.BACKGROUND_COLOR, Color.BLUE),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
Drawable backgroundDrawable = ((TextView) rootView.getChildAt(0)).getBackground();
|
||||
assertThat(((ReactViewBackgroundDrawable) backgroundDrawable).getColor()).isEqualTo(Color.BLUE);
|
||||
@@ -353,7 +354,7 @@ public class ReactTextTest {
|
||||
ReactRootView rootView = createText(
|
||||
uiManager,
|
||||
JavaOnlyMap.of(ViewProps.NUMBER_OF_LINES, 2),
|
||||
JavaOnlyMap.of(ReactTextShadowNode.PROP_TEXT, "test text"));
|
||||
JavaOnlyMap.of(ReactRawTextShadowNode.PROP_TEXT, "test text"));
|
||||
|
||||
TextView textView = (TextView) rootView.getChildAt(0);
|
||||
assertThat(textView.getText().toString()).isEqualTo("test text");
|
||||
|
||||
Reference in New Issue
Block a user