diff --git a/change/react-native-windows-d0b46459-5370-47eb-9a2c-9c46738403cb.json b/change/react-native-windows-d0b46459-5370-47eb-9a2c-9c46738403cb.json new file mode 100644 index 00000000000..564f8267998 --- /dev/null +++ b/change/react-native-windows-d0b46459-5370-47eb-9a2c-9c46738403cb.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Change the definition of YGUndefined from NAN to __builtin_nanf(\"0\")", + "packageName": "react-native-windows", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/YGValue.h b/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/YGValue.h new file mode 100644 index 00000000000..1853ccfec71 --- /dev/null +++ b/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/YGValue.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include "YGEnums.h" +#include "YGMacros.h" + +#if defined(_MSC_VER) && defined(__clang__) +#define COMPILING_WITH_CLANG_ON_WINDOWS +#endif +#if defined(COMPILING_WITH_CLANG_ON_WINDOWS) +#include +constexpr float YGUndefined = std::numeric_limits::quiet_NaN(); +#else +YG_EXTERN_C_BEGIN + +#if defined(_MSC_VER) +#define YGUndefined __builtin_nanf("0") +#else +#define YGUndefined NAN +#endif + +#endif + +typedef struct YGValue { + float value; + YGUnit unit; +} YGValue; + +YOGA_EXPORT extern const YGValue YGValueAuto; +YOGA_EXPORT extern const YGValue YGValueUndefined; +YOGA_EXPORT extern const YGValue YGValueZero; + +#if !defined(COMPILING_WITH_CLANG_ON_WINDOWS) +YG_EXTERN_C_END +#endif +#undef COMPILING_WITH_CLANG_ON_WINDOWS + +#ifdef __cplusplus + +inline bool operator==(const YGValue& lhs, const YGValue& rhs) { + if (lhs.unit != rhs.unit) { + return false; + } + + switch (lhs.unit) { + case YGUnitUndefined: + case YGUnitAuto: + return true; + case YGUnitPoint: + case YGUnitPercent: + return lhs.value == rhs.value; + } + + return false; +} + +inline bool operator!=(const YGValue& lhs, const YGValue& rhs) { + return !(lhs == rhs); +} + +inline YGValue operator-(const YGValue& value) { + return {-value.value, value.unit}; +} + +namespace facebook { +namespace yoga { +namespace literals { + +inline YGValue operator"" _pt(long double value) { + return YGValue{static_cast(value), YGUnitPoint}; +} +inline YGValue operator"" _pt(unsigned long long value) { + return operator"" _pt(static_cast(value)); +} + +inline YGValue operator"" _percent(long double value) { + return YGValue{static_cast(value), YGUnitPercent}; +} +inline YGValue operator"" _percent(unsigned long long value) { + return operator"" _percent(static_cast(value)); +} + +} // namespace literals +} // namespace yoga +} // namespace facebook + +#endif diff --git a/vnext/overrides.json b/vnext/overrides.json index 0a3a2c1a941..14f0b33133b 100644 --- a/vnext/overrides.json +++ b/vnext/overrides.json @@ -74,6 +74,12 @@ "baseHash": "95a6fd14e80719f9796942ffe59dd850a56d544c", "issue": 9791 }, + { + "type": "patch", + "file": "ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/YGValue.h", + "baseFile": "ReactCommon/yoga/yoga/YGValue.h", + "baseHash": "1beec1c755f33ebbd4ab9ec5e138cd1a3cfba3ee" + }, { "type": "patch", "file": "ReactCommon/Yoga.cpp",