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
This commit is contained in:
Rubén Norte
2023-06-08 14:38:00 -07:00
committed by Facebook GitHub Bot
parent 9bd5591c59
commit a88c0edbd3
9 changed files with 27 additions and 97 deletions
@@ -11,6 +11,7 @@
#include <react/renderer/components/image/ImageProps.h>
#include <react/renderer/components/image/ImageState.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <react/renderer/core/ShadowNodeFamily.h>
#include <react/renderer/imagemanager/ImageManager.h>
#include <react/renderer/imagemanager/primitives.h>
@@ -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};
@@ -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<ScrollViewProps const &>(*props).contentOffset, {}, 0};
}
@@ -12,6 +12,7 @@
#include <react/renderer/components/scrollview/ScrollViewState.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/core/ShadowNodeFamily.h>
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
@@ -160,8 +160,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
return std::make_shared<ConcreteState>(
std::make_shared<ConcreteStateData const>(
ConcreteShadowNode::initialStateData(
props, ShadowNodeFamilyFragment::build(*family), *this)),
ConcreteShadowNode::initialStateData(props, family, *this)),
family);
}
@@ -13,6 +13,7 @@
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/RawProps.h>
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/core/ShadowNodeFamily.h>
#include <react/renderer/core/StateData.h>
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 {};
}
@@ -14,7 +14,6 @@
#include <react/renderer/core/EventEmitter.h>
#include <react/renderer/core/ReactPrimitives.h>
#include <react/renderer/core/ShadowNodeFamilyFragment.h>
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;
/*
@@ -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 <react/renderer/core/ShadowNodeFamily.h>
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
@@ -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 <react/renderer/core/EventEmitter.h>
#include <react/renderer/core/ReactPrimitives.h>
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
@@ -12,7 +12,6 @@
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
#include <react/renderer/core/ComponentDescriptor.h>
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/core/ShadowNodeFamilyFragment.h>
#include <react/renderer/core/ShadowNodeFragment.h>
#include <react/renderer/element/Element.h>