From a88c0edbd3b152239ce782763918d72ea09e003c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 8 Jun 2023 14:38:00 -0700 Subject: [PATCH] Remove references to ShadowNodeFamilyFragment when not used to create new instances of ShadowNodeFamily (#37772) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37772 Changelog: [internal] `ShadowNodeFragment` is used in multiple places as a general definition for the fragment, but it lacks information that's going to be constructed in the fragment itself in the future (like `eventEmitter` in D46149084). This migrates some of the usages of this fragment to the `ShadowNodeFamily` directly (as they already have access to it). Reviewed By: javache, sammy-SC Differential Revision: D46190382 fbshipit-source-id: 3a879861106594d66a2580410d4d83523c288314 --- .../components/image/ImageShadowNode.h | 3 +- .../scrollview/ScrollViewShadowNode.cpp | 2 +- .../scrollview/ScrollViewShadowNode.h | 3 +- .../core/ConcreteComponentDescriptor.h | 3 +- .../react/renderer/core/ConcreteShadowNode.h | 5 +- .../react/renderer/core/ShadowNodeFamily.h | 20 ++++++- .../core/ShadowNodeFamilyFragment.cpp | 34 ------------ .../renderer/core/ShadowNodeFamilyFragment.h | 53 ------------------- .../react/renderer/element/ComponentBuilder.h | 1 - 9 files changed, 27 insertions(+), 97 deletions(-) delete mode 100644 packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamilyFragment.cpp delete mode 100644 packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamilyFragment.h diff --git a/packages/react-native/ReactCommon/react/renderer/components/image/ImageShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/image/ImageShadowNode.h index be233e807b1..55d56df694b 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/image/ImageShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/image/ImageShadowNode.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -42,7 +43,7 @@ class ImageShadowNode final : public ConcreteViewShadowNode< static ImageState initialStateData( Props::Shared const &props, - ShadowNodeFamilyFragment const &familyFragment, + ShadowNodeFamily::Shared const & /*family*/, ComponentDescriptor const &componentDescriptor) { auto imageSource = ImageSource{ImageSource::Type::Invalid}; return {imageSource, {imageSource, nullptr}, 0}; diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewShadowNode.cpp index 7fe5a502133..d47ec135586 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewShadowNode.cpp @@ -50,7 +50,7 @@ void ScrollViewShadowNode::updateScrollContentOffsetIfNeeded() { ScrollViewState ScrollViewShadowNode::initialStateData( Props::Shared const &props, - const ShadowNodeFamilyFragment & /*familyFragment*/, + const ShadowNodeFamily::Shared & /*family*/, const ComponentDescriptor & /*componentDescriptor*/) { return {static_cast(*props).contentOffset, {}, 0}; } diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewShadowNode.h index 3d2447fe3d9..387a2268719 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewShadowNode.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace facebook::react { @@ -30,7 +31,7 @@ class ScrollViewShadowNode final : public ConcreteViewShadowNode< static ScrollViewState initialStateData( Props::Shared const &props, - ShadowNodeFamilyFragment const &familyFragment, + ShadowNodeFamily::Shared const &family, ComponentDescriptor const &componentDescriptor); #pragma mark - LayoutableShadowNode diff --git a/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h index 6a063b62650..f6fbcb9029e 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h @@ -160,8 +160,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { return std::make_shared( std::make_shared( - ConcreteShadowNode::initialStateData( - props, ShadowNodeFamilyFragment::build(*family), *this)), + ConcreteShadowNode::initialStateData(props, family, *this)), family); } diff --git a/packages/react-native/ReactCommon/react/renderer/core/ConcreteShadowNode.h b/packages/react-native/ReactCommon/react/renderer/core/ConcreteShadowNode.h index b55d30fc4b5..e23a9ae3877 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ConcreteShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ConcreteShadowNode.h @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace facebook::react { @@ -87,8 +88,8 @@ class ConcreteShadowNode : public BaseShadowNodeT { static ConcreteStateData initialStateData( Props::Shared const & /*props*/, - ShadowNodeFamilyFragment const &familyFragment, - ComponentDescriptor const &componentDescriptor) { + ShadowNodeFamily::Shared const & /*family*/, + ComponentDescriptor const & /*componentDescriptor*/) { return {}; } diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h index 09b0300c403..c2220a2e57f 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamily.h @@ -14,7 +14,6 @@ #include #include -#include namespace facebook::react { @@ -22,6 +21,24 @@ class ComponentDescriptor; class ShadowNode; class State; +/* + * This is a collection of fields serving as a specification to create new + * `ShadowNodeFamily` instances. + * + * Do not use this class as a general purpose container to share information + * about a `ShadowNodeFamily`. Pelase define specific purpose containers in + * those cases. + * + * Note: All of the fields are `const &` references (essentially just raw + * pointers) which means that the Fragment does not copy/store them nor + * retain ownership of them. + */ +struct ShadowNodeFamilyFragment { + Tag const tag; + SurfaceId const surfaceId; + EventEmitter::Shared const &eventEmitter; +}; + /* * Represents all things that shadow nodes from the same family have in common. * To be used inside `ShadowNode` class *only*. @@ -96,7 +113,6 @@ class ShadowNodeFamily final { private: friend ShadowNode; - friend ShadowNodeFamilyFragment; friend State; /* diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamilyFragment.cpp b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamilyFragment.cpp deleted file mode 100644 index 3f27ab9bfef..00000000000 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamilyFragment.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "ShadowNodeFamilyFragment.h" - -#include - -namespace facebook::react { - -ShadowNodeFamilyFragment ShadowNodeFamilyFragment::build( - ShadowNodeFamily const &family) { - return { - family.tag_, - family.surfaceId_, - family.eventEmitter_, - }; -} - -using Value = ShadowNodeFamilyFragment::Value; - -Value::Value(ShadowNodeFamilyFragment const &fragment) - : tag(fragment.tag), - surfaceId(fragment.surfaceId), - eventEmitter(fragment.eventEmitter) {} - -Value::operator ShadowNodeFamilyFragment() const { - return ShadowNodeFamilyFragment{tag, surfaceId, eventEmitter}; -} - -} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamilyFragment.h b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamilyFragment.h deleted file mode 100644 index 0de0e60ebe3..00000000000 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFamilyFragment.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -namespace facebook::react { - -class ShadowNodeFamily; - -/* - * Note: All of the fields are `const &` references (essentially just raw - * pointers) which means that the Fragment does not copy/store them nor - * retain ownership of them. - */ -class ShadowNodeFamilyFragment final { - public: - static ShadowNodeFamilyFragment build(ShadowNodeFamily const &family); - - Tag const tag; - SurfaceId const surfaceId; - EventEmitter::Shared const &eventEmitter; - - /* - * `ShadowNodeFamilyFragment` is not owning data-structure, it only stores raw - * pointers to the data. `ShadowNodeFamilyFragment::Value` is a convenient - * owning counterpart of that. - */ - class Value final { - public: - /* - * Creates an object with given `ShadowNodeFragment`. - */ - Value(ShadowNodeFamilyFragment const &fragment); - - /* - * Creates a `ShadowNodeFragment` from the object. - */ - explicit operator ShadowNodeFamilyFragment() const; - - Tag tag; - SurfaceId surfaceId; - EventEmitter::Shared eventEmitter; - }; -}; - -} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/element/ComponentBuilder.h b/packages/react-native/ReactCommon/react/renderer/element/ComponentBuilder.h index 6a0251fab9f..ae082320a84 100644 --- a/packages/react-native/ReactCommon/react/renderer/element/ComponentBuilder.h +++ b/packages/react-native/ReactCommon/react/renderer/element/ComponentBuilder.h @@ -12,7 +12,6 @@ #include #include #include -#include #include #include