Fabric: Equality operators for AttributedString and derivatives

Summary: We will need this eventually.

Reviewed By: mdvacca

Differential Revision: D9799852

fbshipit-source-id: 0411e2f41540273c80f425e04c877fe51b9b2374
This commit is contained in:
Valentin Shergin 2018-09-14 15:16:59 -07:00 committed by Facebook Github Bot
parent 4eb9b40979
commit e663b1ed59
4 changed files with 104 additions and 0 deletions

View File

@ -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 {

View File

@ -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<Fragment>;
@ -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;

View File

@ -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 {

View File

@ -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;