mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-06 09:13:27 +08:00
Fabric: Introducing LocalData concept
Summary: LocalData might be used to communicate some infomation between `ShadowNode`s and native component views. We will use it soon to store (and transmit to mounting layer) prepared for rendering attributed text in Text component. Reviewed By: mdvacca Differential Revision: D7738582 fbshipit-source-id: 1ead23ffd105cce0b3d9aeb9fc1d0df47673be50
This commit is contained in:
committed by
Facebook Github Bot
parent
9d08e2afae
commit
368388bfc8
@@ -150,3 +150,32 @@ TEST(ShadowNodeTest, handleCloneFunction) {
|
||||
ASSERT_EQ(secondNode->getRootTag(), secondNodeClone->getRootTag());
|
||||
ASSERT_EQ(secondNode->getProps(), secondNodeClone->getProps());
|
||||
}
|
||||
|
||||
TEST(ShadowNodeTest, handleLocalData) {
|
||||
auto localData42 = std::make_shared<TestLocalData>();
|
||||
localData42->setNumber(42);
|
||||
|
||||
auto anotherLocalData42 = std::make_shared<TestLocalData>();
|
||||
anotherLocalData42->setNumber(42);
|
||||
|
||||
auto localDataOver9000 = std::make_shared<TestLocalData>();
|
||||
localDataOver9000->setNumber(9001);
|
||||
|
||||
auto firstNode = std::make_shared<TestShadowNode>(9, 1, (void *)NULL);
|
||||
auto secondNode = std::make_shared<TestShadowNode>(9, 1, (void *)NULL);
|
||||
auto thirdNode = std::make_shared<TestShadowNode>(9, 1, (void *)NULL);
|
||||
|
||||
firstNode->setLocalData(localData42);
|
||||
secondNode->setLocalData(localData42);
|
||||
thirdNode->setLocalData(localDataOver9000);
|
||||
|
||||
// LocalData object are compared by pointer, not by value.
|
||||
ASSERT_EQ(*firstNode, *secondNode);
|
||||
ASSERT_NE(*firstNode, *thirdNode);
|
||||
secondNode->setLocalData(anotherLocalData42);
|
||||
ASSERT_NE(*firstNode, *secondNode);
|
||||
|
||||
// LocalData cannot be changed for sealed shadow node.
|
||||
secondNode->sealRecursive();
|
||||
ASSERT_ANY_THROW(secondNode->setLocalData(localDataOver9000));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user