Skip to content

Commit bae63d4

Browse files
rozelefacebook-github-bot
authored andcommitted
Break circular dependency between renderer/core and renderer/components/view (#38637)
Summary: Pull Request resolved: #38637 ComponentDescriptor and ConcreteComponentDescriptor expose a virtual method to interpolate props for LayoutAnimation. The implementation of this virtual method in ConcreteComponentDescriptor calls ViewPropsInterpolation, creating a circular dependency between react/renderer/core and react/renderer/components/view. To break this circular dependency, this change lifts the props interpolation functionality out of ComponentDescriptor into LayoutAnimationKeyFrameManager. Please note, while this is technically a "breaking" change, as component descriptors for 3p components may have overridden this method, it's not supported because LayoutAnimation only works on View props. ## Changelog: [General] [Breaking] - Remove interpolateProps functionality from ComponentDescriptor to fix circular dependency between react/renderer/core and react/renderer/components/view Reviewed By: christophpurrer Differential Revision: D47797967 fbshipit-source-id: 5285da7cc9de29f21ce14c96b850a3c58c579e94
1 parent 3d2fd4b commit bae63d4

File tree

4 files changed

+46
-37
lines changed

4 files changed

+46
-37
lines changed

packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
2020
#include <react/renderer/components/image/ImageProps.h>
2121
#include <react/renderer/components/view/ViewProps.h>
22+
#include <react/renderer/components/view/ViewPropsInterpolation.h>
2223
#include <react/renderer/core/ComponentDescriptor.h>
2324
#include <react/renderer/core/LayoutMetrics.h>
2425
#include <react/renderer/core/Props.h>
@@ -1152,8 +1153,13 @@ ShadowView LayoutAnimationKeyFrameManager::createInterpolatedShadowView(
11521153
// Animate opacity or scale/transform
11531154
PropsParserContext propsParserContext{
11541155
finalView.surfaceId, *contextContainer_};
1155-
mutatedShadowView.props = componentDescriptor.interpolateProps(
1156-
propsParserContext, progress, startingView.props, finalView.props);
1156+
mutatedShadowView.props = interpolateProps(
1157+
componentDescriptor,
1158+
propsParserContext,
1159+
progress,
1160+
startingView.props,
1161+
finalView.props);
1162+
11571163
react_native_assert(mutatedShadowView.props != nullptr);
11581164
if (mutatedShadowView.props == nullptr) {
11591165
return finalView;
@@ -1656,4 +1662,32 @@ void LayoutAnimationKeyFrameManager::deleteAnimationsForStoppedSurfaces()
16561662
}
16571663
}
16581664

1665+
Props::Shared LayoutAnimationKeyFrameManager::interpolateProps(
1666+
const ComponentDescriptor &componentDescriptor,
1667+
const PropsParserContext &context,
1668+
Float animationProgress,
1669+
const Props::Shared &props,
1670+
const Props::Shared &newProps) const {
1671+
#ifdef ANDROID
1672+
// On Android only, the merged props should have the same RawProps as the
1673+
// final props struct
1674+
Props::Shared interpolatedPropsShared =
1675+
(newProps != nullptr
1676+
? componentDescriptor.cloneProps(
1677+
context, newProps, newProps->rawProps)
1678+
: componentDescriptor.cloneProps(context, newProps, {}));
1679+
#else
1680+
Props::Shared interpolatedPropsShared =
1681+
componentDescriptor.cloneProps(context, newProps, {});
1682+
#endif
1683+
1684+
if (componentDescriptor.getTraits().check(
1685+
ShadowNodeTraits::Trait::ViewKind)) {
1686+
interpolateViewProps(
1687+
animationProgress, props, newProps, interpolatedPropsShared);
1688+
}
1689+
1690+
return interpolatedPropsShared;
1691+
};
1692+
16591693
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate,
173173

174174
void simulateImagePropsMemoryAccess(
175175
ShadowViewMutationList const &mutations) const;
176+
177+
/**
178+
* Interpolates the props values.
179+
*/
180+
Props::Shared interpolateProps(
181+
const ComponentDescriptor &componentDescriptor,
182+
const PropsParserContext &context,
183+
Float animationProgress,
184+
const Props::Shared &props,
185+
const Props::Shared &newProps) const;
176186
};
177187

178188
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/core/ComponentDescriptor.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,6 @@ class ComponentDescriptor {
108108
const Props::Shared &props,
109109
const RawProps &rawProps) const = 0;
110110

111-
/*
112-
* Creates a new `Props` of a particular type with all values interpolated
113-
* between `props` and `newProps`.
114-
*/
115-
virtual Props::Shared interpolateProps(
116-
const PropsParserContext &context,
117-
Float animationProgress,
118-
const Props::Shared &props,
119-
const Props::Shared &newProps) const = 0;
120-
121111
/*
122112
* Create an initial State object that represents (and contains) an initial
123113
* State's data which can be constructed based on initial Props.

packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <memory>
1212

1313
#include <react/debug/react_native_assert.h>
14-
#include <react/renderer/components/view/ViewPropsInterpolation.h>
1514
#include <react/renderer/core/ComponentDescriptor.h>
1615
#include <react/renderer/core/EventDispatcher.h>
1716
#include <react/renderer/core/Props.h>
@@ -125,30 +124,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
125124
return shadowNodeProps;
126125
};
127126

128-
Props::Shared interpolateProps(
129-
const PropsParserContext &context,
130-
Float animationProgress,
131-
const Props::Shared &props,
132-
const Props::Shared &newProps) const override {
133-
#ifdef ANDROID
134-
// On Android only, the merged props should have the same RawProps as the
135-
// final props struct
136-
Props::Shared interpolatedPropsShared =
137-
(newProps != nullptr ? cloneProps(context, newProps, newProps->rawProps)
138-
: cloneProps(context, newProps, {}));
139-
#else
140-
Props::Shared interpolatedPropsShared = cloneProps(context, newProps, {});
141-
#endif
142-
143-
if (ConcreteShadowNode::BaseTraits().check(
144-
ShadowNodeTraits::Trait::ViewKind)) {
145-
interpolateViewProps(
146-
animationProgress, props, newProps, interpolatedPropsShared);
147-
}
148-
149-
return interpolatedPropsShared;
150-
};
151-
152127
virtual State::Shared createInitialState(
153128
Props::Shared const &props,
154129
ShadowNodeFamily::Shared const &family) const override {

0 commit comments

Comments
 (0)