Remove C++ form of YGNodeSetChildren (#37013)
Summary: X-link: https://github.com/facebook/react-native/pull/37013 Pull Request resolved: https://github.com/facebook/yoga/pull/1254 Brings Yoga public interface back to a nice pure C ABI. Changelog: [Internal] Reviewed By: rshest Differential Revision: D45138827 fbshipit-source-id: 8df7e4fd03afcda9a714d193b0430c122a7a7574
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7afddfd204
commit
85ff2f06c2
@@ -23,11 +23,11 @@ TEST(YogaTest, set_children_adds_children_to_parent) {
|
||||
YGNodeRef const root_child0 = YGNodeNew();
|
||||
YGNodeRef const root_child1 = YGNodeNew();
|
||||
|
||||
YGNodeSetChildren(root, {root_child0, root_child1});
|
||||
YGNodeRef children[] = {root_child0, root_child1};
|
||||
YGNodeSetChildren(root, children, 2);
|
||||
|
||||
const std::vector<YGNodeRef> children = getChildren(root);
|
||||
const std::vector<YGNodeRef> expectedChildren = {root_child0, root_child1};
|
||||
ASSERT_EQ(children, expectedChildren);
|
||||
ASSERT_EQ(getChildren(root), expectedChildren);
|
||||
|
||||
const std::vector<YGNodeRef> owners = {
|
||||
YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)};
|
||||
@@ -42,12 +42,12 @@ TEST(YogaTest, set_children_to_empty_removes_old_children) {
|
||||
YGNodeRef const root_child0 = YGNodeNew();
|
||||
YGNodeRef const root_child1 = YGNodeNew();
|
||||
|
||||
YGNodeSetChildren(root, {root_child0, root_child1});
|
||||
YGNodeSetChildren(root, {});
|
||||
YGNodeRef children[] = {root_child0, root_child1};
|
||||
YGNodeSetChildren(root, children, 2);
|
||||
YGNodeSetChildren(root, nullptr, 0);
|
||||
|
||||
const std::vector<YGNodeRef> children = getChildren(root);
|
||||
const std::vector<YGNodeRef> expectedChildren = {};
|
||||
ASSERT_EQ(children, expectedChildren);
|
||||
ASSERT_EQ(getChildren(root), expectedChildren);
|
||||
|
||||
const std::vector<YGNodeRef> owners = {
|
||||
YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)};
|
||||
@@ -62,16 +62,17 @@ TEST(YogaTest, set_children_replaces_non_common_children) {
|
||||
YGNodeRef const root_child0 = YGNodeNew();
|
||||
YGNodeRef const root_child1 = YGNodeNew();
|
||||
|
||||
YGNodeSetChildren(root, {root_child0, root_child1});
|
||||
YGNodeRef children1[] = {root_child0, root_child1};
|
||||
YGNodeSetChildren(root, children1, 2);
|
||||
|
||||
YGNodeRef const root_child2 = YGNodeNew();
|
||||
YGNodeRef const root_child3 = YGNodeNew();
|
||||
|
||||
YGNodeSetChildren(root, {root_child2, root_child3});
|
||||
YGNodeRef children2[] = {root_child2, root_child3};
|
||||
YGNodeSetChildren(root, children2, 2);
|
||||
|
||||
const std::vector<YGNodeRef> children = getChildren(root);
|
||||
const std::vector<YGNodeRef> expectedChildren = {root_child2, root_child3};
|
||||
ASSERT_EQ(children, expectedChildren);
|
||||
ASSERT_EQ(getChildren(root), expectedChildren);
|
||||
|
||||
const std::vector<YGNodeRef> owners = {
|
||||
YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)};
|
||||
@@ -89,16 +90,17 @@ TEST(YogaTest, set_children_keeps_and_reorders_common_children) {
|
||||
YGNodeRef const root_child1 = YGNodeNew();
|
||||
YGNodeRef const root_child2 = YGNodeNew();
|
||||
|
||||
YGNodeSetChildren(root, {root_child0, root_child1, root_child2});
|
||||
YGNodeRef children1[] = {root_child0, root_child1, root_child2};
|
||||
YGNodeSetChildren(root, children1, 3);
|
||||
|
||||
YGNodeRef const root_child3 = YGNodeNew();
|
||||
|
||||
YGNodeSetChildren(root, {root_child2, root_child1, root_child3});
|
||||
YGNodeRef children2[] = {root_child2, root_child1, root_child3};
|
||||
YGNodeSetChildren(root, children2, 3);
|
||||
|
||||
const std::vector<YGNodeRef> children = getChildren(root);
|
||||
const std::vector<YGNodeRef> expectedChildren = {
|
||||
root_child2, root_child1, root_child3};
|
||||
ASSERT_EQ(children, expectedChildren);
|
||||
ASSERT_EQ(getChildren(root), expectedChildren);
|
||||
|
||||
const std::vector<YGNodeRef> owners = {
|
||||
YGNodeGetOwner(root_child0),
|
||||
|
@@ -379,13 +379,16 @@ YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef owner) {
|
||||
owner->markDirtyAndPropagate();
|
||||
}
|
||||
|
||||
static void YGNodeSetChildrenInternal(
|
||||
YGNodeRef const owner,
|
||||
const std::vector<YGNodeRef>& children) {
|
||||
YOGA_EXPORT void YGNodeSetChildren(
|
||||
const YGNodeRef owner,
|
||||
const YGNodeRef* children,
|
||||
const uint32_t count) {
|
||||
if (!owner) {
|
||||
return;
|
||||
}
|
||||
if (children.size() == 0) {
|
||||
|
||||
const YGVector childrenVector = {children, children + count};
|
||||
if (childrenVector.size() == 0) {
|
||||
if (YGNodeGetChildCount(owner) > 0) {
|
||||
for (YGNodeRef const child : owner->getChildren()) {
|
||||
child->setLayout(YGLayout());
|
||||
@@ -399,35 +402,21 @@ static void YGNodeSetChildrenInternal(
|
||||
for (YGNodeRef const oldChild : owner->getChildren()) {
|
||||
// Our new children may have nodes in common with the old children. We
|
||||
// don't reset these common nodes.
|
||||
if (std::find(children.begin(), children.end(), oldChild) ==
|
||||
children.end()) {
|
||||
if (std::find(childrenVector.begin(), childrenVector.end(), oldChild) ==
|
||||
childrenVector.end()) {
|
||||
oldChild->setLayout(YGLayout());
|
||||
oldChild->setOwner(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
owner->setChildren(children);
|
||||
for (YGNodeRef child : children) {
|
||||
owner->setChildren(childrenVector);
|
||||
for (YGNodeRef child : childrenVector) {
|
||||
child->setOwner(owner);
|
||||
}
|
||||
owner->markDirtyAndPropagate();
|
||||
}
|
||||
}
|
||||
|
||||
YOGA_EXPORT void YGNodeSetChildren(
|
||||
const YGNodeRef owner,
|
||||
const YGNodeRef c[],
|
||||
const uint32_t count) {
|
||||
const YGVector children = {c, c + count};
|
||||
YGNodeSetChildrenInternal(owner, children);
|
||||
}
|
||||
|
||||
YOGA_EXPORT void YGNodeSetChildren(
|
||||
YGNodeRef const owner,
|
||||
const std::vector<YGNodeRef>& children) {
|
||||
YGNodeSetChildrenInternal(owner, children);
|
||||
}
|
||||
|
||||
YOGA_EXPORT YGNodeRef
|
||||
YGNodeGetChild(const YGNodeRef node, const uint32_t index) {
|
||||
if (index < node->getChildren().size()) {
|
||||
|
10
yoga/Yoga.h
10
yoga/Yoga.h
@@ -82,7 +82,7 @@ WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node);
|
||||
WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeRef node);
|
||||
WIN_EXPORT void YGNodeSetChildren(
|
||||
YGNodeRef owner,
|
||||
const YGNodeRef children[],
|
||||
const YGNodeRef* children,
|
||||
uint32_t count);
|
||||
|
||||
WIN_EXPORT void YGNodeSetIsReferenceBaseline(
|
||||
@@ -364,11 +364,3 @@ WIN_EXPORT float YGRoundValueToPixelGrid(
|
||||
bool forceFloor);
|
||||
|
||||
YG_EXTERN_C_END
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <vector>
|
||||
|
||||
void YGNodeSetChildren(YGNodeRef owner, const std::vector<YGNodeRef>& children);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user