Skip to content

Commit

Permalink
Refactor ReactShadowNode to add emoji support for TextInput and Fabric
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Feb 4, 2020
1 parent acaef83 commit 86d1153
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {

public static final int DEFAULT_TEXT_SHADOW_COLOR = 0x55000000;

protected @Nullable ReactTextViewManagerCallback mReactTextViewManagerCallback;

private static class SetSpanOperation {
protected int start, end;
protected ReactSpan what;
Expand Down Expand Up @@ -313,6 +315,10 @@ protected Spannable spannedFromShadowNode(
textShadowNode.mTextAttributes.setHeightOfTallestInlineViewOrImage(
heightOfTallestInlineViewOrImage);

if (mReactTextViewManagerCallback != null) {
mReactTextViewManagerCallback.onPostProcessSpannable(sb);
}

return sb;
}

Expand Down Expand Up @@ -379,7 +385,13 @@ protected Spannable spannedFromShadowNode(
protected Map<Integer, ReactShadowNode> mInlineViews;

public ReactBaseTextShadowNode() {
this(null);
}

public ReactBaseTextShadowNode(
@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
mTextAttributes = new TextAttributes();
mReactTextViewManagerCallback = reactTextViewManagerCallback;
}

// Return text alignment according to LTR or RTL style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {

private boolean mShouldNotifyOnTextLayout;

private @Nullable ReactTextViewManagerCallback mReactTextViewManagerCallback = null;

private final YogaMeasureFunction mTextMeasureFunction =
new YogaMeasureFunction() {
@Override
Expand Down Expand Up @@ -189,6 +187,11 @@ public long measure(
};

public ReactTextShadowNode() {
this(null);
}

public ReactTextShadowNode(@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
super(reactTextViewManagerCallback);
initMeasureFunction();
}

Expand All @@ -198,10 +201,6 @@ private void initMeasureFunction() {
}
}

public void setReactTextViewManagerCallback(ReactTextViewManagerCallback callback) {
mReactTextViewManagerCallback = callback;
}

// Return text alignment according to LTR or RTL style
private int getTextAlign() {
int textAlign = mTextAlign;
Expand All @@ -223,9 +222,6 @@ public void onBeforeLayout(NativeViewHierarchyOptimizer nativeViewHierarchyOptim
/* text (e.g. from `value` prop): */ null,
/* supportsInlineViews: */ true,
nativeViewHierarchyOptimizer);
if (mReactTextViewManagerCallback != null) {
mReactTextViewManagerCallback.onPostProcessSpannable(mPreparedSpannableText);
}
markUpdated();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class ReactTextViewManager

@VisibleForTesting public static final String REACT_CLASS = "RCTText";

protected @Nullable ReactTextViewManagerCallback mReactTextViewManagerCallback;

@Override
public String getName() {
return REACT_CLASS;
Expand All @@ -59,6 +61,11 @@ public ReactTextShadowNode createShadowNodeInstance() {
return new ReactTextShadowNode();
}

public ReactTextShadowNode createShadowNodeInstance(
@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
return new ReactTextShadowNode(reactTextViewManagerCallback);
}

@Override
public Class<ReactTextShadowNode> getShadowNodeClass() {
return ReactTextShadowNode.class;
Expand Down

0 comments on commit 86d1153

Please sign in to comment.