mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use enum classes in C++ Turbo Modules (#41923)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41923 Changelog: [Internal][BREAKING] Use C++ enum classes in C++ Turbo Modules Problem: Using **C styles** `enums` can easily cause compiliation errors if symbol names collide. This code does not compile: ``` enum CustomEnumInt { A = 23, B = 42 }; static int A = 22; ``` This **C++ code**, using `enum classes` compiles: ``` enum class CustomEnumInt : int32_t { A = 23, B = 42 }; static int A = 22; ``` Reviewed By: rshest Differential Revision: D52098598 fbshipit-source-id: c919bd2e41970c83a032fec91b0537cd6fae8397
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1e22fa39ea
commit
8183afeb81
@@ -47,11 +47,12 @@ struct Bridging<ValueStruct>
|
||||
: NativeCxxModuleExampleCxxValueStructBridging<ValueStruct> {};
|
||||
|
||||
#pragma mark - enums
|
||||
enum CustomEnumInt { A = 23, B = 42 };
|
||||
enum class CustomEnumInt : int32_t { A = 23, B = 42 };
|
||||
|
||||
template <>
|
||||
struct Bridging<CustomEnumInt> {
|
||||
static CustomEnumInt fromJs(jsi::Runtime& rt, int32_t value) {
|
||||
static CustomEnumInt fromJs(jsi::Runtime& rt, jsi::Value rawValue) {
|
||||
auto value = static_cast<int32_t>(rawValue.asNumber());
|
||||
if (value == 23) {
|
||||
return CustomEnumInt::A;
|
||||
} else if (value == 42) {
|
||||
|
||||
Reference in New Issue
Block a user