Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ void AttributedString::prependAttributedString(
attributedString.fragments_.end());
}

void AttributedString::setBaseTextAttributes(
const TextAttributes& defaultAttributes) {
baseAttributes_ = defaultAttributes;
}

const Fragments& AttributedString::getFragments() const {
return fragments_;
}
Expand All @@ -107,6 +112,10 @@ std::string AttributedString::getString() const {
return string;
}

const TextAttributes& AttributedString::getBaseTextAttributes() const {
return baseAttributes_;
}

bool AttributedString::isEmpty() const {
return fragments_.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class AttributedString : public Sealable, public DebugStringConvertible {
void appendAttributedString(const AttributedString& attributedString);
void prependAttributedString(const AttributedString& attributedString);

/*
* Sets attributes which would apply to hypothetical text not included in the
* AttributedString.
*/
void setBaseTextAttributes(const TextAttributes& defaultAttributes);

/*
* Returns a read-only reference to a list of fragments.
*/
Expand All @@ -90,6 +96,8 @@ class AttributedString : public Sealable, public DebugStringConvertible {
*/
std::string getString() const;

const TextAttributes& getBaseTextAttributes() const;

/*
* Returns `true` if the string is empty (has no any fragments).
*/
Expand All @@ -113,6 +121,7 @@ class AttributedString : public Sealable, public DebugStringConvertible {

private:
Fragments fragments_;
TextAttributes baseAttributes_;
};

} // namespace facebook::react
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,7 @@ constexpr static MapBuffer::Key AS_KEY_HASH = 0;
constexpr static MapBuffer::Key AS_KEY_STRING = 1;
constexpr static MapBuffer::Key AS_KEY_FRAGMENTS = 2;
constexpr static MapBuffer::Key AS_KEY_CACHE_ID = 3;
constexpr static MapBuffer::Key AS_KEY_BASE_ATTRIBUTES = 4;

// constants for Fragment serialization
constexpr static MapBuffer::Key FR_KEY_STRING = 0;
Expand Down Expand Up @@ -1117,6 +1118,9 @@ inline MapBuffer toMapBuffer(const AttributedString& attributedString) {
// TODO: This truncates half the hash
builder.putInt(AS_KEY_HASH, static_cast<int>(hash));
builder.putString(AS_KEY_STRING, attributedString.getString());
builder.putMapBuffer(
AS_KEY_BASE_ATTRIBUTES,
toMapBuffer(attributedString.getBaseTextAttributes()));
auto fragmentsMap = fragmentsBuilder.build();
builder.putMapBuffer(AS_KEY_FRAGMENTS, fragmentsMap);
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const Content& ParagraphShadowNode::getContent(
auto attributedString = AttributedString{};
auto attachments = Attachments{};
buildAttributedString(textAttributes, *this, attributedString, attachments);
attributedString.setBaseTextAttributes(textAttributes);

content_ = Content{
attributedString, getConcreteProps().paragraphAttributes, attachments};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ AttributedString AndroidTextInputShadowNode::getAttributedString() const {
auto attachments = BaseTextShadowNode::Attachments{};
BaseTextShadowNode::buildAttributedString(
childTextAttributes, *this, attributedString, attachments);
attributedString.setBaseTextAttributes(childTextAttributes);

// BaseTextShadowNode only gets children. We must detect and prepend text
// value attributes manually.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ AttributedString TextInputShadowNode::getAttributedString(
auto attachments = Attachments{};
BaseTextShadowNode::buildAttributedString(
textAttributes, *this, attributedString, attachments);
attributedString.setBaseTextAttributes(textAttributes);

return attributedString;
}
Expand Down