Implement cloning for all ReactShadowNodes

Reviewed By: achen1

Differential Revision: D7063509

fbshipit-source-id: 90df8a3d2e6f2a4efa13f5eb0337b191b690bf8f
This commit is contained in:
David Vacca 2018-02-26 09:03:55 -08:00 committed by Facebook Github Bot
parent dabe8e0d01
commit 62efff8ab8
12 changed files with 201 additions and 4 deletions

View File

@ -37,6 +37,13 @@ public class LayoutShadowNode extends ReactShadowNodeImpl {
float value;
YogaUnit unit;
private MutableYogaValue() { }
private MutableYogaValue(MutableYogaValue mutableYogaValue) {
this.value = mutableYogaValue.value;
this.unit = mutableYogaValue.unit;
}
void setFromDynamic(Dynamic dynamic) {
if (dynamic.isNull()) {
unit = YogaUnit.UNDEFINED;
@ -59,7 +66,21 @@ public class LayoutShadowNode extends ReactShadowNodeImpl {
}
}
private final MutableYogaValue mTempYogaValue = new MutableYogaValue();
private final MutableYogaValue mTempYogaValue;
public LayoutShadowNode() {
mTempYogaValue = new MutableYogaValue();
}
protected LayoutShadowNode(LayoutShadowNode node) {
super(node);
mTempYogaValue = new MutableYogaValue(node.mTempYogaValue);
}
@Override
public LayoutShadowNode mutableCopy() {
return new LayoutShadowNode(this);
}
@ReactProp(name = ViewProps.WIDTH)
public void setWidth(Dynamic width) {

View File

@ -21,6 +21,17 @@ import com.facebook.react.uimanager.ReactShadowNodeImpl;
*/
class ModalHostShadowNode extends LayoutShadowNode {
public ModalHostShadowNode() {}
private ModalHostShadowNode(ModalHostShadowNode node) {
super(node);
}
@Override
public ModalHostShadowNode mutableCopy() {
return new ModalHostShadowNode(this);
}
/**
* We need to set the styleWidth and styleHeight of the one child (represented by the <View/>
* within the <RCTModalHostView/> in Modal.js. This needs to fill the entire window.

View File

@ -33,14 +33,30 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements YogaMeasu
private String mStyle = ReactProgressBarViewManager.DEFAULT_STYLE;
private final SparseIntArray mHeight = new SparseIntArray();
private final SparseIntArray mWidth = new SparseIntArray();
private final Set<Integer> mMeasured = new HashSet<>();
private final SparseIntArray mHeight;
private final SparseIntArray mWidth;
private final Set<Integer> mMeasured;
public ProgressBarShadowNode() {
mHeight = new SparseIntArray();
mWidth = new SparseIntArray();
mMeasured = new HashSet<>();
setMeasureFunction(this);
}
public ProgressBarShadowNode(ProgressBarShadowNode node) {
super(node);
mWidth = node.mWidth.clone();
mHeight = node.mHeight.clone();
mMeasured = new HashSet<>(node.mMeasured);
setMeasureFunction(this);
}
@Override
public ProgressBarShadowNode mutableCopy() {
return new ProgressBarShadowNode(this);
}
public @Nullable String getStyle() {
return mStyle;
}

View File

@ -48,9 +48,26 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider> {
private boolean mMeasured;
private ReactSliderShadowNode() {
initMeasureFunction();
}
private ReactSliderShadowNode(ReactSliderShadowNode node) {
super(node);
mWidth = node.mWidth;
mHeight = node.mHeight;
mMeasured = node.mMeasured;
initMeasureFunction();
}
private void initMeasureFunction() {
setMeasureFunction(this);
}
@Override
public ReactSliderShadowNode mutableCopy() {
return new ReactSliderShadowNode(this);
}
@Override
public long measure(
YogaNode node,

View File

@ -40,9 +40,26 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch> {
private boolean mMeasured;
private ReactSwitchShadowNode() {
initMeasureFunction();
}
private ReactSwitchShadowNode(ReactSwitchShadowNode node) {
super(node);
mWidth = node.mWidth;
mHeight = node.mHeight;
mMeasured = node.mMeasured;
initMeasureFunction();
}
private void initMeasureFunction() {
setMeasureFunction(this);
}
@Override
public ReactSwitchShadowNode mutableCopy() {
return new ReactSwitchShadowNode(this);
}
@Override
public long measure(
YogaNode node,

View File

@ -280,6 +280,39 @@ public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {
protected boolean mContainsImages = false;
protected float mHeightOfTallestInlineImage = Float.NaN;
public ReactBaseTextShadowNode() {}
public ReactBaseTextShadowNode(ReactBaseTextShadowNode node) {
super(node);
mLineHeight = node.mLineHeight;
mIsColorSet = node.mIsColorSet;
mAllowFontScaling = node.mAllowFontScaling;
mColor = node.mColor;
mIsBackgroundColorSet = node.mIsBackgroundColorSet;
mBackgroundColor = node.mBackgroundColor;
mNumberOfLines = node.mNumberOfLines;
mFontSize = node.mFontSize;
mFontSizeInput = node.mFontSizeInput;
mLineHeightInput = node.mLineHeightInput;
mTextAlign = node.mTextAlign;
mTextBreakStrategy = node.mTextBreakStrategy;
mTextShadowOffsetDx = node.mTextShadowOffsetDx;
mTextShadowOffsetDy = node.mTextShadowOffsetDy;
mTextShadowRadius = node.mTextShadowRadius;
mTextShadowColor = node.mTextShadowColor;
mIsUnderlineTextDecorationSet = node.mIsUnderlineTextDecorationSet;
mIsLineThroughTextDecorationSet = node.mIsLineThroughTextDecorationSet;
mIncludeFontPadding = node.mIncludeFontPadding;
mFontStyle = node.mFontStyle;
mFontWeight = node.mFontWeight;
mFontFamily = node.mFontFamily;
mContainsImages = node.mContainsImages;
mHeightOfTallestInlineImage = node.mHeightOfTallestInlineImage;
}
// Returns a line height which takes into account the requested line height
// and the height of the inline images.
public float getEffectiveLineHeight() {

View File

@ -22,6 +22,18 @@ public class ReactRawTextShadowNode extends ReactShadowNodeImpl {
private @Nullable String mText = null;
public ReactRawTextShadowNode() { }
private ReactRawTextShadowNode(ReactRawTextShadowNode node) {
super(node);
this.mText = node.mText;
}
@Override
public ReactShadowNodeImpl mutableCopy() {
return new ReactRawTextShadowNode(this);
}
@ReactProp(name = PROP_TEXT)
public void setText(@Nullable String text) {
mText = text;
@ -36,4 +48,6 @@ public class ReactRawTextShadowNode extends ReactShadowNodeImpl {
public boolean isVirtual() {
return true;
}
}

View File

@ -20,4 +20,11 @@ public abstract class ReactTextInlineImageShadowNode extends LayoutShadowNode {
* place of this node.
*/
public abstract TextInlineImageSpan buildInlineImageSpan();
public ReactTextInlineImageShadowNode() {}
protected ReactTextInlineImageShadowNode(ReactTextInlineImageShadowNode node) {
super(node);
}
}

View File

@ -17,6 +17,7 @@ import android.text.TextPaint;
import android.view.Gravity;
import android.widget.TextView;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.Spacing;
import com.facebook.react.uimanager.UIViewOperationQueue;
import com.facebook.yoga.YogaConstants;
@ -137,11 +138,26 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
};
public ReactTextShadowNode() {
initMeasureFunction();
}
private ReactTextShadowNode(ReactTextShadowNode node) {
super(node);
this.mPreparedSpannableText = node.mPreparedSpannableText;
initMeasureFunction();
}
private void initMeasureFunction() {
if (!isVirtual()) {
setMeasureFunction(mTextMeasureFunction);
}
}
@Override
public LayoutShadowNode mutableCopy() {
return new ReactTextShadowNode(this);
}
// Return text alignment according to LTR or RTL style
private int getTextAlign() {
int textAlign = mTextAlign;

View File

@ -11,4 +11,15 @@ public class ReactVirtualTextShadowNode extends ReactBaseTextShadowNode {
public boolean isVirtual() {
return true;
}
public ReactVirtualTextShadowNode() { }
private ReactVirtualTextShadowNode(ReactVirtualTextShadowNode node) {
super(node);
}
@Override
public ReactVirtualTextShadowNode mutableCopy() {
return new ReactVirtualTextShadowNode(this);
}
}

View File

@ -7,6 +7,7 @@
package com.facebook.react.views.text.frescosupport;
import com.facebook.react.uimanager.LayoutShadowNode;
import javax.annotation.Nullable;
import java.util.Locale;
@ -48,6 +49,21 @@ public class FrescoBasedReactTextInlineImageShadowNode extends ReactTextInlineIm
mCallerContext = callerContext;
}
private FrescoBasedReactTextInlineImageShadowNode(FrescoBasedReactTextInlineImageShadowNode node) {
super(node);
mHeaders = node.mHeaders; // mHeaders is immutable
mWidth = node.mWidth;
mHeight = node.mHeight;
mDraweeControllerBuilder = node.mDraweeControllerBuilder;
mCallerContext = node.mCallerContext;
mUri = node.mUri;
}
@Override
public FrescoBasedReactTextInlineImageShadowNode mutableCopy() {
return new FrescoBasedReactTextInlineImageShadowNode(this);
}
@ReactProp(name = "src")
public void setSource(@Nullable ReadableArray sources) {
final String source =

View File

@ -14,6 +14,7 @@ import android.widget.EditText;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.Spacing;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIViewOperationQueue;
@ -47,6 +48,23 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
setMeasureFunction(this);
}
private ReactTextInputShadowNode(ReactTextInputShadowNode node) {
super(node);
mMostRecentEventCount = node.mMostRecentEventCount;
mText = node.mText;
mLocalData = node.mLocalData;
setMeasureFunction(this);
ThemedReactContext themedContext = getThemedContext();
if (themedContext != null) {
setThemedContext(themedContext);
}
}
@Override
public ReactTextInputShadowNode mutableCopy() {
return new ReactTextInputShadowNode(this);
}
@Override
public void setThemedContext(ThemedReactContext themedContext) {
super.setThemedContext(themedContext);