From 5765be9488048f93ef3802c7e4b9a308358fa5a6 Mon Sep 17 00:00:00 2001 From: Marlene Cota Date: Tue, 6 Feb 2024 09:14:25 -0800 Subject: [PATCH] Remove some c++20 forks (#12679) * Remove some c++20 forks * Change files * Re-add MapBufferBuilder.cpp * Re-add ShadowTree.cpp --- ...-8227ceff-75df-4435-b47d-c3fa96ab30d7.json | 7 + .../react/renderer/core/RawPropsParser.cpp | 226 ------------- .../react/renderer/core/propsConversions.h | 147 --------- .../yoga/yoga/config/Config.h | 93 ------ .../yoga/yoga/enums/YogaEnums.h | 74 ----- .../yoga/yoga/node/LayoutResults.h | 140 -------- .../yoga/yoga/numeric/Comparison.h | 86 ----- .../yoga/yoga/style/Style.h | 301 ------------------ vnext/overrides.json | 42 --- 9 files changed, 7 insertions(+), 1109 deletions(-) create mode 100644 change/react-native-windows-8227ceff-75df-4435-b47d-c3fa96ab30d7.json delete mode 100644 vnext/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/RawPropsParser.cpp delete mode 100644 vnext/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/propsConversions.h delete mode 100644 vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/config/Config.h delete mode 100644 vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/enums/YogaEnums.h delete mode 100644 vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/node/LayoutResults.h delete mode 100644 vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/numeric/Comparison.h delete mode 100644 vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/style/Style.h diff --git a/change/react-native-windows-8227ceff-75df-4435-b47d-c3fa96ab30d7.json b/change/react-native-windows-8227ceff-75df-4435-b47d-c3fa96ab30d7.json new file mode 100644 index 00000000000..8dc74224754 --- /dev/null +++ b/change/react-native-windows-8227ceff-75df-4435-b47d-c3fa96ab30d7.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Remove some c++20 forks", + "packageName": "react-native-windows", + "email": "email not defined", + "dependentChangeType": "patch" +} diff --git a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/RawPropsParser.cpp b/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/RawPropsParser.cpp deleted file mode 100644 index a5720ef4b65..00000000000 --- a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/RawPropsParser.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "RawPropsParser.h" - -#include -#include - -#include - -namespace facebook::react { - -// During parser initialization, Props structs are used to parse -// "fake"/empty objects, and `at` is called repeatedly which tells us -// which props are accessed during parsing, and in which order. -const RawValue* RawPropsParser::at( - const RawProps& rawProps, - const RawPropsKey& key) const noexcept { - // [Windows c++20 fix #12195 - if (UNLIKELY(!ready_)) { - // Windows] - // Check against the same key being inserted more than once. - // This happens commonly with nested Props structs, where the higher-level - // struct may access all fields, and then the nested Props struct may - // access fields a second (or third, etc) time. - // Without this, multiple entries will be created for the same key, but - // only the first access of the key will return a sensible value. - // The complexity of this is (n + (n - 1) + (n - 2) + ... + (n - (n - 1) + - // 1))) or n*n - (1/2)(n*(n+1)). If there are 100 props, this will result in - // 4950 lookups and equality checks on initialization of the parser, which - // happens exactly once per component. - size_t size = keys_.size(); - for (size_t i = 0; i < size; i++) { - if (keys_[i] == key) { - return nullptr; - } - } - // This is not thread-safe part; this happens only during initialization of - // a `ComponentDescriptor` where it is actually safe. - keys_.push_back(key); - react_native_assert(size < std::numeric_limits::max()); - nameToIndex_.insert(key, static_cast(size)); - return nullptr; - } - - // Normally, keys are looked up in-order. For performance we can simply - // increment this key counter, and if the key is equal to the key at the next - // index, there's no need to do any lookups. However, it's possible for keys - // to be accessed out-of-order or multiple times, in which case we start - // searching again from index 0. - // To prevent infinite loops (which can occur if you look up a key that - // doesn't exist) we keep track of whether or not we've already looped around, - // and log and return nullptr if so. However, we ONLY do this in debug mode, - // where you're more likely to look up a nonexistent key as part of debugging. - // You can (and must) ensure infinite loops are not possible in production by: - // (1) constructing all props objects without conditionals, or (2) if there - // are conditionals, ensure that in the parsing setup case, the Props - // constructor will access _all_ possible props. To ensure this performance - // optimization is utilized, always access props in the same order every time. - // This is trivial if you have a simple Props constructor, but difficult or - // impossible if you have a shared sub-prop Struct that is used by multiple - // parent Props. -#ifdef REACT_NATIVE_DEBUG - bool resetLoop = false; -#endif - do { - rawProps.keyIndexCursor_++; - // [Windows c++20 fix #12195 - if (UNLIKELY(static_cast(rawProps.keyIndexCursor_) >= keys_.size())) { - // Windows] -#ifdef REACT_NATIVE_DEBUG - if (resetLoop) { - LOG(ERROR) - << "Looked up property name which was not seen when preparing: " - << (std::string)key; - return nullptr; - } - resetLoop = true; -#endif - rawProps.keyIndexCursor_ = 0; - } - } while (key != keys_[rawProps.keyIndexCursor_]); - - auto valueIndex = rawProps.keyIndexToValueIndex_[rawProps.keyIndexCursor_]; - return valueIndex == kRawPropsValueIndexEmpty ? nullptr - : &rawProps.values_[valueIndex]; -} - -void RawPropsParser::postPrepare() noexcept { - ready_ = true; - nameToIndex_.reindex(); -} - -void RawPropsParser::preparse(const RawProps& rawProps) const noexcept { - const size_t keyCount = keys_.size(); - rawProps.keyIndexToValueIndex_.resize(keyCount, kRawPropsValueIndexEmpty); - - // Resetting the cursor, the next increment will give `0`. - rawProps.keyIndexCursor_ = static_cast(keyCount - 1); - - // If the Props constructor doesn't use ::at at all, we might be - // able to skip this entirely (in those cases, the Props struct probably - // uses setProp instead). - if (keyCount == 0) { - return; - } - - switch (rawProps.mode_) { - case RawProps::Mode::Empty: - return; - - case RawProps::Mode::JSI: { - auto& runtime = *rawProps.runtime_; - if (!rawProps.value_.isObject()) { - LOG(ERROR) << "Preparse props: rawProps value is not object"; - } - react_native_assert(rawProps.value_.isObject()); - auto object = rawProps.value_.asObject(runtime); - - auto names = object.getPropertyNames(runtime); - auto count = names.size(runtime); - auto valueIndex = RawPropsValueIndex{0}; - - for (size_t i = 0; i < count; i++) { - auto nameValue = names.getValueAtIndex(runtime, i).getString(runtime); - auto value = object.getProperty(runtime, nameValue); - - auto name = nameValue.utf8(runtime); - - auto keyIndex = nameToIndex_.at( - name.data(), static_cast(name.size())); - - if (keyIndex == kRawPropsValueIndexEmpty) { - continue; - } - - rawProps.keyIndexToValueIndex_[keyIndex] = valueIndex; - rawProps.values_.push_back( - RawValue(jsi::dynamicFromValue(runtime, value))); - valueIndex++; - } - - break; - } - - case RawProps::Mode::Dynamic: { - const auto& dynamic = rawProps.dynamic_; - auto valueIndex = RawPropsValueIndex{0}; - - for (const auto& pair : dynamic.items()) { - auto name = pair.first.getString(); - - auto keyIndex = nameToIndex_.at( - name.data(), static_cast(name.size())); - - if (keyIndex == kRawPropsValueIndexEmpty) { - continue; - } - - rawProps.keyIndexToValueIndex_[keyIndex] = valueIndex; - rawProps.values_.push_back(RawValue{pair.second}); - valueIndex++; - } - break; - } - } -} - -/** - * To be used by RawProps only. Value iterator functions. - */ -void RawPropsParser::iterateOverValues( - const RawProps& rawProps, - const std::function< - void(RawPropsPropNameHash, const char*, RawValue const&)>& visit) - const { - switch (rawProps.mode_) { - case RawProps::Mode::Empty: - return; - - case RawProps::Mode::JSI: { - auto& runtime = *rawProps.runtime_; - if (!rawProps.value_.isObject()) { - LOG(ERROR) << "Preparse props: rawProps value is not object"; - } - react_native_assert(rawProps.value_.isObject()); - auto object = rawProps.value_.asObject(runtime); - - auto names = object.getPropertyNames(runtime); - auto count = names.size(runtime); - - for (size_t i = 0; i < count; i++) { - auto nameValue = names.getValueAtIndex(runtime, i).getString(runtime); - auto value = object.getProperty(runtime, nameValue); - - auto name = nameValue.utf8(runtime); - - auto nameHash = RAW_PROPS_KEY_HASH(name); - auto rawValue = RawValue(jsi::dynamicFromValue(runtime, value)); - - visit(nameHash, name.c_str(), rawValue); - } - - break; - } - - case RawProps::Mode::Dynamic: { - const auto& dynamic = rawProps.dynamic_; - - for (const auto& pair : dynamic.items()) { - auto name = pair.first.getString(); - - auto nameHash = RAW_PROPS_KEY_HASH(name); - auto rawValue = RawValue{pair.second}; - visit(nameHash, name.c_str(), rawValue); - } - break; - } - } -} - -} // namespace facebook::react diff --git a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/propsConversions.h b/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/propsConversions.h deleted file mode 100644 index 76a383110cb..00000000000 --- a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/propsConversions.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and 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 -#include -#include -#include -#include - -namespace facebook::react { - -/** - * Use this only when a prop update has definitely been sent from JS; - * essentially, cases where rawValue is virtually guaranteed to not be a - * nullptr. - */ -template -void fromRawValue( - const PropsParserContext& context, - const RawValue& rawValue, - T& result, - T defaultValue) { - if (!rawValue.hasValue()) { - result = std::move(defaultValue); - return; - } - - fromRawValue(context, rawValue, result); -} - -template -void fromRawValue( - const PropsParserContext& context, - const RawValue& rawValue, - T& result) { - result = (T)rawValue; -} - -template -void fromRawValue( - const PropsParserContext& context, - const RawValue& rawValue, - std::optional& result) { - T resultValue; - fromRawValue(context, rawValue, resultValue); - result = std::optional{std::move(resultValue)}; -} - -template -void fromRawValue( - const PropsParserContext& context, - const RawValue& rawValue, - std::vector& result) { - if (rawValue.hasType>()) { - auto items = (std::vector)rawValue; - auto length = items.size(); - result.clear(); - result.reserve(length); - for (size_t i = 0; i < length; i++) { - T itemResult; - fromRawValue(context, items.at(i), itemResult); - result.push_back(itemResult); - } - return; - } - - // The case where `value` is not an array. - result.clear(); - result.reserve(1); - T itemResult; - fromRawValue(context, rawValue, itemResult); - result.push_back(itemResult); -} - -template -void fromRawValue( - const PropsParserContext& context, - const RawValue& rawValue, - std::vector>& result) { - if (rawValue.hasType>>()) { - auto items = (std::vector>)rawValue; - auto length = items.size(); - result.clear(); - result.reserve(length); - for (int i = 0; i < length; i++) { - T itemResult; - fromRawValue(context, items.at(i), itemResult); - result.push_back(itemResult); - } - return; - } - - // The case where `value` is not an array. - result.clear(); - result.reserve(1); - T itemResult; - fromRawValue(context, rawValue, itemResult); - result.push_back(itemResult); -} - -template -T convertRawProp( - const PropsParserContext& context, - const RawProps& rawProps, - const char* name, - T const& sourceValue, - U const& defaultValue, - const char* namePrefix = nullptr, - const char* nameSuffix = nullptr) { - const auto* rawValue = rawProps.at(name, namePrefix, nameSuffix); - // [Windows c++20 fix #12195 - if (LIKELY(rawValue == nullptr)) { - // Windows] - return sourceValue; - } - - // Special case: `null` always means "the prop was removed, use default - // value". - // [Windows c++20 fix #12195 - if (UNLIKELY(!rawValue->hasValue())) { - // Windows] - return defaultValue; - } - - try { - T result; - fromRawValue(context, *rawValue, result); - return result; - } catch (const std::exception& e) { - // In case of errors, log the error and fall back to the default - RawPropsKey key{namePrefix, name, nameSuffix}; - // TODO: report this using ErrorUtils so it's more visible to the user - LOG(ERROR) << "Error while converting prop '" - << static_cast(key) << "': " << e.what(); - return defaultValue; - } -} - -} // namespace facebook::react \ No newline at end of file diff --git a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/config/Config.h b/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/config/Config.h deleted file mode 100644 index 344d3d1d178..00000000000 --- a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/config/Config.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and 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 -#include -#include -#include - -// Tag struct used to form the opaque YGConfigRef for the public C API -struct YGConfig {}; - -namespace facebook::yoga { - -class Config; -class Node; - -using ExperimentalFeatureSet = std::bitset()>; - -// Whether moving a node from an old to new config should dirty previously -// calculated layout results. -bool configUpdateInvalidatesLayout( - const Config& oldConfig, - const Config& newConfig); - -class YG_EXPORT Config : public ::YGConfig { - public: - Config(YGLogger logger); - - void setUseWebDefaults(bool useWebDefaults); - bool useWebDefaults() const; - - void setShouldPrintTree(bool printTree); - bool shouldPrintTree() const; - - void setExperimentalFeatureEnabled(ExperimentalFeature feature, bool enabled); - bool isExperimentalFeatureEnabled(ExperimentalFeature feature) const; - ExperimentalFeatureSet getEnabledExperiments() const; - - void setErrata(Errata errata); - void addErrata(Errata errata); - void removeErrata(Errata errata); - Errata getErrata() const; - bool hasErrata(Errata errata) const; - - void setPointScaleFactor(float pointScaleFactor); - float getPointScaleFactor() const; - - void setContext(void* context); - void* getContext() const; - - void setLogger(YGLogger logger); - void log( - const yoga::Node* node, - LogLevel logLevel, - const char* format, - va_list args) const; - - void setCloneNodeCallback(YGCloneNodeFunc cloneNode); - YGNodeRef - cloneNode(YGNodeConstRef node, YGNodeConstRef owner, size_t childIndex) const; - - static const Config& getDefault(); - - private: - YGCloneNodeFunc cloneNodeCallback_; - YGLogger logger_; - - bool useWebDefaults_ = false; - bool printTree_ = false; - - ExperimentalFeatureSet experimentalFeatures_{}; - Errata errata_ = Errata::None; - float pointScaleFactor_ = 1.0f; - void* context_ = nullptr; -}; - -inline Config* resolveRef(const YGConfigRef ref) { - return static_cast(ref); -} - -inline const Config* resolveRef(const YGConfigConstRef ref) { - return static_cast(ref); -} - -} // namespace facebook::yoga diff --git a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/enums/YogaEnums.h b/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/enums/YogaEnums.h deleted file mode 100644 index afc1b5f5e05..00000000000 --- a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/enums/YogaEnums.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and 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 - -namespace facebook::yoga { - -template -constexpr inline int32_t ordinalCount(); - -/** - * Count of bits needed to represent every ordinal - */ -template -constexpr inline int32_t bitCount(); - -/** - * Polyfill of C++ 23 to_underlying() - * https://en.cppreference.com/w/cpp/utility/to_underlying - */ -template -constexpr auto to_underlying(T e) noexcept { - return static_cast>(e); -} - -/** - * Convenience function to iterate through every value in a Yoga enum as part of - * a range-based for loop. - */ -template -auto ordinals() { - struct Iterator { - EnumT e{}; - - EnumT operator*() const { - return e; - } - - Iterator& operator++() { - e = static_cast(to_underlying(e) + 1); - return *this; - } - - // [Windows C++20 fix ##12195 - bool operator==(const Iterator& other) const { - return e == other.e; - } - - bool operator!=(const Iterator& other) const { - return e != other.e; - } - // Windows] - }; - - struct Range { - Iterator begin() const { - return Iterator{}; - } - Iterator end() const { - return Iterator{static_cast(ordinalCount())}; - } - }; - - return Range{}; -} - -} // namespace facebook::yoga diff --git a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/node/LayoutResults.h b/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/node/LayoutResults.h deleted file mode 100644 index 6975fcf0768..00000000000 --- a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/node/LayoutResults.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and 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 -#include -#include -#include -#include -#include - -namespace facebook::yoga { - -struct LayoutResults { - - // [Windows C++20 fix #12195 - LayoutResults() : direction_(Direction::Inherit), hadOverflow_(false) {} - // Windows] - - // This value was chosen based on empirical data: - // 98% of analyzed layouts require less than 8 entries. - static constexpr int32_t MaxCachedMeasurements = 8; - - uint32_t computedFlexBasisGeneration = 0; - FloatOptional computedFlexBasis = {}; - - // Instead of recomputing the entire layout every single time, we cache some - // information to break early when nothing changed - uint32_t generationCount = 0; - Direction lastOwnerDirection = Direction::Inherit; - - uint32_t nextCachedMeasurementsIndex = 0; - std::array cachedMeasurements = {}; - - CachedMeasurement cachedLayout{}; - - Direction direction() const { - return direction_; - } - - void setDirection(Direction direction) { - direction_ = direction; - } - - bool hadOverflow() const { - return hadOverflow_; - } - - void setHadOverflow(bool hadOverflow) { - hadOverflow_ = hadOverflow; - } - - float dimension(Dimension axis) const { - return dimensions_[yoga::to_underlying(axis)]; - } - - void setDimension(Dimension axis, float dimension) { - dimensions_[yoga::to_underlying(axis)] = dimension; - } - - float measuredDimension(Dimension axis) const { - return measuredDimensions_[yoga::to_underlying(axis)]; - } - - void setMeasuredDimension(Dimension axis, float dimension) { - measuredDimensions_[yoga::to_underlying(axis)] = dimension; - } - - float position(Edge cardinalEdge) const { - assertCardinalEdge(cardinalEdge); - return position_[yoga::to_underlying(cardinalEdge)]; - } - - void setPosition(Edge cardinalEdge, float dimension) { - assertCardinalEdge(cardinalEdge); - position_[yoga::to_underlying(cardinalEdge)] = dimension; - } - - float margin(Edge cardinalEdge) const { - assertCardinalEdge(cardinalEdge); - return margin_[yoga::to_underlying(cardinalEdge)]; - } - - void setMargin(Edge cardinalEdge, float dimension) { - assertCardinalEdge(cardinalEdge); - margin_[yoga::to_underlying(cardinalEdge)] = dimension; - } - - float border(Edge cardinalEdge) const { - assertCardinalEdge(cardinalEdge); - return border_[yoga::to_underlying(cardinalEdge)]; - } - - void setBorder(Edge cardinalEdge, float dimension) { - assertCardinalEdge(cardinalEdge); - border_[yoga::to_underlying(cardinalEdge)] = dimension; - } - - float padding(Edge cardinalEdge) const { - assertCardinalEdge(cardinalEdge); - return padding_[yoga::to_underlying(cardinalEdge)]; - } - - void setPadding(Edge cardinalEdge, float dimension) { - assertCardinalEdge(cardinalEdge); - padding_[yoga::to_underlying(cardinalEdge)] = dimension; - } - - bool operator==(LayoutResults layout) const; - bool operator!=(LayoutResults layout) const { - return !(*this == layout); - } - - private: - static inline void assertCardinalEdge(Edge edge) { - assertFatal( - static_cast(edge) <= 3, "Edge must be top/left/bottom/right"); - } - - // [Windows c++20 fix #12195 - Direction direction_ : bitCount(); - bool hadOverflow_ : 1; - // Windows] - - std::array dimensions_ = {{YGUndefined, YGUndefined}}; - std::array measuredDimensions_ = {{YGUndefined, YGUndefined}}; - std::array position_ = {}; - std::array margin_ = {}; - std::array border_ = {}; - std::array padding_ = {}; -}; - -} // namespace facebook::yoga \ No newline at end of file diff --git a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/numeric/Comparison.h b/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/numeric/Comparison.h deleted file mode 100644 index 22b2dcd8316..00000000000 --- a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/numeric/Comparison.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and 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 -#include - -#include - -namespace facebook::yoga { - -template -constexpr bool isUndefined(T value) { - return value != value; -} - -// [Windows c++20 fix #12195] -template -constexpr bool isDefined(T value) { - return !isUndefined(value); -} - -template -constexpr auto maxOrDefined(T a, T b) { - if (yoga::isDefined(a) && yoga::isDefined(b)) { - return std::max(a, b); - } - return yoga::isUndefined(a) ? b : a; -} - -template -constexpr auto minOrDefined(T a, T b) { - if (yoga::isDefined(a) && yoga::isDefined(b)) { - return std::min(a, b); - } - - return yoga::isUndefined(a) ? b : a; -} - -// Custom equality functions using a hardcoded epsilon of 0.0001f, or returning -// true if both floats are NaN. -inline bool inexactEquals(float a, float b) { - if (yoga::isDefined(a) && yoga::isDefined(b)) { - return std::abs(a - b) < 0.0001f; - } - return yoga::isUndefined(a) && yoga::isUndefined(b); -} - -inline bool inexactEquals(double a, double b) { - if (yoga::isDefined(a) && yoga::isDefined(b)) { - return std::abs(a - b) < 0.0001; - } - return yoga::isUndefined(a) && yoga::isUndefined(b); -} - -inline bool inexactEquals(const YGValue& a, const YGValue& b) { - if (a.unit != b.unit) { - return false; - } - - if (a.unit == YGUnitUndefined || - (yoga::isUndefined(a.value) && yoga::isUndefined(b.value))) { - return true; - } - - return fabs(a.value - b.value) < 0.0001f; -} - -template -bool inexactEquals( - const std::array& val1, - const std::array& val2) { - bool areEqual = true; - for (std::size_t i = 0; i < Size && areEqual; ++i) { - areEqual = inexactEquals(val1[i], val2[i]); - } - return areEqual; -} - -} // namespace facebook::yoga diff --git a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/style/Style.h b/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/style/Style.h deleted file mode 100644 index 95750aaa6d9..00000000000 --- a/vnext/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/style/Style.h +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and 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 -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace facebook::yoga { - -class YG_EXPORT Style { - public: - /** - * Style::Length represents a CSS Value which may be one of: - * 1. Undefined - * 2. A keyword (e.g. auto) - * 3. A CSS value: - * a. value (e.g. 10px) - * b. value of a reference - * 4. (soon) A math function which returns a value - * - * References: - * 1. https://www.w3.org/TR/css-values-4/#lengths - * 2. https://www.w3.org/TR/css-values-4/#percentage-value - * 3. https://www.w3.org/TR/css-values-4/#mixed-percentages - * 4. https://www.w3.org/TR/css-values-4/#math - */ - using Length = CompactValue; - - static constexpr float DefaultFlexGrow = 0.0f; - static constexpr float DefaultFlexShrink = 0.0f; - static constexpr float WebDefaultFlexShrink = 1.0f; - - // [Windows C++20 fix #12195 - Style() : direction_(Direction::Inherit), flexDirection_(FlexDirection::Column), justifyContent_(Justify::FlexStart), - alignContent_(Align::FlexStart), alignItems_(Align::Stretch), alignSelf_(Align::Auto), positionType_(PositionType::Relative), flexWrap_(Wrap::NoWrap), overflow_(Overflow::Visible), - display_(Display::Flex) {} - // Windows] - - - Direction direction() const { - return direction_; - } - void setDirection(Direction value) { - direction_ = value; - } - - FlexDirection flexDirection() const { - return flexDirection_; - } - void setFlexDirection(FlexDirection value) { - flexDirection_ = value; - } - - Justify justifyContent() const { - return justifyContent_; - } - void setJustifyContent(Justify value) { - justifyContent_ = value; - } - - Align alignContent() const { - return alignContent_; - } - void setAlignContent(Align value) { - alignContent_ = value; - } - - Align alignItems() const { - return alignItems_; - } - void setAlignItems(Align value) { - alignItems_ = value; - } - - Align alignSelf() const { - return alignSelf_; - } - void setAlignSelf(Align value) { - alignSelf_ = value; - } - - PositionType positionType() const { - return positionType_; - } - void setPositionType(PositionType value) { - positionType_ = value; - } - - Wrap flexWrap() const { - return flexWrap_; - } - void setFlexWrap(Wrap value) { - flexWrap_ = value; - } - - Overflow overflow() const { - return overflow_; - } - void setOverflow(Overflow value) { - overflow_ = value; - } - - Display display() const { - return display_; - } - void setDisplay(Display value) { - display_ = value; - } - - FloatOptional flex() const { - return flex_; - } - void setFlex(FloatOptional value) { - flex_ = value; - } - - FloatOptional flexGrow() const { - return flexGrow_; - } - void setFlexGrow(FloatOptional value) { - flexGrow_ = value; - } - - FloatOptional flexShrink() const { - return flexShrink_; - } - void setFlexShrink(FloatOptional value) { - flexShrink_ = value; - } - - Style::Length flexBasis() const { - return flexBasis_; - } - void setFlexBasis(Style::Length value) { - flexBasis_ = value; - } - - Style::Length margin(Edge edge) const { - return margin_[yoga::to_underlying(edge)]; - } - void setMargin(Edge edge, Style::Length value) { - margin_[yoga::to_underlying(edge)] = value; - } - - Style::Length position(Edge edge) const { - return position_[yoga::to_underlying(edge)]; - } - void setPosition(Edge edge, Style::Length value) { - position_[yoga::to_underlying(edge)] = value; - } - - Style::Length padding(Edge edge) const { - return padding_[yoga::to_underlying(edge)]; - } - void setPadding(Edge edge, Style::Length value) { - padding_[yoga::to_underlying(edge)] = value; - } - - Style::Length border(Edge edge) const { - return border_[yoga::to_underlying(edge)]; - } - void setBorder(Edge edge, Style::Length value) { - border_[yoga::to_underlying(edge)] = value; - } - - Style::Length gap(Gutter gutter) const { - return gap_[yoga::to_underlying(gutter)]; - } - void setGap(Gutter gutter, Style::Length value) { - gap_[yoga::to_underlying(gutter)] = value; - } - - Style::Length dimension(Dimension axis) const { - return dimensions_[yoga::to_underlying(axis)]; - } - void setDimension(Dimension axis, Style::Length value) { - dimensions_[yoga::to_underlying(axis)] = value; - } - - Style::Length minDimension(Dimension axis) const { - return minDimensions_[yoga::to_underlying(axis)]; - } - void setMinDimension(Dimension axis, Style::Length value) { - minDimensions_[yoga::to_underlying(axis)] = value; - } - - Style::Length maxDimension(Dimension axis) const { - return maxDimensions_[yoga::to_underlying(axis)]; - } - void setMaxDimension(Dimension axis, Style::Length value) { - maxDimensions_[yoga::to_underlying(axis)] = value; - } - - FloatOptional aspectRatio() const { - return aspectRatio_; - } - void setAspectRatio(FloatOptional value) { - aspectRatio_ = value; - } - - Length resolveColumnGap() const { - if (gap_[yoga::to_underlying(Gutter::Column)].isDefined()) { - return gap_[yoga::to_underlying(Gutter::Column)]; - } else { - return gap_[yoga::to_underlying(Gutter::All)]; - } - } - - Style::Length resolveRowGap() const { - if (gap_[yoga::to_underlying(Gutter::Row)].isDefined()) { - return gap_[yoga::to_underlying(Gutter::Row)]; - } else { - return gap_[yoga::to_underlying(Gutter::All)]; - } - } - - bool operator==(const Style& other) const { - return direction_ == other.direction_ && - flexDirection_ == other.flexDirection_ && - justifyContent_ == other.justifyContent_ && - alignContent_ == other.alignContent_ && - alignItems_ == other.alignItems_ && alignSelf_ == other.alignSelf_ && - positionType_ == other.positionType_ && flexWrap_ == other.flexWrap_ && - overflow_ == other.overflow_ && display_ == other.display_ && - inexactEquals(flex_, other.flex_) && - inexactEquals(flexGrow_, other.flexGrow_) && - inexactEquals(flexShrink_, other.flexShrink_) && - inexactEquals(flexBasis_, other.flexBasis_) && - inexactEquals(margin_, other.margin_) && - inexactEquals(position_, other.position_) && - inexactEquals(padding_, other.padding_) && - inexactEquals(border_, other.border_) && - inexactEquals(gap_, other.gap_) && - inexactEquals(dimensions_, other.dimensions_) && - inexactEquals(minDimensions_, other.minDimensions_) && - inexactEquals(maxDimensions_, other.maxDimensions_) && - inexactEquals(aspectRatio_, other.aspectRatio_); - } - - bool operator!=(const Style& other) const { - return !(*this == other); - } - - private: - using Dimensions = std::array()>; - using Edges = std::array()>; - using Gutters = std::array()>; - - // [Window C++20 fix #12195 - Direction direction_ : bitCount(); - FlexDirection flexDirection_ : bitCount(); - Justify justifyContent_ : bitCount(); - Align alignContent_ : bitCount(); - Align alignItems_ : bitCount(); - Align alignSelf_ : bitCount(); - PositionType positionType_: bitCount(); - Wrap flexWrap_ : bitCount(); - Overflow overflow_ : bitCount(); - Display display_ : bitCount(); - // Windows] - - FloatOptional flex_{}; - FloatOptional flexGrow_{}; - FloatOptional flexShrink_{}; - Style::Length flexBasis_{value::ofAuto()}; - Edges margin_{}; - Edges position_{}; - Edges padding_{}; - Edges border_{}; - Gutters gap_{}; - Dimensions dimensions_{value::ofAuto(), value::ofAuto()}; - Dimensions minDimensions_{}; - Dimensions maxDimensions_{}; - FloatOptional aspectRatio_{}; -}; - -} // namespace facebook::yoga diff --git a/vnext/overrides.json b/vnext/overrides.json index e659786059d..f6419d1ef79 100644 --- a/vnext/overrides.json +++ b/vnext/overrides.json @@ -133,13 +133,6 @@ "baseHash": "11de652e153bff8c42cc0e2bbf209c762ed3b314", "issue": 12195 }, - { - "type": "patch", - "file": "ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/RawPropsParser.cpp", - "baseFile": "packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp", - "baseHash": "79fc21a9ad5ba440186d970c44021e25928b6f79", - "issue": 12300 - }, { "type": "patch", "file": "ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/mapbuffer/MapBufferBuilder.cpp", @@ -161,27 +154,6 @@ "baseHash": "9210ab2289dbe492ead3e3506f080290cd9fa26b", "issue": 12195 }, - { - "type": "patch", - "file": "ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/config/Config.h", - "baseFile": "packages/react-native/ReactCommon/yoga/yoga/config/Config.h", - "baseHash": "c01a9fd4408d1df6419197990a4000a09d28bf52", - "issue": 12195 - }, - { - "type": "patch", - "file": "ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/enums/YogaEnums.h", - "baseFile": "packages/react-native/ReactCommon/yoga/yoga/enums/YogaEnums.h", - "baseHash": "25adf2469465bb27ea1b5c41901ff8642b4b4896", - "issue": 12195 - }, - { - "type": "patch", - "file": "ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/node/LayoutResults.h", - "baseFile": "packages/react-native/ReactCommon/yoga/yoga/node/LayoutResults.h", - "baseHash": "f0a011a4eb145be9d85a01746d70ca2a6bfe66d1", - "issue": 12195 - }, { "type": "patch", "file": "ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/node/Node.h", @@ -189,20 +161,6 @@ "baseHash": "aaf16b9303a01ca3dc4955061d97ef9577d8b5e7", "issue": 12195 }, - { - "type": "patch", - "file": "ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/numeric/Comparison.h", - "baseFile": "packages/react-native/ReactCommon/yoga/yoga/numeric/Comparison.h", - "baseHash": "c4150273aa8ab23568f31365cd678b9967521362", - "issue": 12195 - }, - { - "type": "patch", - "file": "ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/style/Style.h", - "baseFile": "packages/react-native/ReactCommon/yoga/yoga/style/Style.h", - "baseHash": "97d57900ffa9a3ade3f3278811d07f267e48f706", - "issue": 12195 - }, { "type": "copy", "directory": "ReactCopies/IntegrationTests",