Skip to content

Commit 6bf9024

Browse files
sherginfacebook-github-bot
authored andcommitted
Implementation of operator== for YGValue
Summary: @public It's very useful sometimes for product code to compare `YGValue`s (e.g. in Fabric). Reviewed By: priteshrnandgaonkar Differential Revision: D8937594 fbshipit-source-id: b93e1ab4a6419ada6746f233b587e8c9cb32c6d4
1 parent fab5fff commit 6bf9024

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ const YGValue YGValueZero = {0, YGUnitPoint};
4848
const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined};
4949
const YGValue YGValueAuto = {YGUndefined, YGUnitAuto};
5050

51+
bool operator==(const YGValue& lhs, const YGValue& rhs) {
52+
if ((lhs.unit == YGUnitUndefined && rhs.unit == YGUnitUndefined) ||
53+
(lhs.unit == YGUnitAuto && rhs.unit == YGUnitAuto)) {
54+
return true;
55+
}
56+
57+
return lhs.unit == rhs.unit && lhs.value == rhs.value;
58+
}
59+
60+
bool operator!=(const YGValue& lhs, const YGValue& rhs) {
61+
return !(lhs == rhs);
62+
}
63+
5164
#ifdef ANDROID
5265
#include <android/log.h>
5366
static int YGAndroidLog(

ReactCommon/yoga/yoga/Yoga.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ typedef struct YGValue {
4545
extern const YGValue YGValueUndefined;
4646
extern const YGValue YGValueAuto;
4747

48+
#ifdef __cplusplus
49+
50+
extern bool operator==(const YGValue& lhs, const YGValue& rhs);
51+
extern bool operator!=(const YGValue& lhs, const YGValue& rhs);
52+
53+
#endif
54+
4855
typedef struct YGConfig* YGConfigRef;
4956

5057
typedef struct YGNode* YGNodeRef;

0 commit comments

Comments
 (0)