diff --git a/ReactAndroid/src/main/jni/react/fabric/viewPropConversions.h b/ReactAndroid/src/main/jni/react/fabric/viewPropConversions.h index 6e05d0afb35b19..1c05d7973fb8ec 100644 --- a/ReactAndroid/src/main/jni/react/fabric/viewPropConversions.h +++ b/ReactAndroid/src/main/jni/react/fabric/viewPropConversions.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp b/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp index cec544ea1f76c0..2994acac6122a0 100644 --- a/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp +++ b/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp @@ -8,8 +8,8 @@ #include "ParagraphAttributes.h" #include +#include #include -#include #include namespace facebook::react { diff --git a/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp b/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp index 63b5a4aab19fce..2112a70a3d2019 100644 --- a/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp +++ b/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include diff --git a/ReactCommon/react/renderer/attributedstring/conversions.h b/ReactCommon/react/renderer/attributedstring/conversions.h index 367afbfc30007d..8687b892204da2 100644 --- a/ReactCommon/react/renderer/attributedstring/conversions.h +++ b/ReactCommon/react/renderer/attributedstring/conversions.h @@ -19,8 +19,8 @@ #include #include #include +#include #include -#include #include #ifdef ANDROID diff --git a/ReactCommon/react/renderer/attributedstring/tests/AttributedStringTest.cpp b/ReactCommon/react/renderer/attributedstring/tests/AttributedStringTest.cpp index 63991131325fd6..466c76f97372ed 100644 --- a/ReactCommon/react/renderer/attributedstring/tests/AttributedStringTest.cpp +++ b/ReactCommon/react/renderer/attributedstring/tests/AttributedStringTest.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace facebook { namespace react { diff --git a/ReactCommon/react/renderer/attributedstring/tests/TextAttributesTest.cpp b/ReactCommon/react/renderer/attributedstring/tests/TextAttributesTest.cpp index c753b00d67ac48..fdb3251de55a1a 100644 --- a/ReactCommon/react/renderer/attributedstring/tests/TextAttributesTest.cpp +++ b/ReactCommon/react/renderer/attributedstring/tests/TextAttributesTest.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace facebook { namespace react { diff --git a/ReactCommon/react/renderer/components/image/conversions.h b/ReactCommon/react/renderer/components/image/conversions.h index c466702c0a43c6..d2c8e499ee7d3f 100644 --- a/ReactCommon/react/renderer/components/image/conversions.h +++ b/ReactCommon/react/renderer/components/image/conversions.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include namespace facebook { diff --git a/ReactCommon/react/renderer/components/inputaccessory/InputAccessoryState.h b/ReactCommon/react/renderer/components/inputaccessory/InputAccessoryState.h index 15843aa341e52d..81cfdd387e5a40 100644 --- a/ReactCommon/react/renderer/components/inputaccessory/InputAccessoryState.h +++ b/ReactCommon/react/renderer/components/inputaccessory/InputAccessoryState.h @@ -7,8 +7,8 @@ #pragma once +#include #include -#include namespace facebook { namespace react { diff --git a/ReactCommon/react/renderer/components/modal/ModalHostViewState.h b/ReactCommon/react/renderer/components/modal/ModalHostViewState.h index f25d1a5e88d476..dd5f7a5a40029d 100644 --- a/ReactCommon/react/renderer/components/modal/ModalHostViewState.h +++ b/ReactCommon/react/renderer/components/modal/ModalHostViewState.h @@ -7,8 +7,8 @@ #pragma once +#include #include -#include #ifdef ANDROID #include diff --git a/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp b/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp index ef2cee93e9f0e6..e60623e4900e02 100644 --- a/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp +++ b/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp @@ -9,8 +9,8 @@ #include #include +#include #include -#include #include diff --git a/ReactCommon/react/renderer/components/text/BaseTextProps.cpp b/ReactCommon/react/renderer/components/text/BaseTextProps.cpp index e098e7beab2404..d83b9f73188d89 100644 --- a/ReactCommon/react/renderer/components/text/BaseTextProps.cpp +++ b/ReactCommon/react/renderer/components/text/BaseTextProps.cpp @@ -9,9 +9,9 @@ #include #include +#include #include #include -#include namespace facebook::react { diff --git a/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp b/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp index 7e6de53abce9fc..fd74bff32a8175 100644 --- a/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp +++ b/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp @@ -8,8 +8,8 @@ #include "AndroidTextInputProps.h" #include #include +#include #include -#include namespace facebook::react { diff --git a/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputProps.cpp b/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputProps.cpp index dad0ea7f8ad803..5b1c867c19d2cb 100644 --- a/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputProps.cpp +++ b/ReactCommon/react/renderer/components/textinput/iostextinput/react/renderer/components/iostextinput/TextInputProps.cpp @@ -9,8 +9,8 @@ #include #include +#include #include -#include namespace facebook::react { diff --git a/ReactCommon/react/renderer/components/view/ViewProps.cpp b/ReactCommon/react/renderer/components/view/ViewProps.cpp index f97a0560f61dd5..6e08ced4990d60 100644 --- a/ReactCommon/react/renderer/components/view/ViewProps.cpp +++ b/ReactCommon/react/renderer/components/view/ViewProps.cpp @@ -12,9 +12,9 @@ #include #include #include +#include #include #include -#include namespace facebook::react { diff --git a/ReactCommon/react/renderer/components/view/ViewPropsMapBuffer.cpp b/ReactCommon/react/renderer/components/view/ViewPropsMapBuffer.cpp index 4136842c3b8593..4602fa88f97d26 100644 --- a/ReactCommon/react/renderer/components/view/ViewPropsMapBuffer.cpp +++ b/ReactCommon/react/renderer/components/view/ViewPropsMapBuffer.cpp @@ -12,7 +12,7 @@ #include "viewPropConversions.h" -#include +#include #include namespace facebook { diff --git a/ReactCommon/react/renderer/components/view/viewPropConversions.h b/ReactCommon/react/renderer/components/view/viewPropConversions.h index 64a0469a9f7c8b..a21df7eab053b8 100644 --- a/ReactCommon/react/renderer/components/view/viewPropConversions.h +++ b/ReactCommon/react/renderer/components/view/viewPropConversions.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp b/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp index 900a8c20f06815..87a612befd4fe7 100644 --- a/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp +++ b/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp @@ -12,8 +12,8 @@ #include #include #include +#include #include -#include namespace facebook::react { diff --git a/ReactCommon/react/renderer/core/graphicsConversions.h b/ReactCommon/react/renderer/core/graphicsConversions.h new file mode 100644 index 00000000000000..c142b8e57bf8c0 --- /dev/null +++ b/ReactCommon/react/renderer/core/graphicsConversions.h @@ -0,0 +1,257 @@ +/* + * 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 + +namespace facebook { +namespace react { + +#pragma mark - Color + +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + SharedColor &result) { + ColorComponents colorComponents = {0, 0, 0, 0}; + + if (value.hasType()) { + auto argb = (int64_t)value; + auto ratio = 255.f; + colorComponents.alpha = ((argb >> 24) & 0xFF) / ratio; + colorComponents.red = ((argb >> 16) & 0xFF) / ratio; + colorComponents.green = ((argb >> 8) & 0xFF) / ratio; + colorComponents.blue = (argb & 0xFF) / ratio; + } else if (value.hasType>()) { + auto items = (std::vector)value; + auto length = items.size(); + react_native_expect(length == 3 || length == 4); + colorComponents.red = items.at(0); + colorComponents.green = items.at(1); + colorComponents.blue = items.at(2); + colorComponents.alpha = length == 4 ? items.at(3) : 1.0f; + } else { + colorComponents = parsePlatformColor(context, value); + } + + result = colorFromComponents(colorComponents); +} + +#ifdef ANDROID +inline int toAndroidRepr(const SharedColor &color) { + return *color; +} +#endif + +inline std::string toString(const SharedColor &value) { + ColorComponents components = colorComponentsFromColor(value); + auto ratio = 255.f; + return "rgba(" + folly::to(round(components.red * ratio)) + + ", " + folly::to(round(components.green * ratio)) + ", " + + folly::to(round(components.blue * ratio)) + ", " + + folly::to(round(components.alpha * ratio)) + ")"; +} + +#pragma mark - Geometry + +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + Point &result) { + if (value.hasType>()) { + auto map = (butter::map)value; + for (const auto &pair : map) { + if (pair.first == "x") { + result.x = pair.second; + } else if (pair.first == "y") { + result.y = pair.second; + } + } + return; + } + + react_native_expect(value.hasType>()); + if (value.hasType>()) { + auto array = (std::vector)value; + react_native_expect(array.size() == 2); + if (array.size() >= 2) { + result = {array.at(0), array.at(1)}; + } else { + result = {0, 0}; + LOG(ERROR) << "Unsupported Point vector size: " << array.size(); + } + } else { + LOG(ERROR) << "Unsupported Point type"; + } +} + +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + Size &result) { + if (value.hasType>()) { + auto map = (butter::map)value; + for (const auto &pair : map) { + if (pair.first == "width") { + result.width = pair.second; + } else if (pair.first == "height") { + result.height = pair.second; + } else { + LOG(ERROR) << "Unsupported Size map key: " << pair.first; + react_native_expect(false); + } + } + return; + } + + react_native_expect(value.hasType>()); + if (value.hasType>()) { + auto array = (std::vector)value; + react_native_expect(array.size() == 2); + if (array.size() >= 2) { + result = {array.at(0), array.at(1)}; + } else { + result = {0, 0}; + LOG(ERROR) << "Unsupported Size vector size: " << array.size(); + } + } else { + LOG(ERROR) << "Unsupported Size type"; + } +} + +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + EdgeInsets &result) { + if (value.hasType()) { + auto number = (Float)value; + result = {number, number, number, number}; + return; + } + + if (value.hasType>()) { + auto map = (butter::map)value; + for (const auto &pair : map) { + if (pair.first == "top") { + result.top = pair.second; + } else if (pair.first == "left") { + result.left = pair.second; + } else if (pair.first == "bottom") { + result.bottom = pair.second; + } else if (pair.first == "right") { + result.right = pair.second; + } else { + LOG(ERROR) << "Unsupported EdgeInsets map key: " << pair.first; + react_native_expect(false); + } + } + return; + } + + react_native_expect(value.hasType>()); + if (value.hasType>()) { + auto array = (std::vector)value; + react_native_expect(array.size() == 4); + if (array.size() >= 4) { + result = {array.at(0), array.at(1), array.at(2), array.at(3)}; + } else { + result = {0, 0, 0, 0}; + LOG(ERROR) << "Unsupported EdgeInsets vector size: " << array.size(); + } + } else { + LOG(ERROR) << "Unsupported EdgeInsets type"; + } +} + +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + CornerInsets &result) { + if (value.hasType()) { + auto number = (Float)value; + result = {number, number, number, number}; + return; + } + + if (value.hasType>()) { + auto map = (butter::map)value; + for (const auto &pair : map) { + if (pair.first == "topLeft") { + result.topLeft = pair.second; + } else if (pair.first == "topRight") { + result.topRight = pair.second; + } else if (pair.first == "bottomLeft") { + result.bottomLeft = pair.second; + } else if (pair.first == "bottomRight") { + result.bottomRight = pair.second; + } else { + LOG(ERROR) << "Unsupported CornerInsets map key: " << pair.first; + react_native_expect(false); + } + } + return; + } + + react_native_expect(value.hasType>()); + if (value.hasType>()) { + auto array = (std::vector)value; + react_native_expect(array.size() == 4); + if (array.size() >= 4) { + result = {array.at(0), array.at(1), array.at(2), array.at(3)}; + } else { + LOG(ERROR) << "Unsupported CornerInsets vector size: " << array.size(); + } + } + + // Error case - we should only here if all other supported cases fail + // In dev we would crash on assert before this point + result = {0, 0, 0, 0}; + LOG(ERROR) << "Unsupported CornerInsets type"; +} + +inline std::string toString(const Point &point) { + return "{" + folly::to(point.x) + ", " + + folly::to(point.y) + "}"; +} + +inline std::string toString(const Size &size) { + return "{" + folly::to(size.width) + ", " + + folly::to(size.height) + "}"; +} + +inline std::string toString(const Rect &rect) { + return "{" + toString(rect.origin) + ", " + toString(rect.size) + "}"; +} + +inline std::string toString(const EdgeInsets &edgeInsets) { + return "{" + folly::to(edgeInsets.left) + ", " + + folly::to(edgeInsets.top) + ", " + + folly::to(edgeInsets.right) + ", " + + folly::to(edgeInsets.bottom) + "}"; +} + +inline std::string toString(const CornerInsets &cornerInsets) { + return "{" + folly::to(cornerInsets.topLeft) + ", " + + folly::to(cornerInsets.topRight) + ", " + + folly::to(cornerInsets.bottomLeft) + ", " + + folly::to(cornerInsets.bottomRight) + "}"; +} + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/react/renderer/core/propsConversions.h b/ReactCommon/react/renderer/core/propsConversions.h index 269c64a4ad021f..02d92832218629 100644 --- a/ReactCommon/react/renderer/core/propsConversions.h +++ b/ReactCommon/react/renderer/core/propsConversions.h @@ -13,8 +13,8 @@ #include #include #include +#include #include -#include namespace facebook { namespace react { diff --git a/ReactCommon/react/renderer/graphics/conversions.h b/ReactCommon/react/renderer/graphics/conversions.h index c142b8e57bf8c0..e8a016d8958c22 100644 --- a/ReactCommon/react/renderer/graphics/conversions.h +++ b/ReactCommon/react/renderer/graphics/conversions.h @@ -7,251 +7,21 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace facebook { -namespace react { - -#pragma mark - Color - -inline void fromRawValue( - const PropsParserContext &context, - const RawValue &value, - SharedColor &result) { - ColorComponents colorComponents = {0, 0, 0, 0}; - - if (value.hasType()) { - auto argb = (int64_t)value; - auto ratio = 255.f; - colorComponents.alpha = ((argb >> 24) & 0xFF) / ratio; - colorComponents.red = ((argb >> 16) & 0xFF) / ratio; - colorComponents.green = ((argb >> 8) & 0xFF) / ratio; - colorComponents.blue = (argb & 0xFF) / ratio; - } else if (value.hasType>()) { - auto items = (std::vector)value; - auto length = items.size(); - react_native_expect(length == 3 || length == 4); - colorComponents.red = items.at(0); - colorComponents.green = items.at(1); - colorComponents.blue = items.at(2); - colorComponents.alpha = length == 4 ? items.at(3) : 1.0f; - } else { - colorComponents = parsePlatformColor(context, value); - } - - result = colorFromComponents(colorComponents); -} - -#ifdef ANDROID -inline int toAndroidRepr(const SharedColor &color) { - return *color; -} -#endif - -inline std::string toString(const SharedColor &value) { - ColorComponents components = colorComponentsFromColor(value); - auto ratio = 255.f; - return "rgba(" + folly::to(round(components.red * ratio)) + - ", " + folly::to(round(components.green * ratio)) + ", " + - folly::to(round(components.blue * ratio)) + ", " + - folly::to(round(components.alpha * ratio)) + ")"; -} - -#pragma mark - Geometry - -inline void fromRawValue( - const PropsParserContext &context, - const RawValue &value, - Point &result) { - if (value.hasType>()) { - auto map = (butter::map)value; - for (const auto &pair : map) { - if (pair.first == "x") { - result.x = pair.second; - } else if (pair.first == "y") { - result.y = pair.second; - } - } - return; - } - - react_native_expect(value.hasType>()); - if (value.hasType>()) { - auto array = (std::vector)value; - react_native_expect(array.size() == 2); - if (array.size() >= 2) { - result = {array.at(0), array.at(1)}; - } else { - result = {0, 0}; - LOG(ERROR) << "Unsupported Point vector size: " << array.size(); - } - } else { - LOG(ERROR) << "Unsupported Point type"; - } -} - -inline void fromRawValue( - const PropsParserContext &context, - const RawValue &value, - Size &result) { - if (value.hasType>()) { - auto map = (butter::map)value; - for (const auto &pair : map) { - if (pair.first == "width") { - result.width = pair.second; - } else if (pair.first == "height") { - result.height = pair.second; - } else { - LOG(ERROR) << "Unsupported Size map key: " << pair.first; - react_native_expect(false); - } - } - return; - } - - react_native_expect(value.hasType>()); - if (value.hasType>()) { - auto array = (std::vector)value; - react_native_expect(array.size() == 2); - if (array.size() >= 2) { - result = {array.at(0), array.at(1)}; - } else { - result = {0, 0}; - LOG(ERROR) << "Unsupported Size vector size: " << array.size(); - } - } else { - LOG(ERROR) << "Unsupported Size type"; - } -} - -inline void fromRawValue( - const PropsParserContext &context, - const RawValue &value, - EdgeInsets &result) { - if (value.hasType()) { - auto number = (Float)value; - result = {number, number, number, number}; - return; - } - - if (value.hasType>()) { - auto map = (butter::map)value; - for (const auto &pair : map) { - if (pair.first == "top") { - result.top = pair.second; - } else if (pair.first == "left") { - result.left = pair.second; - } else if (pair.first == "bottom") { - result.bottom = pair.second; - } else if (pair.first == "right") { - result.right = pair.second; - } else { - LOG(ERROR) << "Unsupported EdgeInsets map key: " << pair.first; - react_native_expect(false); - } - } - return; - } - - react_native_expect(value.hasType>()); - if (value.hasType>()) { - auto array = (std::vector)value; - react_native_expect(array.size() == 4); - if (array.size() >= 4) { - result = {array.at(0), array.at(1), array.at(2), array.at(3)}; - } else { - result = {0, 0, 0, 0}; - LOG(ERROR) << "Unsupported EdgeInsets vector size: " << array.size(); - } - } else { - LOG(ERROR) << "Unsupported EdgeInsets type"; - } -} - -inline void fromRawValue( - const PropsParserContext &context, - const RawValue &value, - CornerInsets &result) { - if (value.hasType()) { - auto number = (Float)value; - result = {number, number, number, number}; - return; - } - - if (value.hasType>()) { - auto map = (butter::map)value; - for (const auto &pair : map) { - if (pair.first == "topLeft") { - result.topLeft = pair.second; - } else if (pair.first == "topRight") { - result.topRight = pair.second; - } else if (pair.first == "bottomLeft") { - result.bottomLeft = pair.second; - } else if (pair.first == "bottomRight") { - result.bottomRight = pair.second; - } else { - LOG(ERROR) << "Unsupported CornerInsets map key: " << pair.first; - react_native_expect(false); - } - } - return; - } - - react_native_expect(value.hasType>()); - if (value.hasType>()) { - auto array = (std::vector)value; - react_native_expect(array.size() == 4); - if (array.size() >= 4) { - result = {array.at(0), array.at(1), array.at(2), array.at(3)}; - } else { - LOG(ERROR) << "Unsupported CornerInsets vector size: " << array.size(); - } - } - - // Error case - we should only here if all other supported cases fail - // In dev we would crash on assert before this point - result = {0, 0, 0, 0}; - LOG(ERROR) << "Unsupported CornerInsets type"; -} - -inline std::string toString(const Point &point) { - return "{" + folly::to(point.x) + ", " + - folly::to(point.y) + "}"; -} - -inline std::string toString(const Size &size) { - return "{" + folly::to(size.width) + ", " + - folly::to(size.height) + "}"; -} - -inline std::string toString(const Rect &rect) { - return "{" + toString(rect.origin) + ", " + toString(rect.size) + "}"; -} - -inline std::string toString(const EdgeInsets &edgeInsets) { - return "{" + folly::to(edgeInsets.left) + ", " + - folly::to(edgeInsets.top) + ", " + - folly::to(edgeInsets.right) + ", " + - folly::to(edgeInsets.bottom) + "}"; -} - -inline std::string toString(const CornerInsets &cornerInsets) { - return "{" + folly::to(cornerInsets.topLeft) + ", " + - folly::to(cornerInsets.topRight) + ", " + - folly::to(cornerInsets.bottomLeft) + ", " + - folly::to(cornerInsets.bottomRight) + "}"; -} - -} // namespace react -} // namespace facebook +#include + +// This file belongs to the React-graphics module. +// This file also used to have a reference to two files that are located in the +// react/renderer/core folder. That folder belongs to a module that is called +// React-Fabric. +// The React-Fabric module declares an explicit dependency on +// React-graphics. Including those files in a React-graphics' file created a +// circular dependency because React-Fabric was explicitly depending on +// React-graphics, which was implicitly depending on React-Fabric. We break that +// dependency by moving the old `graphics/conversions.h` file to the +// React-Fabric module and renaming it `core/graphicsConversions.h`. + +#warning \ + "[DEPRECATION] `graphics/conversions.h` is deprecated and will be removed in the future. \ + If this warning appears due to a library, please open an issue in that library, and ask for an update. \ + Please, replace the `#include ` statements \ + with `#include `."