Skip to content

Commit

Permalink
Refactor BaseTextShadowNode::getAttributedString to recurse on Shared…
Browse files Browse the repository at this point in the history
…ShadowNode

Summary: Previously, `BaseTextShadowNode::getAttributedString` used to recurse on a list of `SharedShadowNode`s (i.e: the children). In the `RawText` base case of this recursion, we'll need to record the parent of the current `RawText` (so that we can dispatch the `onPress` event to it). Therefore, we need to start recursing using the `SharedShadowNode` itself, and not its children.

Reviewed By: shergin

Differential Revision: D9696908

fbshipit-source-id: dbf3f9c21a7ae4de421d0355c4e5900b3947dc2a
  • Loading branch information
RSNara authored and facebook-github-bot committed Sep 10, 2018
1 parent 5023b10 commit 4a4e083
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace react {

AttributedString BaseTextShadowNode::getAttributedString(
const TextAttributes &textAttributes,
const SharedShadowNodeList &childNodes
const SharedShadowNode &parentNode
) const {
AttributedString attributedString;

for (const auto &childNode : childNodes) {
for (const auto &childNode : parentNode->getChildren()) {
// RawShadowNode
auto rawTextShadowNode = std::dynamic_pointer_cast<const RawTextShadowNode>(childNode);
if (rawTextShadowNode) {
Expand All @@ -38,7 +38,7 @@ AttributedString BaseTextShadowNode::getAttributedString(
if (textShadowNode) {
TextAttributes localTextAttributes = textAttributes;
localTextAttributes.apply(textShadowNode->getProps()->textAttributes);
attributedString.appendAttributedString(textShadowNode->getAttributedString(localTextAttributes, textShadowNode->getChildren()));
attributedString.appendAttributedString(textShadowNode->getAttributedString(localTextAttributes, textShadowNode));
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BaseTextShadowNode {
*/
AttributedString getAttributedString(
const TextAttributes &baseTextAttributes,
const SharedShadowNodeList &childNodes
const SharedShadowNode &parentNode
) const;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const char ParagraphComponentName[] = "Paragraph";
AttributedString ParagraphShadowNode::getAttributedString() const {
if (!cachedAttributedString_.has_value()) {
cachedAttributedString_ =
BaseTextShadowNode::getAttributedString(getProps()->textAttributes, getChildren());
BaseTextShadowNode::getAttributedString(getProps()->textAttributes, shared_from_this());
}

return cachedAttributedString_.value();
Expand Down

0 comments on commit 4a4e083

Please sign in to comment.