Breaking remove YogaNode#clone
Summary: @public The cloning features of YogaNode don’t seem to be used. Let’s remove them. Reviewed By: SidharthGuglani Differential Revision: D14165624 fbshipit-source-id: 5b710964a4abf1b35f3bcc25b143ffc719a03cec
This commit is contained in:
committed by
Facebook Github Bot
parent
47abe1c482
commit
e25fe994b3
@@ -233,112 +233,6 @@ public class YogaNodeTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneNode() throws Exception {
|
||||
YogaConfig config = new YogaConfig();
|
||||
YogaNode root = createNode(config);
|
||||
YogaNode child = createNode(config);
|
||||
YogaNode grandChild = createNode(config);
|
||||
root.addChildAt(child, 0);
|
||||
child.addChildAt(grandChild, 0);
|
||||
child.setFlexDirection(YogaFlexDirection.ROW);
|
||||
|
||||
YogaNode clonedChild = ((YogaNodeJNI) child).clone();
|
||||
|
||||
assertNotSame(clonedChild, child);
|
||||
|
||||
assertEquals(YogaFlexDirection.ROW, child.getFlexDirection());
|
||||
assertEquals(child.getFlexDirection(), clonedChild.getFlexDirection());
|
||||
|
||||
// Verify the cloning is shallow on the List of children
|
||||
assertEquals(1, child.getChildCount());
|
||||
assertEquals(child.getChildCount(), clonedChild.getChildCount());
|
||||
assertEquals(child.getChildAt(0), clonedChild.getChildAt(0));
|
||||
|
||||
child.removeChildAt(0);
|
||||
assertEquals(0, child.getChildCount());
|
||||
assertEquals(1, clonedChild.getChildCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneWithNewChildren() throws Exception {
|
||||
YogaConfig config = new YogaConfig();
|
||||
YogaNode root = createNode(config);
|
||||
YogaNode child = createNode(config);
|
||||
YogaNode grandChild = createNode(config);
|
||||
root.addChildAt(child, 0);
|
||||
child.addChildAt(grandChild, 0);
|
||||
child.setFlexDirection(YogaFlexDirection.ROW);
|
||||
|
||||
YogaNode clonedChild = ((YogaNodeJNI) child).cloneWithNewChildren();
|
||||
|
||||
assertNotSame(clonedChild, child);
|
||||
assertEquals(YogaFlexDirection.ROW, clonedChild.getFlexDirection());
|
||||
assertEquals(child.getFlexDirection(), clonedChild.getFlexDirection());
|
||||
assertEquals(0, clonedChild.getChildCount());
|
||||
assertEquals(1, child.getChildCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneNodeListener() throws Exception {
|
||||
final AtomicBoolean onNodeClonedExecuted = new AtomicBoolean(false);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setOnCloneNode(
|
||||
new YogaNodeCloneFunction() {
|
||||
@Override
|
||||
public YogaNode cloneNode(YogaNode oldNode, YogaNode owner, int childIndex) {
|
||||
onNodeClonedExecuted.set(true);
|
||||
return ((YogaNodeJNI) oldNode).clone();
|
||||
}
|
||||
});
|
||||
YogaNode root = createNode(config);
|
||||
root.setWidth(100f);
|
||||
root.setHeight(100f);
|
||||
YogaNode child0 = createNode(config);
|
||||
root.addChildAt(child0, 0);
|
||||
child0.setWidth(50f);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
// Force a clone to happen.
|
||||
final YogaNode root2 = ((YogaNodeJNI) root).clone();
|
||||
root2.setWidth(200f);
|
||||
root2.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertTrue(onNodeClonedExecuted.get());
|
||||
assertEquals(1, root2.getChildCount());
|
||||
YogaNode clonedNode = root2.getChildAt(0);
|
||||
assertNotSame(child0, clonedNode);
|
||||
assertEquals(child0.getWidth(), clonedNode.getWidth());
|
||||
assertEquals(50f, clonedNode.getWidth().value, 0.01f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnNodeClonedLeak() throws Exception {
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setOnCloneNode(
|
||||
new YogaNodeCloneFunction() {
|
||||
@Override
|
||||
public YogaNode cloneNode(YogaNode oldNode, YogaNode owner, int childIndex) {
|
||||
return ((YogaNodeJNI) oldNode).clone();
|
||||
}
|
||||
});
|
||||
config.setOnCloneNode(null);
|
||||
WeakReference<Object> ref = new WeakReference<Object>(config);
|
||||
// noinspection UnusedAssignment
|
||||
config = null;
|
||||
// try and free for the next 5 seconds, usually it works after the
|
||||
// first GC attempt.
|
||||
for (int i = 0; i < 50; i++) {
|
||||
System.gc();
|
||||
if (ref.get() == null) {
|
||||
// free successfully
|
||||
return;
|
||||
}
|
||||
Thread.sleep(100);
|
||||
}
|
||||
fail("YogaConfig leaked");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlagShouldDiffLayoutWithoutLegacyStretchBehaviour() throws Exception {
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
Reference in New Issue
Block a user