Refactor ReactShadowNode to add emoji support for TextInput and Fabric

Summary:
This diff refactors support of emojis in RN classic in order to make it easy to extend support for text input and fabric (as part of this stack)

changelog:[internal]

Reviewed By: JoshuaGross

Differential Revision: D19679394

fbshipit-source-id: 45eff49800b3db281721088f107494005d390fff
This commit is contained in:
David Vacca 2020-02-03 21:03:11 -08:00 коммит произвёл Facebook Github Bot
Родитель acaef83a27
Коммит 86d1153586
3 изменённых файлов: 24 добавлений и 9 удалений

Просмотреть файл

@ -66,6 +66,8 @@ public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {
public static final int DEFAULT_TEXT_SHADOW_COLOR = 0x55000000; public static final int DEFAULT_TEXT_SHADOW_COLOR = 0x55000000;
protected @Nullable ReactTextViewManagerCallback mReactTextViewManagerCallback;
private static class SetSpanOperation { private static class SetSpanOperation {
protected int start, end; protected int start, end;
protected ReactSpan what; protected ReactSpan what;
@ -313,6 +315,10 @@ public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {
textShadowNode.mTextAttributes.setHeightOfTallestInlineViewOrImage( textShadowNode.mTextAttributes.setHeightOfTallestInlineViewOrImage(
heightOfTallestInlineViewOrImage); heightOfTallestInlineViewOrImage);
if (mReactTextViewManagerCallback != null) {
mReactTextViewManagerCallback.onPostProcessSpannable(sb);
}
return sb; return sb;
} }
@ -379,7 +385,13 @@ public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {
protected Map<Integer, ReactShadowNode> mInlineViews; protected Map<Integer, ReactShadowNode> mInlineViews;
public ReactBaseTextShadowNode() { public ReactBaseTextShadowNode() {
this(null);
}
public ReactBaseTextShadowNode(
@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
mTextAttributes = new TextAttributes(); mTextAttributes = new TextAttributes();
mReactTextViewManagerCallback = reactTextViewManagerCallback;
} }
// Return text alignment according to LTR or RTL style // Return text alignment according to LTR or RTL style

Просмотреть файл

@ -57,8 +57,6 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
private boolean mShouldNotifyOnTextLayout; private boolean mShouldNotifyOnTextLayout;
private @Nullable ReactTextViewManagerCallback mReactTextViewManagerCallback = null;
private final YogaMeasureFunction mTextMeasureFunction = private final YogaMeasureFunction mTextMeasureFunction =
new YogaMeasureFunction() { new YogaMeasureFunction() {
@Override @Override
@ -189,6 +187,11 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
}; };
public ReactTextShadowNode() { public ReactTextShadowNode() {
this(null);
}
public ReactTextShadowNode(@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
super(reactTextViewManagerCallback);
initMeasureFunction(); initMeasureFunction();
} }
@ -198,10 +201,6 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
} }
} }
public void setReactTextViewManagerCallback(ReactTextViewManagerCallback callback) {
mReactTextViewManagerCallback = callback;
}
// Return text alignment according to LTR or RTL style // Return text alignment according to LTR or RTL style
private int getTextAlign() { private int getTextAlign() {
int textAlign = mTextAlign; int textAlign = mTextAlign;
@ -223,9 +222,6 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
/* text (e.g. from `value` prop): */ null, /* text (e.g. from `value` prop): */ null,
/* supportsInlineViews: */ true, /* supportsInlineViews: */ true,
nativeViewHierarchyOptimizer); nativeViewHierarchyOptimizer);
if (mReactTextViewManagerCallback != null) {
mReactTextViewManagerCallback.onPostProcessSpannable(mPreparedSpannableText);
}
markUpdated(); markUpdated();
} }

Просмотреть файл

@ -34,6 +34,8 @@ public class ReactTextViewManager
@VisibleForTesting public static final String REACT_CLASS = "RCTText"; @VisibleForTesting public static final String REACT_CLASS = "RCTText";
protected @Nullable ReactTextViewManagerCallback mReactTextViewManagerCallback;
@Override @Override
public String getName() { public String getName() {
return REACT_CLASS; return REACT_CLASS;
@ -59,6 +61,11 @@ public class ReactTextViewManager
return new ReactTextShadowNode(); return new ReactTextShadowNode();
} }
public ReactTextShadowNode createShadowNodeInstance(
@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
return new ReactTextShadowNode(reactTextViewManagerCallback);
}
@Override @Override
public Class<ReactTextShadowNode> getShadowNodeClass() { public Class<ReactTextShadowNode> getShadowNodeClass() {
return ReactTextShadowNode.class; return ReactTextShadowNode.class;