Skip to content

Commit fc26dbf

Browse files
chiaramooneyfacebook-github-bot
authored andcommitted
Fix Macro Errors for Windows (#34299)
Summary: Fix macro errors for Windows. Current syntax breaks the build of the React Common project on Windows because the ({...}) syntax is not supported; must be replaced with lambda expressions. Resolves #34090 ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [General] [Fixed] - Fix macro errors for Windows. lyahdav JoshuaGross Pull Request resolved: #34299 Test Plan: Build on react-native-windows repo. Tested in RNW app. Reviewed By: javache Differential Revision: D38272966 Pulled By: NickGerleman fbshipit-source-id: e76eac11cde173ef49465d01d793c593017f2ab7
1 parent cd595bd commit fc26dbf

4 files changed

Lines changed: 20 additions & 21 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
#include <react/renderer/graphics/conversions.h>
1414

1515
#define GET_FIELD_VALUE(field, fieldName, defaultValue, rawValue) \
16-
(rawValue.hasValue() ? ({ \
16+
(rawValue.hasValue() ? ([&rawValue, &context] { \
1717
decltype(defaultValue) res; \
1818
fromRawValue(context, rawValue, res); \
19-
res; \
20-
}) \
21-
: defaultValue)
19+
return res; \
20+
}()) \
21+
: defaultValue);
2222

2323
#define REBUILD_FIELD_SWITCH_CASE( \
2424
defaults, rawValue, property, field, fieldName) \

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,18 @@ 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] = ({ \
265-
bool res = defaultViewEvents[eventType]; \
266-
if (value.hasValue()) { \
267-
fromRawValue(context, value, res); \
268-
} \
269-
res; \
270-
}); \
271-
return; \
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; \
272273
}
273274

274275
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()->setProp(context, hash, propName, fn);
122+
shadowNodeProps.get()->Props::setProp(context, hash, propName, fn);
123123
});
124124
}
125125

ReactCommon/react/renderer/core/PropsMacros.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919

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

3129
#define RAW_PROPS_KEY_HASH(s) folly::hash::fnv32_buf(s, std::strlen(s))
3230

0 commit comments

Comments
 (0)