Skip to content

Commit 67381e1

Browse files
javachemeta-codesync[bot]
authored andcommitted
Remove RawPropsKey prefix and suffix
Summary: X-link: #55763 RawPropsKey previously stored three `const char*` fields (prefix, name, suffix) that were concatenated at runtime to form property names. This is pretty niche, used to make a few patterns simpler, but also can lead to confusing conflicts when the same property name can be represented in different ways (e.g. T174300106). Iterator style props parsing also completely avoids it. Lets change the API to a flat name instead. This change is breaking, but could only find a single user (Nitro module) effected, searching through `react-native-libraries`. Changelog: [General][Breaking] - Remove RawPropsKey prefix and suffix Reviewed By: christophpurrer Differential Revision: D94367880 fbshipit-source-id: d865725c7be6f880760b6e8d1a567a1b12ac469a
1 parent 2bbd70a commit 67381e1

23 files changed

Lines changed: 504 additions & 378 deletions

packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace facebook::react {
1717

1818
static bool
1919
hasValue(const RawProps& rawProps, bool defaultValue, const char* name) {
20-
auto rawValue = rawProps.at(name, nullptr, nullptr);
20+
auto rawValue = rawProps.at(name);
2121

2222
// No change to prop - use default
2323
if (rawValue == nullptr) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,8 @@ AccessibilityProps::AccessibilityProps(
229229
role = sourceProps.role;
230230
accessibilityTraits = sourceProps.accessibilityTraits;
231231
} else {
232-
auto* accessibilityRoleValue =
233-
rawProps.at("accessibilityRole", nullptr, nullptr);
234-
auto* roleValue = rawProps.at("role", nullptr, nullptr);
232+
auto* accessibilityRoleValue = rawProps.at("accessibilityRole");
233+
auto* roleValue = rawProps.at("role");
235234

236235
auto* precedentRoleValue =
237236
roleValue != nullptr ? roleValue : accessibilityRoleValue;

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

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,20 @@ BaseViewProps::BaseViewProps(
8484
: convertRawProp(
8585
context,
8686
rawProps,
87-
"border",
88-
"Radius",
87+
CascadedRectangleCornersNames{
88+
.topLeft = "borderTopLeftRadius",
89+
.topRight = "borderTopRightRadius",
90+
.bottomLeft = "borderBottomLeftRadius",
91+
.bottomRight = "borderBottomRightRadius",
92+
.topStart = "borderTopStartRadius",
93+
.topEnd = "borderTopEndRadius",
94+
.bottomStart = "borderBottomStartRadius",
95+
.bottomEnd = "borderBottomEndRadius",
96+
.endEnd = "borderEndEndRadius",
97+
.endStart = "borderEndStartRadius",
98+
.startEnd = "borderStartEndRadius",
99+
.startStart = "borderStartStartRadius",
100+
.all = "borderRadius"},
89101
sourceProps.borderRadii,
90102
{})),
91103
borderColors(
@@ -94,8 +106,19 @@ BaseViewProps::BaseViewProps(
94106
: convertRawProp(
95107
context,
96108
rawProps,
97-
"border",
98-
"Color",
109+
CascadedRectangleEdgesNames{
110+
.left = "borderLeftColor",
111+
.right = "borderRightColor",
112+
.top = "borderTopColor",
113+
.bottom = "borderBottomColor",
114+
.start = "borderStartColor",
115+
.end = "borderEndColor",
116+
.horizontal = "borderHorizontalColor",
117+
.vertical = "borderVerticalColor",
118+
.block = "borderBlockColor",
119+
.blockEnd = "borderBlockEndColor",
120+
.blockStart = "borderBlockStartColor",
121+
.all = "borderColor"},
99122
sourceProps.borderColors,
100123
{})),
101124
borderCurves(
@@ -104,8 +127,20 @@ BaseViewProps::BaseViewProps(
104127
: convertRawProp(
105128
context,
106129
rawProps,
107-
"border",
108-
"Curve",
130+
CascadedRectangleCornersNames{
131+
.topLeft = "borderTopLeftCurve",
132+
.topRight = "borderTopRightCurve",
133+
.bottomLeft = "borderBottomLeftCurve",
134+
.bottomRight = "borderBottomRightCurve",
135+
.topStart = "borderTopStartCurve",
136+
.topEnd = "borderTopEndCurve",
137+
.bottomStart = "borderBottomStartCurve",
138+
.bottomEnd = "borderBottomEndCurve",
139+
.endEnd = "borderEndEndCurve",
140+
.endStart = "borderEndStartCurve",
141+
.startEnd = "borderStartEndCurve",
142+
.startStart = "borderStartStartCurve",
143+
.all = "borderCurve"},
109144
sourceProps.borderCurves,
110145
{})),
111146
borderStyles(
@@ -114,8 +149,19 @@ BaseViewProps::BaseViewProps(
114149
: convertRawProp(
115150
context,
116151
rawProps,
117-
"border",
118-
"Style",
152+
CascadedRectangleEdgesNames{
153+
.left = "borderLeftStyle",
154+
.right = "borderRightStyle",
155+
.top = "borderTopStyle",
156+
.bottom = "borderBottomStyle",
157+
.start = "borderStartStyle",
158+
.end = "borderEndStyle",
159+
.horizontal = "borderHorizontalStyle",
160+
.vertical = "borderVerticalStyle",
161+
.block = "borderBlockStyle",
162+
.blockEnd = "borderBlockEndStyle",
163+
.blockStart = "borderBlockStartStyle",
164+
.all = "borderStyle"},
119165
sourceProps.borderStyles,
120166
{})),
121167
outlineColor(

packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ convertRawProp(const PropsParserContext &context, const RawProps &rawProps, cons
357357
convertRawProp(context, rawProps, "maxHeight", sourceValue.maxDimension(yoga::Dimension::Height), {}));
358358

359359
{
360-
const auto *rawValue = rawProps.at("aspectRatio", nullptr, nullptr);
360+
const auto *rawValue = rawProps.at("aspectRatio");
361361
if (rawValue != nullptr) {
362362
yogaStyle.setAspectRatio(rawValue->hasValue() ? convertAspectRatio(context, *rawValue) : yogaStyle.aspectRatio());
363363
} else {
@@ -371,43 +371,67 @@ convertRawProp(const PropsParserContext &context, const RawProps &rawProps, cons
371371
return yogaStyle;
372372
}
373373

374+
struct CascadedRectangleCornersNames {
375+
const char *topLeft;
376+
const char *topRight;
377+
const char *bottomLeft;
378+
const char *bottomRight;
379+
const char *topStart;
380+
const char *topEnd;
381+
const char *bottomStart;
382+
const char *bottomEnd;
383+
const char *endEnd;
384+
const char *endStart;
385+
const char *startEnd;
386+
const char *startStart;
387+
const char *all;
388+
};
389+
390+
struct CascadedRectangleEdgesNames {
391+
const char *left;
392+
const char *right;
393+
const char *top;
394+
const char *bottom;
395+
const char *start;
396+
const char *end;
397+
const char *horizontal;
398+
const char *vertical;
399+
const char *block;
400+
const char *blockEnd;
401+
const char *blockStart;
402+
const char *all;
403+
};
404+
374405
// This can be deleted when non-iterator ViewProp parsing is deleted
375406
template <typename T>
376407
static inline CascadedRectangleCorners<T> convertRawProp(
377408
const PropsParserContext &context,
378409
const RawProps &rawProps,
379-
const char *prefix,
380-
const char *suffix,
410+
const CascadedRectangleCornersNames &names,
381411
const CascadedRectangleCorners<T> &sourceValue,
382412
const CascadedRectangleCorners<T> &defaultValue)
383413
{
384414
CascadedRectangleCorners<T> result;
385415

386-
result.topLeft =
387-
convertRawProp(context, rawProps, "TopLeft", sourceValue.topLeft, defaultValue.topLeft, prefix, suffix);
388-
result.topRight =
389-
convertRawProp(context, rawProps, "TopRight", sourceValue.topRight, defaultValue.topRight, prefix, suffix);
416+
result.topLeft = convertRawProp(context, rawProps, names.topLeft, sourceValue.topLeft, defaultValue.topLeft);
417+
result.topRight = convertRawProp(context, rawProps, names.topRight, sourceValue.topRight, defaultValue.topRight);
390418
result.bottomLeft =
391-
convertRawProp(context, rawProps, "BottomLeft", sourceValue.bottomLeft, defaultValue.bottomLeft, prefix, suffix);
392-
result.bottomRight = convertRawProp(
393-
context, rawProps, "BottomRight", sourceValue.bottomRight, defaultValue.bottomRight, prefix, suffix);
394-
395-
result.topStart =
396-
convertRawProp(context, rawProps, "TopStart", sourceValue.topStart, defaultValue.topStart, prefix, suffix);
397-
result.topEnd = convertRawProp(context, rawProps, "TopEnd", sourceValue.topEnd, defaultValue.topEnd, prefix, suffix);
398-
result.bottomStart = convertRawProp(
399-
context, rawProps, "BottomStart", sourceValue.bottomStart, defaultValue.bottomStart, prefix, suffix);
400-
result.bottomEnd =
401-
convertRawProp(context, rawProps, "BottomEnd", sourceValue.bottomEnd, defaultValue.bottomEnd, prefix, suffix);
402-
result.endEnd = convertRawProp(context, rawProps, "EndEnd", sourceValue.endEnd, defaultValue.endEnd, prefix, suffix);
403-
result.endStart =
404-
convertRawProp(context, rawProps, "EndStart", sourceValue.endStart, defaultValue.endStart, prefix, suffix);
405-
result.startEnd =
406-
convertRawProp(context, rawProps, "StartEnd", sourceValue.startEnd, defaultValue.startEnd, prefix, suffix);
419+
convertRawProp(context, rawProps, names.bottomLeft, sourceValue.bottomLeft, defaultValue.bottomLeft);
420+
result.bottomRight =
421+
convertRawProp(context, rawProps, names.bottomRight, sourceValue.bottomRight, defaultValue.bottomRight);
422+
423+
result.topStart = convertRawProp(context, rawProps, names.topStart, sourceValue.topStart, defaultValue.topStart);
424+
result.topEnd = convertRawProp(context, rawProps, names.topEnd, sourceValue.topEnd, defaultValue.topEnd);
425+
result.bottomStart =
426+
convertRawProp(context, rawProps, names.bottomStart, sourceValue.bottomStart, defaultValue.bottomStart);
427+
result.bottomEnd = convertRawProp(context, rawProps, names.bottomEnd, sourceValue.bottomEnd, defaultValue.bottomEnd);
428+
result.endEnd = convertRawProp(context, rawProps, names.endEnd, sourceValue.endEnd, defaultValue.endEnd);
429+
result.endStart = convertRawProp(context, rawProps, names.endStart, sourceValue.endStart, defaultValue.endStart);
430+
result.startEnd = convertRawProp(context, rawProps, names.startEnd, sourceValue.startEnd, defaultValue.startEnd);
407431
result.startStart =
408-
convertRawProp(context, rawProps, "StartStart", sourceValue.startStart, defaultValue.startStart, prefix, suffix);
432+
convertRawProp(context, rawProps, names.startStart, sourceValue.startStart, defaultValue.startStart);
409433

410-
result.all = convertRawProp(context, rawProps, "", sourceValue.all, defaultValue.all, prefix, suffix);
434+
result.all = convertRawProp(context, rawProps, names.all, sourceValue.all, defaultValue.all);
411435

412436
return result;
413437
}
@@ -416,31 +440,28 @@ template <typename T>
416440
static inline CascadedRectangleEdges<T> convertRawProp(
417441
const PropsParserContext &context,
418442
const RawProps &rawProps,
419-
const char *prefix,
420-
const char *suffix,
443+
const CascadedRectangleEdgesNames &names,
421444
const CascadedRectangleEdges<T> &sourceValue,
422445
const CascadedRectangleEdges<T> &defaultValue)
423446
{
424447
CascadedRectangleEdges<T> result;
425448

426-
result.left = convertRawProp(context, rawProps, "Left", sourceValue.left, defaultValue.left, prefix, suffix);
427-
result.right = convertRawProp(context, rawProps, "Right", sourceValue.right, defaultValue.right, prefix, suffix);
428-
result.top = convertRawProp(context, rawProps, "Top", sourceValue.top, defaultValue.top, prefix, suffix);
429-
result.bottom = convertRawProp(context, rawProps, "Bottom", sourceValue.bottom, defaultValue.bottom, prefix, suffix);
449+
result.left = convertRawProp(context, rawProps, names.left, sourceValue.left, defaultValue.left);
450+
result.right = convertRawProp(context, rawProps, names.right, sourceValue.right, defaultValue.right);
451+
result.top = convertRawProp(context, rawProps, names.top, sourceValue.top, defaultValue.top);
452+
result.bottom = convertRawProp(context, rawProps, names.bottom, sourceValue.bottom, defaultValue.bottom);
430453

431-
result.start = convertRawProp(context, rawProps, "Start", sourceValue.start, defaultValue.start, prefix, suffix);
432-
result.end = convertRawProp(context, rawProps, "End", sourceValue.end, defaultValue.end, prefix, suffix);
454+
result.start = convertRawProp(context, rawProps, names.start, sourceValue.start, defaultValue.start);
455+
result.end = convertRawProp(context, rawProps, names.end, sourceValue.end, defaultValue.end);
433456
result.horizontal =
434-
convertRawProp(context, rawProps, "Horizontal", sourceValue.horizontal, defaultValue.horizontal, prefix, suffix);
435-
result.vertical =
436-
convertRawProp(context, rawProps, "Vertical", sourceValue.vertical, defaultValue.vertical, prefix, suffix);
437-
result.block = convertRawProp(context, rawProps, "Block", sourceValue.block, defaultValue.block, prefix, suffix);
438-
result.blockEnd =
439-
convertRawProp(context, rawProps, "BlockEnd", sourceValue.blockEnd, defaultValue.blockEnd, prefix, suffix);
457+
convertRawProp(context, rawProps, names.horizontal, sourceValue.horizontal, defaultValue.horizontal);
458+
result.vertical = convertRawProp(context, rawProps, names.vertical, sourceValue.vertical, defaultValue.vertical);
459+
result.block = convertRawProp(context, rawProps, names.block, sourceValue.block, defaultValue.block);
460+
result.blockEnd = convertRawProp(context, rawProps, names.blockEnd, sourceValue.blockEnd, defaultValue.blockEnd);
440461
result.blockStart =
441-
convertRawProp(context, rawProps, "BlockStart", sourceValue.blockStart, defaultValue.blockStart, prefix, suffix);
462+
convertRawProp(context, rawProps, names.blockStart, sourceValue.blockStart, defaultValue.blockStart);
442463

443-
result.all = convertRawProp(context, rawProps, "", sourceValue.all, defaultValue.all, prefix, suffix);
464+
result.all = convertRawProp(context, rawProps, names.all, sourceValue.all, defaultValue.all);
444465

445466
return result;
446467
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <cxxreact/TraceSection.h>
1111
#include <react/debug/react_native_assert.h>
12-
#include <react/renderer/core/RawPropsKey.h>
1312
#include <react/renderer/core/RawPropsParser.h>
1413

1514
namespace facebook::react {
@@ -110,15 +109,11 @@ bool RawProps::isEmpty() const noexcept {
110109
* Returns a const unowning pointer to `RawValue` of a prop with a given name.
111110
* Returns `nullptr` if a prop with the given name does not exist.
112111
*/
113-
const RawValue* RawProps::at(
114-
const char* name,
115-
const char* prefix,
116-
const char* suffix) const noexcept {
112+
const RawValue* RawProps::at(const char* name) const noexcept {
117113
react_native_assert(
118114
parser_ &&
119115
"The object is not parsed. `parse` must be called before `at`.");
120-
return parser_->at(
121-
*this, RawPropsKey{.prefix = prefix, .name = name, .suffix = suffix});
116+
return parser_->at(*this, name);
122117
}
123118

124119
} // namespace facebook::react

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class RawProps final {
9090
* Returns a const unowning pointer to `RawValue` of a prop with a given name.
9191
* Returns `nullptr` if a prop with the given name does not exist.
9292
*/
93-
const RawValue *at(const char *name, const char *prefix, const char *suffix) const noexcept;
93+
const RawValue *at(const char *name) const noexcept;
9494

9595
private:
9696
friend class RawPropsParser;

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

Lines changed: 0 additions & 62 deletions
This file was deleted.

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

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)