Clone ReactShadowNode when Yoga clones a YogaNode during layout
Reviewed By: achen1 Differential Revision: D7195840 fbshipit-source-id: d596e3ada8fe48577b91295721d41c0afd33087f
This commit is contained in:
parent
20fcf4779c
commit
a7558d58a0
|
@ -21,6 +21,7 @@ import com.facebook.yoga.YogaFlexDirection;
|
||||||
import com.facebook.yoga.YogaJustify;
|
import com.facebook.yoga.YogaJustify;
|
||||||
import com.facebook.yoga.YogaMeasureFunction;
|
import com.facebook.yoga.YogaMeasureFunction;
|
||||||
import com.facebook.yoga.YogaNode;
|
import com.facebook.yoga.YogaNode;
|
||||||
|
import com.facebook.yoga.YogaNodeClonedFunction;
|
||||||
import com.facebook.yoga.YogaOverflow;
|
import com.facebook.yoga.YogaOverflow;
|
||||||
import com.facebook.yoga.YogaPositionType;
|
import com.facebook.yoga.YogaPositionType;
|
||||||
import com.facebook.yoga.YogaValue;
|
import com.facebook.yoga.YogaValue;
|
||||||
|
@ -58,6 +59,19 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||||
private static final YogaConfig sYogaConfig;
|
private static final YogaConfig sYogaConfig;
|
||||||
static {
|
static {
|
||||||
sYogaConfig = ReactYogaConfigProvider.get();
|
sYogaConfig = ReactYogaConfigProvider.get();
|
||||||
|
sYogaConfig.setOnNodeCloned(new YogaNodeClonedFunction() {
|
||||||
|
@Override
|
||||||
|
public void onNodeCloned(YogaNode oldYogaNode,
|
||||||
|
YogaNode newYogaNode,
|
||||||
|
YogaNode parent,
|
||||||
|
int childIndex) {
|
||||||
|
ReactShadowNode parentReactShadowNode = (ReactShadowNode) parent.getData();
|
||||||
|
Assertions.assertNotNull(parentReactShadowNode);
|
||||||
|
|
||||||
|
ReactShadowNode newReactShadowNode = (ReactShadowNode) newYogaNode.getData();
|
||||||
|
Assertions.assertNotNull(newReactShadowNode);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private int mReactTag;
|
private int mReactTag;
|
||||||
|
@ -88,6 +102,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||||
if (!isVirtual()) {
|
if (!isVirtual()) {
|
||||||
YogaNode node = YogaNodePool.get().acquire();
|
YogaNode node = YogaNodePool.get().acquire();
|
||||||
mYogaNode = node == null ? new YogaNode(sYogaConfig) : node;
|
mYogaNode = node == null ? new YogaNode(sYogaConfig) : node;
|
||||||
|
mYogaNode.setData(this);
|
||||||
Arrays.fill(mPadding, YogaConstants.UNDEFINED);
|
Arrays.fill(mPadding, YogaConstants.UNDEFINED);
|
||||||
} else {
|
} else {
|
||||||
mYogaNode = null;
|
mYogaNode = null;
|
||||||
|
@ -117,6 +132,7 @@ public class ReactShadowNodeImpl implements ReactShadowNode<ReactShadowNodeImpl>
|
||||||
arraycopy(original.mPadding, 0, mPadding, 0, original.mPadding.length);
|
arraycopy(original.mPadding, 0, mPadding, 0, original.mPadding.length);
|
||||||
arraycopy(original.mPaddingIsPercent, 0, mPaddingIsPercent, 0, original.mPaddingIsPercent.length);
|
arraycopy(original.mPaddingIsPercent, 0, mPaddingIsPercent, 0, original.mPaddingIsPercent.length);
|
||||||
mYogaNode = original.mYogaNode.clone();
|
mYogaNode = original.mYogaNode.clone();
|
||||||
|
mYogaNode.setData(this);
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
// it should never happen
|
// it should never happen
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
|
Loading…
Reference in New Issue