Fabric: Using ShadowView instad of ShadowNode inside AttributedString

Summary:
That's generally better because:
 * Avoids exposing ShadowNode to mounting layer;
 * Enables hashing and comparing the AttributedString based on actual meaningful data (not on just a pointer to ShadowNode).

Reviewed By: mdvacca

Differential Revision: D13205230

fbshipit-source-id: 7b79c1aad97b10d81e3faa10408be61b74f815cf
This commit is contained in:
Valentin Shergin
2018-11-27 18:29:39 -08:00
committed by Facebook Github Bot
parent 6c3b05f343
commit 7197aa026b
6 changed files with 21 additions and 26 deletions

View File

@@ -12,6 +12,7 @@
#include <react/components/text/TextProps.h>
#include <react/components/text/TextShadowNode.h>
#include <react/debug/DebugStringConvertibleItem.h>
#include <react/mounting/ShadowView.h>
namespace facebook {
namespace react {
@@ -34,10 +35,7 @@ AttributedString BaseTextShadowNode::getAttributedString(
// `attributedString` causes a retain cycle (besides that fact that we
// don't need it at all). Storing a `ShadowView` instance instead of
// `ShadowNode` should properly fix this problem.
fragment.parentShadowNode =
std::dynamic_pointer_cast<const TextShadowNode>(parentNode)
? parentNode
: nullptr;
fragment.parentShadowView = ShadowView(*parentNode);
attributedString.appendFragment(fragment);
continue;
}
@@ -56,7 +54,7 @@ AttributedString BaseTextShadowNode::getAttributedString(
// Any other kind of ShadowNode
auto fragment = AttributedString::Fragment{};
fragment.shadowNode = childNode;
fragment.shadowView = ShadowView(*childNode);
fragment.textAttributes = textAttributes;
attributedString.appendFragment(fragment);
}