From 1f1918e473654b009ce59cb9c1d73b05ac88e4dc Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Fri, 21 Apr 2023 15:36:17 -0700 Subject: [PATCH] Remove C++ form of YGNodeSetChildren (#37013) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37013 X-link: 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 --- .../ReactCommon/yoga/yoga/Yoga.cpp | 33 +++++++------------ .../react-native/ReactCommon/yoga/yoga/Yoga.h | 10 +----- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp b/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp index 78486e2e957..ddacd6036c8 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp @@ -379,13 +379,16 @@ YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef owner) { owner->markDirtyAndPropagate(); } -static void YGNodeSetChildrenInternal( - YGNodeRef const owner, - const std::vector& 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& children) { - YGNodeSetChildrenInternal(owner, children); -} - YOGA_EXPORT YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index) { if (index < node->getChildren().size()) { diff --git a/packages/react-native/ReactCommon/yoga/yoga/Yoga.h b/packages/react-native/ReactCommon/yoga/yoga/Yoga.h index 7b579687005..3eee36928f0 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/Yoga.h +++ b/packages/react-native/ReactCommon/yoga/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 - -void YGNodeSetChildren(YGNodeRef owner, const std::vector& children); - -#endif