@@ -828,6 +828,82 @@ using FontScaledTextShadowNode =
828828using FontScaledInputShadowNode =
829829 FontScaledShadowNode<FontScaledInputComponentName, false >;
830830
831+ // NOLINTNEXTLINE(modernize-avoid-c-arrays)
832+ static const char SourceComparingComponentName[] = " SourceComparing" ;
833+
834+ /*
835+ * A measurable leaf that keeps its measurement when cloned with the props of
836+ * the revision it is cloned from.
837+ */
838+ class SourceComparingShadowNode final
839+ : public ConcreteViewShadowNode<SourceComparingComponentName> {
840+ public:
841+ using Base = ConcreteViewShadowNode<SourceComparingComponentName>;
842+ using Base::Base;
843+
844+ static ShadowNodeTraits BaseTraits () {
845+ auto traits = Base::BaseTraits ();
846+ traits.set (ShadowNodeTraits::Trait::LeafYogaNode);
847+ traits.set (ShadowNodeTraits::Trait::MeasurableYogaNode);
848+ return traits;
849+ }
850+
851+ protected:
852+ bool shouldNewRevisionDirtyMeasurement (
853+ const ShadowNode& sourceShadowNode,
854+ const ShadowNodeFragment& /* fragment*/ ) const override {
855+ return sourceShadowNode.getProps () != getProps ();
856+ }
857+ };
858+
859+ TEST (ViewTest, completeCloneAsksWhetherToDirtyAgainstTheSourceRevision) {
860+ ComponentDescriptorProviderRegistry providerRegistry{};
861+ auto registry = providerRegistry.createComponentDescriptorRegistry (
862+ ComponentDescriptorParameters{
863+ .eventDispatcher = EventDispatcher::Shared{},
864+ .contextContainer = nullptr ,
865+ .flavor = nullptr });
866+ providerRegistry.add (
867+ concreteComponentDescriptorProvider<RootComponentDescriptor>());
868+ providerRegistry.add (
869+ concreteComponentDescriptorProvider<
870+ ConcreteComponentDescriptor<SourceComparingShadowNode>>());
871+ auto builder = ComponentBuilder{registry};
872+
873+ auto rootShadowNode = std::shared_ptr<RootShadowNode>{};
874+ auto leafShadowNode = std::shared_ptr<SourceComparingShadowNode>{};
875+
876+ // clang-format off
877+ auto element =
878+ Element<RootShadowNode>()
879+ .reference (rootShadowNode)
880+ .tag (1 )
881+ .children ({
882+ Element<SourceComparingShadowNode>()
883+ .reference (leafShadowNode)
884+ .tag (2 )
885+ });
886+ // clang-format on
887+
888+ builder.build (element);
889+ EXPECT_TRUE (rootShadowNode->layoutIfNeeded ());
890+ ASSERT_TRUE (leafShadowNode->getIsLayoutClean ());
891+
892+ auto cloneWithSourceProps = leafShadowNode->clone ({});
893+ EXPECT_TRUE (
894+ static_cast <const YogaLayoutableShadowNode&>(*cloneWithSourceProps)
895+ .getIsLayoutClean ());
896+
897+ // New non-layout props leave the Yoga style as it was, so only the
898+ // comparison with the source revision can dirty the clone.
899+ auto viewProps = std::make_shared<ViewProps>();
900+ viewProps->opacity = 0.5 ;
901+ auto cloneWithNewProps = leafShadowNode->clone ({.props = viewProps});
902+ EXPECT_FALSE (
903+ static_cast <const YogaLayoutableShadowNode&>(*cloneWithNewProps)
904+ .getIsLayoutClean ());
905+ }
906+
831907// `ModalHostViewShadowNode` needs JNI to create its initial state on Android.
832908#ifndef ANDROID
833909class FontScaleLayoutTest : public ::testing::Test {
0 commit comments