Skip to content

Commit a142a78

Browse files
rshestfacebook-github-bot
authored andcommitted
Fix regression when setting shadow node properties in D38272966 (github PR merge)
Summary: Changelog: [Android][Fixed] - Fix regression when setting shadow node properties. Also simplified the corresponding macros to avoid using lambdas altogether, as they are not required. Note that this **does not** modify any constexpr-related semantics of the existing code, as the main constexpr macro, `CONSTEXPR_RAW_PROPS_KEY_HASH` evaluation result is still contstexpr value, and the other ones already involved non-const parts (see my comments). Reviewed By: NickGerleman Differential Revision: D38356411 fbshipit-source-id: 22c330d3425c8aed36693f4652f1b257d2dc96be
1 parent c7c263d commit a142a78

4 files changed

Lines changed: 22 additions & 28 deletions

File tree

ReactCommon/react/renderer/components/text/BaseTextProps.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,17 @@
1212
#include <react/renderer/debug/DebugStringConvertibleItem.h>
1313
#include <react/renderer/graphics/conversions.h>
1414

15-
#define GET_FIELD_VALUE(field, fieldName, defaultValue, rawValue) \
16-
(rawValue.hasValue() ? ([&rawValue, &context] { \
17-
decltype(defaultValue) res; \
18-
fromRawValue(context, rawValue, res); \
19-
return res; \
20-
}()) \
21-
: defaultValue);
22-
23-
#define REBUILD_FIELD_SWITCH_CASE( \
24-
defaults, rawValue, property, field, fieldName) \
25-
case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \
26-
property.field = \
27-
GET_FIELD_VALUE(field, fieldName, defaults.field, rawValue); \
28-
return; \
15+
#define REBUILD_FIELD_SWITCH_CASE( \
16+
defaults, rawValue, property, field, fieldName) \
17+
case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \
18+
if (rawValue.hasValue()) { \
19+
decltype(defaults.field) res; \
20+
fromRawValue(context, rawValue, res); \
21+
property.field = res; \
22+
} else { \
23+
property.field = defaults.field; \
24+
} \
25+
return; \
2926
}
3027

3128
namespace facebook {

ReactCommon/react/renderer/components/view/ViewProps.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,15 @@ ViewProps::ViewProps(
258258
#endif
259259
{};
260260

261-
#define VIEW_EVENT_CASE(eventType, eventString) \
262-
case CONSTEXPR_RAW_PROPS_KEY_HASH(eventString): { \
263-
ViewEvents defaultViewEvents{}; \
264-
events[eventType] = [ defaultViewEvents, &value, &context ]() constexpr { \
265-
bool res = defaultViewEvents[eventType]; \
266-
if (value.hasValue()) { \
267-
fromRawValue(context, value, res); \
268-
} \
269-
return res; \
270-
} \
271-
(); \
272-
return; \
261+
#define VIEW_EVENT_CASE(eventType, eventString) \
262+
case CONSTEXPR_RAW_PROPS_KEY_HASH(eventString): { \
263+
ViewEvents defaultViewEvents{}; \
264+
bool res = defaultViewEvents[eventType]; \
265+
if (value.hasValue()) { \
266+
fromRawValue(context, value, res); \
267+
} \
268+
events[eventType] = res; \
269+
return; \
273270
}
274271

275272
void ViewProps::setProp(

ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
119119
rawProps.iterateOverValues([&](RawPropsPropNameHash hash,
120120
const char *propName,
121121
RawValue const &fn) {
122-
shadowNodeProps.get()->Props::setProp(context, hash, propName, fn);
122+
shadowNodeProps.get()->setProp(context, hash, propName, fn);
123123
});
124124
}
125125

ReactCommon/react/renderer/core/PropsMacros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
// Get hash at compile-time. sizeof(str) - 1 == strlen
2121
#define CONSTEXPR_RAW_PROPS_KEY_HASH(s) \
22-
([]() constexpr { \
22+
([]() constexpr->RawPropsPropNameHash { \
2323
CLANG_PRAGMA("clang diagnostic push") \
2424
CLANG_PRAGMA("clang diagnostic ignored \"-Wshadow\"") \
2525
return folly::hash::fnv32_buf(s, sizeof(s) - 1); \

0 commit comments

Comments
 (0)