diff --git a/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h b/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h index 9a0f627b70e342..640342d1965ff5 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h @@ -101,9 +101,10 @@ class ConcreteState : public State { return getData().getDynamic(); } - void updateState(folly::dynamic data) const override { - updateState(std::move(Data(getData(), data))); + void updateState(folly::dynamic &&data) const override { + updateState(Data(getData(), std::move(data))); } + MapBuffer getMapBuffer() const override { return getData().getMapBuffer(); } diff --git a/packages/react-native/ReactCommon/react/renderer/core/State.h b/packages/react-native/ReactCommon/react/renderer/core/State.h index d29558d96ea9e5..23932be1b4a8c3 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/State.h +++ b/packages/react-native/ReactCommon/react/renderer/core/State.h @@ -67,7 +67,7 @@ class State { #ifdef ANDROID virtual folly::dynamic getDynamic() const = 0; virtual MapBuffer getMapBuffer() const = 0; - virtual void updateState(folly::dynamic data) const = 0; + virtual void updateState(folly::dynamic &&data) const = 0; #endif protected: diff --git a/packages/react-native/ReactCommon/react/renderer/core/tests/ShadowNodeTest.cpp b/packages/react-native/ReactCommon/react/renderer/core/tests/ShadowNodeTest.cpp index 7a403ede529d5f..65e6705cb582a5 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/tests/ShadowNodeTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/tests/ShadowNodeTest.cpp @@ -221,9 +221,11 @@ TEST_F(ShadowNodeTest, handleCloneFunction) { // Those two nodes are *not* same. EXPECT_NE(nodeAB_, nodeABClone); +#ifndef ANDROID // `secondNodeClone` is an instance of `TestShadowNode`. EXPECT_NE( std::dynamic_pointer_cast(nodeABClone), nullptr); +#endif // Both nodes have same content. EXPECT_EQ(nodeAB_->getTag(), nodeABClone->getTag()); @@ -244,13 +246,9 @@ TEST_F(ShadowNodeTest, handleState) { auto traits = TestShadowNode::BaseTraits(); auto props = std::make_shared(); - auto fragment = ShadowNodeFragment{ - /* .props = */ props, - /* .children = */ ShadowNode::emptySharedShadowNodeSharedList(), - /* .state = */ {}}; auto const initialState = - componentDescriptor_.createInitialState(fragment, family); + componentDescriptor_.createInitialState(props, family); auto firstNode = std::make_shared( ShadowNodeFragment{ @@ -277,18 +275,18 @@ TEST_F(ShadowNodeTest, handleState) { TestShadowNode::ConcreteState::Shared _state = std::static_pointer_cast( initialState); - _state->updateState(TestState{42}); + _state->updateState(TestState()); - thirdNode->setStateData({9001}); + thirdNode->setStateData(TestState()); // State object are compared by pointer, not by value. EXPECT_EQ(firstNode->getState(), secondNode->getState()); EXPECT_NE(firstNode->getState(), thirdNode->getState()); - secondNode->setStateData(TestState{42}); + secondNode->setStateData(TestState()); EXPECT_NE(firstNode->getState(), secondNode->getState()); // State cannot be changed for sealed shadow node. secondNode->sealRecursive(); EXPECT_DEATH_IF_SUPPORTED( - { secondNode->setStateData(TestState{42}); }, + { secondNode->setStateData(TestState()); }, "Attempt to mutate a sealed object."); } diff --git a/packages/react-native/ReactCommon/react/renderer/core/tests/TestComponent.h b/packages/react-native/ReactCommon/react/renderer/core/tests/TestComponent.h index a0c97b9c320b2b..f740e365ef177f 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/tests/TestComponent.h +++ b/packages/react-native/ReactCommon/react/renderer/core/tests/TestComponent.h @@ -18,6 +18,12 @@ #include #include +#ifdef ANDROID +#include +#include +#include +#endif + /** * This defines a set of TestComponent classes: Props, ShadowNode, * ComponentDescriptor. To be used for testing purpose. @@ -25,9 +31,20 @@ namespace facebook::react { -class TestState { - public: - int number; +struct TestState { + TestState() = default; + +#ifdef ANDROID + TestState(TestState const &previousState, folly::dynamic &&data){}; + + folly::dynamic getDynamic() const { + return {}; + } + + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + } +#endif }; static const char TestComponentName[] = "Test"; diff --git a/packages/react-native/ReactCommon/react/renderer/templateprocessor/tests/UITemplateProcessorTest.cpp b/packages/react-native/ReactCommon/react/renderer/templateprocessor/tests/UITemplateProcessorTest.cpp index 66de70df621b3b..21e8111da3936e 100644 --- a/packages/react-native/ReactCommon/react/renderer/templateprocessor/tests/UITemplateProcessorTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/templateprocessor/tests/UITemplateProcessorTest.cpp @@ -104,13 +104,13 @@ TEST(UITemplateProcessorTest, testSimpleBytecode) { #ifndef NDEBUG LOG(INFO) << std::endl << root1->getDebugDescription(); #endif - auto props1 = std::dynamic_pointer_cast(root1->getProps()); + auto props1 = std::static_pointer_cast(root1->getProps()); EXPECT_NEAR(props1->opacity, 0.5, 0.001); ASSERT_STREQ(props1->testId.c_str(), "root"); auto children1 = root1->getChildren(); EXPECT_EQ(children1.size(), 1); auto child_props1 = - std::dynamic_pointer_cast(children1.at(0)->getProps()); + std::static_pointer_cast(children1.at(0)->getProps()); ASSERT_STREQ(child_props1->testId.c_str(), "child"); } @@ -143,12 +143,12 @@ TEST(UITemplateProcessorTest, testConditionalBytecode) { #ifndef NDEBUG LOG(INFO) << std::endl << root1->getDebugDescription(); #endif - auto props1 = std::dynamic_pointer_cast(root1->getProps()); + auto props1 = std::static_pointer_cast(root1->getProps()); ASSERT_STREQ(props1->testId.c_str(), "root"); auto children1 = root1->getChildren(); EXPECT_EQ(children1.size(), 1); auto child_props1 = - std::dynamic_pointer_cast(children1.at(0)->getProps()); + std::static_pointer_cast(children1.at(0)->getProps()); ASSERT_STREQ(child_props1->testId.c_str(), "cond_true"); mockSimpleTestValue_ = false; @@ -160,7 +160,7 @@ TEST(UITemplateProcessorTest, testConditionalBytecode) { *componentDescriptorRegistry, nativeModuleRegistry, mockReactNativeConfig_); - auto child_props2 = std::dynamic_pointer_cast( + auto child_props2 = std::static_pointer_cast( root2->getChildren().at(0)->getProps()); ASSERT_STREQ(child_props2->testId.c_str(), "cond_false"); }