diff --git a/ReactCommon/fabric/attributedstring/AttributedString.cpp b/ReactCommon/fabric/attributedstring/AttributedString.cpp index ab4965d62..196b52983 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.cpp +++ b/ReactCommon/fabric/attributedstring/AttributedString.cpp @@ -15,6 +15,30 @@ namespace react { using Fragment = AttributedString::Fragment; using Fragments = AttributedString::Fragments; +#pragma mark - Fragment + +bool Fragment::operator==(const Fragment &rhs) const { + return + std::tie( + string, + textAttributes, + shadowNode, + parentShadowNode + ) == + std::tie( + rhs.string, + rhs.textAttributes, + rhs.shadowNode, + rhs.parentShadowNode + ); +} + +bool Fragment::operator!=(const Fragment &rhs) const { + return !(*this == rhs); +} + +#pragma mark - AttributedString + void AttributedString::appendFragment(const Fragment &fragment) { ensureUnsealed(); fragments_.push_back(fragment); @@ -47,6 +71,14 @@ std::string AttributedString::getString() const { return string; } +bool AttributedString::operator==(const AttributedString &rhs) const { + return fragments_ != rhs.fragments_; +} + +bool AttributedString::operator!=(const AttributedString &rhs) const { + return !(*this == rhs); +} + #pragma mark - DebugStringConvertible SharedDebugStringConvertibleList AttributedString::getDebugChildren() const { diff --git a/ReactCommon/fabric/attributedstring/AttributedString.h b/ReactCommon/fabric/attributedstring/AttributedString.h index 5966da17b..2f37b725b 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.h +++ b/ReactCommon/fabric/attributedstring/AttributedString.h @@ -35,11 +35,15 @@ class AttributedString: public: class Fragment { + public: std::string string; TextAttributes textAttributes; SharedShadowNode shadowNode; SharedShadowNode parentShadowNode; + + bool operator==(const Fragment &rhs) const; + bool operator!=(const Fragment &rhs) const; }; using Fragments = std::vector; @@ -67,6 +71,9 @@ public: */ std::string getString() const; + bool operator==(const AttributedString &rhs) const; + bool operator!=(const AttributedString &rhs) const; + #pragma mark - DebugStringConvertible SharedDebugStringConvertibleList getDebugChildren() const override; diff --git a/ReactCommon/fabric/attributedstring/TextAttributes.cpp b/ReactCommon/fabric/attributedstring/TextAttributes.cpp index ed038a5f0..8ce27505c 100644 --- a/ReactCommon/fabric/attributedstring/TextAttributes.cpp +++ b/ReactCommon/fabric/attributedstring/TextAttributes.cpp @@ -53,6 +53,66 @@ void TextAttributes::apply(TextAttributes textAttributes) { layoutDirection = textAttributes.layoutDirection.hasValue() ? textAttributes.layoutDirection : layoutDirection; } +#pragma mark - Operators + +bool TextAttributes::operator==(const TextAttributes &rhs) const { + return + std::tie( + foregroundColor, + backgroundColor, + opacity, + fontFamily, + fontSize, + fontSizeMultiplier, + fontWeight, + fontStyle, + fontVariant, + allowFontScaling, + letterSpacing, + lineHeight, + alignment, + baseWritingDirection, + textDecorationColor, + textDecorationLineType, + textDecorationLineStyle, + textDecorationLinePattern, + textShadowOffset, + textShadowRadius, + textShadowColor, + isHighlighted, + layoutDirection + ) == + std::tie( + rhs.foregroundColor, + rhs.backgroundColor, + rhs.opacity, + rhs.fontFamily, + rhs.fontSize, + rhs.fontSizeMultiplier, + rhs.fontWeight, + rhs.fontStyle, + rhs.fontVariant, + rhs.allowFontScaling, + rhs.letterSpacing, + rhs.lineHeight, + rhs.alignment, + rhs.baseWritingDirection, + rhs.textDecorationColor, + rhs.textDecorationLineType, + rhs.textDecorationLineStyle, + rhs.textDecorationLinePattern, + rhs.textShadowOffset, + rhs.textShadowRadius, + rhs.textShadowColor, + rhs.isHighlighted, + rhs.layoutDirection + ); +} + +bool TextAttributes::operator!=(const TextAttributes &rhs) const { + return !(*this == rhs); +} + #pragma mark - DebugStringConvertible SharedDebugStringConvertibleList TextAttributes::getDebugProps() const { diff --git a/ReactCommon/fabric/attributedstring/TextAttributes.h b/ReactCommon/fabric/attributedstring/TextAttributes.h index cd6ef6ab8..4881df667 100644 --- a/ReactCommon/fabric/attributedstring/TextAttributes.h +++ b/ReactCommon/fabric/attributedstring/TextAttributes.h @@ -70,6 +70,11 @@ public: void apply(TextAttributes textAttributes); +#pragma mark - Operators + + bool operator==(const TextAttributes &rhs) const; + bool operator!=(const TextAttributes &rhs) const; + #pragma mark - DebugStringConvertible SharedDebugStringConvertibleList getDebugProps() const override;