Refactor BaseTextShadowNode::getAttributedString to recurse on SharedShadowNode

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
This commit is contained in:
Ramanpreet Nara 2018-09-10 11:19:15 -07:00 committed by Facebook Github Bot
parent 5023b105e4
commit 4a4e083e2a
3 changed files with 5 additions and 5 deletions

View File

@ -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) {
@ -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;
}

View File

@ -25,7 +25,7 @@ public:
*/
AttributedString getAttributedString(
const TextAttributes &baseTextAttributes,
const SharedShadowNodeList &childNodes
const SharedShadowNode &parentNode
) const;
};

View File

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