Skip to content

Commit 8f2e981

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Remove hard-coded component name listing for Props 2.0 support testing (#51633)
Summary: Pull Request resolved: #51633 To fully support props diffing for a component, the component's Props implementation needs to implement the prop diffing for the derived class. Because all Props classes extend the ViewProps, all Props classes implement the `getDiffProps` function. To support testing that the props diffing implementation support all properties of the derived Props class for the component being mounted, this diff adds the virtual function `getDiffPropsImplementationTarget` which returns the `ComponentName` that the `getDiffProps` function supports. This removes the need for a hard-coded list of components that support props diffing and enables the use of codegen to conditionally enable props diffing. Changelog: [Internal] Reviewed By: javache Differential Revision: D75465020 fbshipit-source-id: 2850a76f1036cfe930c3c69b98d478ef86a2d457
1 parent 3903ce0 commit 8f2e981

16 files changed

Lines changed: 43 additions & 7 deletions

File tree

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,9 @@ jni::local_ref<jobject> getProps(
223223
auto* oldProps = oldShadowView.props.get();
224224
auto* newProps = newShadowView.props.get();
225225
if ((ReactNativeFeatureFlags::enablePropsUpdateReconciliationAndroid()) &&
226-
(strcmp(newShadowView.componentName, "View") == 0 ||
227-
strcmp(newShadowView.componentName, "Image") == 0 ||
228-
strcmp(newShadowView.componentName, "ScrollView") == 0 ||
229-
strcmp(newShadowView.componentName, "RawText") == 0 ||
230-
strcmp(newShadowView.componentName, "Text") == 0 ||
231-
strcmp(newShadowView.componentName, "Paragraph") == 0 ||
232-
strcmp(newShadowView.componentName, "TextInput") == 0)) {
226+
strcmp(
227+
newShadowView.componentName,
228+
newProps->getDiffPropsImplementationTarget()) == 0) {
233229
return ReadableNativeMap::newObjectCxxArgs(
234230
newProps->getDiffProps(oldProps));
235231
}

packages/react-native/ReactCommon/react/renderer/components/image/ImageProps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ static folly::dynamic convertEdgeInsets(const EdgeInsets& edgeInsets) {
185185
return edgeInsetsResult;
186186
}
187187

188+
ComponentName ImageProps::getDiffPropsImplementationTarget() const {
189+
return "Image";
190+
}
191+
188192
folly::dynamic ImageProps::getDiffProps(const Props* prevProps) const {
189193
static const auto defaultProps = ImageProps();
190194

packages/react-native/ReactCommon/react/renderer/components/image/ImageProps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class ImageProps final : public ViewProps {
4747
bool progressiveRenderingEnabled{};
4848

4949
#ifdef RN_SERIALIZABLE_STATE
50+
ComponentName getDiffPropsImplementationTarget() const override;
5051
folly::dynamic getDiffProps(const Props* prevProps) const override;
5152
#endif
5253
};

packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/android/react/renderer/components/scrollview/HostPlatformScrollViewProps.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ static folly::dynamic convertPoint(const Point& point) {
106106
return pointResult;
107107
}
108108

109+
ComponentName HostPlatformScrollViewProps::getDiffPropsImplementationTarget()
110+
const {
111+
return "ScrollView";
112+
}
113+
109114
folly::dynamic HostPlatformScrollViewProps::getDiffProps(
110115
const Props* prevProps) const {
111116
static const auto defaultProps = HostPlatformScrollViewProps();

packages/react-native/ReactCommon/react/renderer/components/scrollview/platform/android/react/renderer/components/scrollview/HostPlatformScrollViewProps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class HostPlatformScrollViewProps final : public BaseScrollViewProps {
3939
SharedDebugStringConvertibleList getDebugProps() const override;
4040
#endif
4141

42+
ComponentName getDiffPropsImplementationTarget() const override;
4243
folly::dynamic getDiffProps(const Props* prevProps) const override;
4344
};
4445

packages/react-native/ReactCommon/react/renderer/components/text/ParagraphProps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ SharedDebugStringConvertibleList ParagraphProps::getDebugProps() const {
154154

155155
#ifdef RN_SERIALIZABLE_STATE
156156

157+
ComponentName ParagraphProps::getDiffPropsImplementationTarget() const {
158+
return "Paragraph";
159+
}
160+
157161
folly::dynamic ParagraphProps::getDiffProps(const Props* prevProps) const {
158162
static const auto defaultProps = ParagraphProps();
159163

packages/react-native/ReactCommon/react/renderer/components/text/ParagraphProps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ParagraphProps : public ViewProps, public BaseTextProps {
5959
#endif
6060

6161
#ifdef RN_SERIALIZABLE_STATE
62+
ComponentName getDiffPropsImplementationTarget() const override;
6263
folly::dynamic getDiffProps(const Props* prevProps) const override;
6364
#endif
6465
};

packages/react-native/ReactCommon/react/renderer/components/text/RawTextProps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ SharedDebugStringConvertibleList RawTextProps::getDebugProps() const {
3030

3131
#ifdef RN_SERIALIZABLE_STATE
3232

33+
ComponentName RawTextProps::getDiffPropsImplementationTarget() const {
34+
return "RawText";
35+
}
36+
3337
folly::dynamic RawTextProps::getDiffProps(const Props* prevProps) const {
3438
folly::dynamic result = folly::dynamic::object();
3539

packages/react-native/ReactCommon/react/renderer/components/text/RawTextProps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class RawTextProps : public Props {
3838
#endif
3939

4040
#ifdef RN_SERIALIZABLE_STATE
41+
ComponentName getDiffPropsImplementationTarget() const override;
4142
folly::dynamic getDiffProps(const Props* prevProps) const override;
4243
#endif
4344
};

packages/react-native/ReactCommon/react/renderer/components/text/TextProps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ SharedDebugStringConvertibleList TextProps::getDebugProps() const {
3535

3636
#ifdef RN_SERIALIZABLE_STATE
3737

38+
ComponentName TextProps::getDiffPropsImplementationTarget() const {
39+
return "Text";
40+
}
41+
3842
folly::dynamic TextProps::getDiffProps(const Props* prevProps) const {
3943
folly::dynamic result = folly::dynamic::object();
4044

0 commit comments

Comments
 (0)