diff --git a/ReactCommon/fabric/attributedstring/AttributedString.h b/ReactCommon/fabric/attributedstring/AttributedString.h index 2f37b725bc..ecd6289f6b 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.h +++ b/ReactCommon/fabric/attributedstring/AttributedString.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include @@ -85,3 +86,29 @@ private: } // namespace react } // namespace facebook + +namespace std { + template <> + struct hash { + size_t operator()(const facebook::react::AttributedString::Fragment &fragment) const { + return + std::hash{}(fragment.string) + + std::hash{}(fragment.textAttributes) + + std::hash{}(fragment.shadowNode) + + std::hash{}(fragment.parentShadowNode); + } + }; + + template <> + struct hash { + size_t operator()(const facebook::react::AttributedString &attributedString) const { + auto result = size_t {0}; + + for (const auto &fragment : attributedString.getFragments()) { + result += std::hash{}(fragment); + } + + return result; + } + }; +} // namespace std diff --git a/ReactCommon/fabric/attributedstring/TextAttributes.h b/ReactCommon/fabric/attributedstring/TextAttributes.h index 4881df6670..d14d1f0bc5 100644 --- a/ReactCommon/fabric/attributedstring/TextAttributes.h +++ b/ReactCommon/fabric/attributedstring/TextAttributes.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include @@ -83,3 +84,34 @@ public: } // namespace react } // namespace facebook +namespace std { + template <> + struct hash { + size_t operator()(const facebook::react::TextAttributes &textAttributes) const { + return + std::hash{}(textAttributes.foregroundColor) + + std::hash{}(textAttributes.backgroundColor) + + std::hash{}(textAttributes.opacity) + + std::hash{}(textAttributes.fontFamily) + + std::hash{}(textAttributes.fontSize) + + std::hash{}(textAttributes.fontSizeMultiplier) + + std::hash{}(textAttributes.fontWeight) + + std::hash{}(textAttributes.fontStyle) + + std::hash{}(textAttributes.fontVariant) + + std::hash{}(textAttributes.allowFontScaling) + + std::hash{}(textAttributes.letterSpacing) + + std::hash{}(textAttributes.lineHeight) + + std::hash{}(textAttributes.alignment) + + std::hash{}(textAttributes.baseWritingDirection) + + std::hash{}(textAttributes.textDecorationColor) + + std::hash{}(textAttributes.textDecorationLineType) + + std::hash{}(textAttributes.textDecorationLineStyle) + + std::hash{}(textAttributes.textDecorationLinePattern) + + std::hash{}(textAttributes.textShadowOffset) + + std::hash{}(textAttributes.textShadowRadius) + + std::hash{}(textAttributes.textShadowColor) + + std::hash{}(textAttributes.isHighlighted) + + std::hash{}(textAttributes.layoutDirection); + } + }; +} // namespace std diff --git a/ReactCommon/fabric/graphics/Geometry.h b/ReactCommon/fabric/graphics/Geometry.h index b75bcb5d0f..1600780eca 100644 --- a/ReactCommon/fabric/graphics/Geometry.h +++ b/ReactCommon/fabric/graphics/Geometry.h @@ -6,6 +6,7 @@ #pragma once #include +#include #include #include @@ -177,3 +178,55 @@ using CornerInsets = RectangleCorners; } // namespace react } // namespace facebook + +namespace std { + template <> + struct hash { + size_t operator()(const facebook::react::Point &point) const { + return + hash{}(point.x) + + hash{}(point.y); + } + }; + + template <> + struct hash { + size_t operator()(const facebook::react::Size &size) const { + return + hash{}(size.width) + + hash{}(size.height); + } + }; + + template <> + struct hash { + size_t operator()(const facebook::react::Rect &rect) const { + return + hash{}(rect.origin) + + hash{}(rect.size); + } + }; + + template + struct hash> { + size_t operator()(const facebook::react::RectangleEdges &edges) const { + return + hash{}(edges.left) + + hash{}(edges.right) + + hash{}(edges.top) + + hash{}(edges.bottom); + } + }; + + template + struct hash> { + size_t operator()(const facebook::react::RectangleCorners &corners) const { + return + hash{}(corners.topLeft) + + hash{}(corners.bottomLeft) + + hash{}(corners.topRight) + + hash{}(corners.bottomRight); + } + }; + +} // namespace std