Skip to content

Commit 9052f0b

Browse files
javachemeta-codesync[bot]
authored andcommitted
Move nativeId parsing into the Props ctor initializer list (#57339)
Summary: Pull Request resolved: #57339 Every Props subclass parses its fields in its 3-arg ctor's initializer list, but `Props` was the odd one out — its 3-arg ctor had an empty initializer list and a body that called a separate `Props::initialize` method, which then assigned `nativeId` and (on Android) ran `initializeDynamicProps`. Fold the `nativeId` parse back into the initializer list and inline the Android `initializeDynamicProps` call into the ctor body, matching the subclass pattern. This removes the only remaining external caller of `Props::initialize`: `YogaStylableProps`'s ctor was constructing its `Props` subobject via `Props()` and then calling `initialize(...)` from its body. Replace with the standard `Props(ctx, sourceProps, rawProps, filterObjectKeys)` initializer-list chain. With both call sites gone, delete `Props::initialize` outright. Behaviour is unchanged: the work that `initialize` did still runs on the same construction path, just via the ctor itself. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D109691981 fbshipit-source-id: 835615191332239e90353da2e66fecc429365529
1 parent e73592b commit 9052f0b

12 files changed

Lines changed: 15 additions & 41 deletions

File tree

packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ YogaStylableProps::YogaStylableProps(
2424
const YogaStylableProps& sourceProps,
2525
const RawProps& rawProps,
2626
const std::function<bool(const std::string&)>& filterObjectKeys)
27-
: Props() {
28-
initialize(context, sourceProps, rawProps, filterObjectKeys);
29-
30-
yogaStyle = ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
31-
? sourceProps.yogaStyle
32-
: convertRawProp(context, rawProps, sourceProps.yogaStyle);
33-
27+
: Props(context, sourceProps, rawProps, filterObjectKeys),
28+
yogaStyle(
29+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
30+
? sourceProps.yogaStyle
31+
: convertRawProp(context, rawProps, sourceProps.yogaStyle)) {
3432
if (!ReactNativeFeatureFlags::enableCppPropsIteratorSetter()) {
3533
convertRawPropAliases(context, sourceProps, rawProps);
3634
}

packages/react-native/ReactCommon/react/renderer/core/Props.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,20 @@
1616
namespace facebook::react {
1717

1818
Props::Props(
19-
const PropsParserContext& context,
20-
const Props& sourceProps,
21-
const RawProps& rawProps,
22-
const std::function<bool(const std::string&)>& filterObjectKeys) {
23-
initialize(context, sourceProps, rawProps, filterObjectKeys);
24-
}
25-
26-
void Props::initialize(
2719
const PropsParserContext& context,
2820
const Props& sourceProps,
2921
const RawProps& rawProps,
3022
[[maybe_unused]] const std::function<bool(const std::string&)>&
31-
filterObjectKeys) {
32-
nativeId = ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
33-
? sourceProps.nativeId
34-
: convertRawProp(context, rawProps, "nativeID", sourceProps.nativeId, {});
35-
23+
filterObjectKeys)
24+
: nativeId(
25+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
26+
? sourceProps.nativeId
27+
: convertRawProp(
28+
context,
29+
rawProps,
30+
"nativeID",
31+
sourceProps.nativeId,
32+
{})) {
3633
#ifdef RN_SERIALIZABLE_STATE
3734
if (!ReactNativeFeatureFlags::enableExclusivePropsUpdateAndroid()) {
3835
initializeDynamicProps(sourceProps, rawProps, filterObjectKeys);

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,6 @@ class Props : public virtual Sealable, public virtual DebugStringConvertible {
8282
SharedDebugStringConvertibleList getDebugProps() const override;
8383

8484
#endif
85-
86-
protected:
87-
/** Initialize member variables of Props instance */
88-
void initialize(
89-
const PropsParserContext &context,
90-
const Props &sourceProps,
91-
const RawProps &rawProps,
92-
/**
93-
* Filter object keys to be excluded when converting the RawProps to
94-
* folly::dynamic (android only)
95-
*/
96-
const std::function<bool(const std::string &)> &filterObjectKeys = nullptr);
9785
};
9886

9987
} // namespace facebook::react

scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4125,7 +4125,6 @@ class facebook::react::PreparedTextCacheKey {
41254125
}
41264126

41274127
class facebook::react::Props : public virtual facebook::react::Sealable, public virtual facebook::react::DebugStringConvertible {
4128-
protected void initialize(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);
41294128
public Props() = default;
41304129
public Props(const facebook::react::Props& other) = delete;
41314130
public Props(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);

scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3979,7 +3979,6 @@ class facebook::react::PreparedTextCacheKey {
39793979
}
39803980

39813981
class facebook::react::Props : public virtual facebook::react::Sealable, public virtual facebook::react::DebugStringConvertible {
3982-
protected void initialize(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);
39833982
public Props() = default;
39843983
public Props(const facebook::react::Props& other) = delete;
39853984
public Props(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);

scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4122,7 +4122,6 @@ class facebook::react::PreparedTextCacheKey {
41224122
}
41234123

41244124
class facebook::react::Props : public virtual facebook::react::Sealable, public virtual facebook::react::DebugStringConvertible {
4125-
protected void initialize(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);
41264125
public Props() = default;
41274126
public Props(const facebook::react::Props& other) = delete;
41284127
public Props(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);

scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6312,7 +6312,6 @@ class facebook::react::PreparedTextCacheKey {
63126312
}
63136313

63146314
class facebook::react::Props : public virtual facebook::react::Sealable, public virtual facebook::react::DebugStringConvertible {
6315-
protected void initialize(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);
63166315
public Props() = default;
63176316
public Props(const facebook::react::Props& other) = delete;
63186317
public Props(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);

scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6194,7 +6194,6 @@ class facebook::react::PreparedTextCacheKey {
61946194
}
61956195

61966196
class facebook::react::Props : public virtual facebook::react::Sealable, public virtual facebook::react::DebugStringConvertible {
6197-
protected void initialize(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);
61986197
public Props() = default;
61996198
public Props(const facebook::react::Props& other) = delete;
62006199
public Props(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);

scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6309,7 +6309,6 @@ class facebook::react::PreparedTextCacheKey {
63096309
}
63106310

63116311
class facebook::react::Props : public virtual facebook::react::Sealable, public virtual facebook::react::DebugStringConvertible {
6312-
protected void initialize(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);
63136312
public Props() = default;
63146313
public Props(const facebook::react::Props& other) = delete;
63156314
public Props(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);

scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,6 @@ class facebook::react::PreparedTextCacheKey {
27302730
}
27312731

27322732
class facebook::react::Props : public virtual facebook::react::Sealable, public virtual facebook::react::DebugStringConvertible {
2733-
protected void initialize(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);
27342733
public Props() = default;
27352734
public Props(const facebook::react::Props& other) = delete;
27362735
public Props(const facebook::react::PropsParserContext& context, const facebook::react::Props& sourceProps, const facebook::react::RawProps& rawProps, const std::function<bool(const std::string&)>& filterObjectKeys = nullptr);

0 commit comments

Comments
 (0)