From 45e2941367fbf13584193bbda598173802289167 Mon Sep 17 00:00:00 2001 From: Erich Graham Date: Tue, 22 Mar 2022 17:10:18 -0700 Subject: [PATCH] Remove folly import in GenerateModuleObjCpp Summary: Changelog: [iOS][Changed] Replaced folly::Optional with std::optional from C++17 in Objc module generator. Reviewed By: philIip Differential Revision: D32367103 fbshipit-source-id: f0d254c4add7d6d2e0bdbceb09a852b4a01ea8c7 --- Libraries/TypeSafety/RCTConvertHelpers.h | 19 +-- Libraries/TypeSafety/RCTConvertHelpers.mm | 4 +- Libraries/TypeSafety/RCTTypeSafety.podspec | 7 +- React/CoreModules/RCTAccessibilityManager.mm | 4 +- React/CoreModules/RCTExceptionsManager.mm | 6 +- React/CoreModules/RCTPlatform.mm | 2 + React/CoreModules/RCTStatusBarManager.mm | 2 +- .../GenerateModuleObjCpp-test.js.snap | 148 +++++++++--------- .../header/serializeConstantsStruct.js | 24 +-- .../header/serializeRegularStruct.js | 22 +-- .../modules/GenerateModuleObjCpp/index.js | 2 +- .../GenerateModuleHObjCpp-test.js.snap | 70 ++++----- 12 files changed, 154 insertions(+), 156 deletions(-) diff --git a/Libraries/TypeSafety/RCTConvertHelpers.h b/Libraries/TypeSafety/RCTConvertHelpers.h index 75f751b96b17b6..49a2aa7d8dcdf6 100644 --- a/Libraries/TypeSafety/RCTConvertHelpers.h +++ b/Libraries/TypeSafety/RCTConvertHelpers.h @@ -5,12 +5,13 @@ * LICENSE file in the root directory of this source tree. */ +#import + #import #import #import -#import namespace facebook { namespace react { @@ -35,22 +36,22 @@ NSArray *RCTConvertVecToArray(const ContainerT &vec) } template -NSArray *RCTConvertOptionalVecToArray(const folly::Optional &vec, id (^convertor)(typename ContainerT::value_type element)) +NSArray *RCTConvertOptionalVecToArray(const std::optional &vec, id (^convertor)(typename ContainerT::value_type element)) { - return vec.hasValue() ? RCTConvertVecToArray(vec.value(), convertor) : nil; + return vec.has_value() ? RCTConvertVecToArray(vec.value(), convertor) : nil; } template -NSArray *RCTConvertOptionalVecToArray(const folly::Optional &vec) +NSArray *RCTConvertOptionalVecToArray(const std::optional &vec) { - return vec.hasValue() ? RCTConvertVecToArray(vec.value(), ^id(typename ContainerT::value_type element) { return element; }) : nil; + return vec.has_value() ? RCTConvertVecToArray(vec.value(), ^id(typename ContainerT::value_type element) { return element; }) : nil; } bool RCTBridgingToBool(id value); -folly::Optional RCTBridgingToOptionalBool(id value); +std::optional RCTBridgingToOptionalBool(id value); NSString *RCTBridgingToString(id value); NSString *RCTBridgingToOptionalString(id value); -folly::Optional RCTBridgingToOptionalDouble(id value); +std::optional RCTBridgingToOptionalDouble(id value); double RCTBridgingToDouble(id value); NSArray *RCTBridgingToArray(id value); @@ -64,10 +65,10 @@ facebook::react::LazyVector RCTBridgingToVec(id value, T (^ctor)(id element)) } template -folly::Optional> RCTBridgingToOptionalVec(id value, T (^ctor)(id element)) +std::optional> RCTBridgingToOptionalVec(id value, T (^ctor)(id element)) { if (value == nil || value == (id)kCFNull) { - return folly::none; + return std::nullopt; } else { return RCTBridgingToVec(value, ctor); } diff --git a/Libraries/TypeSafety/RCTConvertHelpers.mm b/Libraries/TypeSafety/RCTConvertHelpers.mm index 24f7a54b881053..46690f5a4eb6b7 100644 --- a/Libraries/TypeSafety/RCTConvertHelpers.mm +++ b/Libraries/TypeSafety/RCTConvertHelpers.mm @@ -14,7 +14,7 @@ bool RCTBridgingToBool(id value) return [RCTConvert BOOL:value] ? true : false; } -folly::Optional RCTBridgingToOptionalBool(id value) +std::optional RCTBridgingToOptionalBool(id value) { if (!RCTNilIfNull(value)) { return {}; @@ -33,7 +33,7 @@ bool RCTBridgingToBool(id value) } -folly::Optional RCTBridgingToOptionalDouble(id value) +std::optional RCTBridgingToOptionalDouble(id value) { if (!RCTNilIfNull(value)) { return {}; diff --git a/Libraries/TypeSafety/RCTTypeSafety.podspec b/Libraries/TypeSafety/RCTTypeSafety.podspec index b5803aa33d90c4..d2744689a01c4d 100644 --- a/Libraries/TypeSafety/RCTTypeSafety.podspec +++ b/Libraries/TypeSafety/RCTTypeSafety.podspec @@ -16,9 +16,6 @@ else source[:tag] = "v#{version}" end -folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' -folly_version = '2021.06.28.00-v2' - Pod::Spec.new do |s| s.name = "RCTTypeSafety" s.version = version @@ -27,18 +24,16 @@ Pod::Spec.new do |s| s.license = package["license"] s.author = "Facebook, Inc. and its affiliates" s.platforms = { :ios => "12.4" } - s.compiler_flags = folly_compiler_flags s.source = source s.source_files = "**/*.{c,h,m,mm,cpp}" s.header_dir = "RCTTypeSafety" s.pod_target_xcconfig = { "USE_HEADERMAP" => "YES", "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", - "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/Libraries/TypeSafety\" \"$(PODS_ROOT)/RCT-Folly\"" + "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/Libraries/TypeSafety\"" } s.dependency "FBLazyVector", version - s.dependency "RCT-Folly", folly_version s.dependency "RCTRequired", version s.dependency "React-Core", version end diff --git a/React/CoreModules/RCTAccessibilityManager.mm b/React/CoreModules/RCTAccessibilityManager.mm index f7ee29c812c1a4..33b0501f694396 100644 --- a/React/CoreModules/RCTAccessibilityManager.mm +++ b/React/CoreModules/RCTAccessibilityManager.mm @@ -281,9 +281,9 @@ - (void)setMultipliers:(NSDictionary *)multipliers static void setMultipliers( NSMutableDictionary *multipliers, NSString *key, - folly::Optional optionalDouble) + std::optional optionalDouble) { - if (optionalDouble.hasValue()) { + if (optionalDouble.has_value()) { multipliers[key] = @(optionalDouble.value()); } } diff --git a/React/CoreModules/RCTExceptionsManager.mm b/React/CoreModules/RCTExceptionsManager.mm index a8f44ed28062b2..9ee53d97f205c7 100644 --- a/React/CoreModules/RCTExceptionsManager.mm +++ b/React/CoreModules/RCTExceptionsManager.mm @@ -117,15 +117,15 @@ - (void)reportFatal:(NSString *)message stack:(NSArray *)stack e NSMutableArray *stackArray = [NSMutableArray new]; for (auto frame : data.stack()) { NSMutableDictionary *frameDict = [NSMutableDictionary new]; - if (frame.column().hasValue()) { + if (frame.column().has_value()) { frameDict[@"column"] = @(frame.column().value()); } frameDict[@"file"] = frame.file(); - if (frame.lineNumber().hasValue()) { + if (frame.lineNumber().has_value()) { frameDict[@"lineNumber"] = @(frame.lineNumber().value()); } frameDict[@"methodName"] = frame.methodName(); - if (frame.collapse().hasValue()) { + if (frame.collapse().has_value()) { frameDict[@"collapse"] = @(frame.collapse().value()); } [stackArray addObject:frameDict]; diff --git a/React/CoreModules/RCTPlatform.mm b/React/CoreModules/RCTPlatform.mm index bf0fed1cdff19c..a9acfeeb1adf31 100644 --- a/React/CoreModules/RCTPlatform.mm +++ b/React/CoreModules/RCTPlatform.mm @@ -15,6 +15,8 @@ #import "CoreModulesPlugins.h" +#import + using namespace facebook::react; static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom) diff --git a/React/CoreModules/RCTStatusBarManager.mm b/React/CoreModules/RCTStatusBarManager.mm index 19d1d8f89ba9ee..3c5d7938519154 100644 --- a/React/CoreModules/RCTStatusBarManager.mm +++ b/React/CoreModules/RCTStatusBarManager.mm @@ -181,7 +181,7 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification RCTUnsafeExecuteOnMainQueueSync(^{ constants = facebook::react::typedConstants({ .HEIGHT = RCTSharedApplication().statusBarFrame.size.height, - .DEFAULT_BACKGROUND_COLOR = folly::none, + .DEFAULT_BACKGROUND_COLOR = std::nullopt, }); }); diff --git a/packages/react-native-codegen/e2e/__tests__/modules/__snapshots__/GenerateModuleObjCpp-test.js.snap b/packages/react-native-codegen/e2e/__tests__/modules/__snapshots__/GenerateModuleObjCpp-test.js.snap index f809a4eb4d78bd..13d1139ab9c54b 100644 --- a/packages/react-native-codegen/e2e/__tests__/modules/__snapshots__/GenerateModuleObjCpp-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/modules/__snapshots__/GenerateModuleObjCpp-test.js.snap @@ -25,7 +25,7 @@ exports[`GenerateModuleObjCpp can generate a header file NativeModule specs 1`] #import #import #import -#import +#import #import @@ -302,8 +302,8 @@ namespace JS { struct Builder { struct Input { - folly::Optional D; - folly::Optional E; + std::optional D; + std::optional E; NSString *F; }; @@ -331,8 +331,8 @@ namespace JS { struct Builder { struct Input { - folly::Optional D; - folly::Optional E; + std::optional D; + std::optional E; NSString *F; }; @@ -360,8 +360,8 @@ namespace JS { struct Builder { struct Input { - folly::Optional D; - folly::Optional E; + std::optional D; + std::optional E; NSString *F; }; @@ -389,9 +389,9 @@ namespace JS { struct Builder { struct Input { - folly::Optional D; + std::optional D; id _Nullable A; - folly::Optional E; + std::optional E; NSString *F; }; @@ -580,7 +580,7 @@ namespace JS { RCTRequired> const1; RCTRequired> const2; RCTRequired> const3; - folly::Optional>> id_; + std::optional>> id_; }; /** Initialize with a set of values */ @@ -637,7 +637,7 @@ namespace facebook { namespace JS { namespace NativeSampleTurboModuleNullable { struct SpecGetObjectShapeArg { - folly::Optional prop() const; + std::optional prop() const; SpecGetObjectShapeArg(NSDictionary *const v) : _v(v) {} private: @@ -670,8 +670,8 @@ namespace JS { struct Builder { struct Input { - RCTRequired> const1; - RCTRequired> const2; + RCTRequired> const1; + RCTRequired> const2; RCTRequired const3; }; @@ -729,7 +729,7 @@ namespace facebook { namespace JS { namespace NativeSampleTurboModuleNullableAndOptional { struct SpecGetObjectShapeArg { - folly::Optional prop() const; + std::optional prop() const; SpecGetObjectShapeArg(NSDictionary *const v) : _v(v) {} private: @@ -762,8 +762,8 @@ namespace JS { struct Builder { struct Input { - folly::Optional const1; - folly::Optional const2; + std::optional const1; + std::optional const2; NSString *const3; }; @@ -821,7 +821,7 @@ namespace facebook { namespace JS { namespace NativeSampleTurboModuleOptional { struct SpecGetObjectShapeArg { - folly::Optional prop() const; + std::optional prop() const; SpecGetObjectShapeArg(NSDictionary *const v) : _v(v) {} private: @@ -854,8 +854,8 @@ namespace JS { struct Builder { struct Input { - folly::Optional const1; - folly::Optional const2; + std::optional const1; + std::optional const2; NSString *const3; }; @@ -1018,9 +1018,9 @@ inline JS::NativeObjectTurboModule::Constants::Builder::Builder(Constants i) : _ inline JS::NativeOptionalObjectTurboModule::ConstantsEEE::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto D = i.D; - d[@\\"D\\"] = D.hasValue() ? @((BOOL)D.value()) : nil; + d[@\\"D\\"] = D.has_value() ? @((BOOL)D.value()) : nil; auto E = i.E; - d[@\\"E\\"] = E.hasValue() ? @((double)E.value()) : nil; + d[@\\"E\\"] = E.has_value() ? @((double)E.value()) : nil; auto F = i.F; d[@\\"F\\"] = F; return d; @@ -1031,9 +1031,9 @@ inline JS::NativeOptionalObjectTurboModule::ConstantsEEE::Builder::Builder(Const inline JS::NativeOptionalObjectTurboModule::ConstantsEE::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto D = i.D; - d[@\\"D\\"] = D.hasValue() ? @((BOOL)D.value()) : nil; + d[@\\"D\\"] = D.has_value() ? @((BOOL)D.value()) : nil; auto E = i.E; - d[@\\"E\\"] = E.hasValue() ? E.value().buildUnsafeRawValue() : nil; + d[@\\"E\\"] = E.has_value() ? E.value().buildUnsafeRawValue() : nil; auto F = i.F; d[@\\"F\\"] = F; return d; @@ -1044,9 +1044,9 @@ inline JS::NativeOptionalObjectTurboModule::ConstantsEE::Builder::Builder(Consta inline JS::NativeOptionalObjectTurboModule::ConstantsE::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto D = i.D; - d[@\\"D\\"] = D.hasValue() ? @((BOOL)D.value()) : nil; + d[@\\"D\\"] = D.has_value() ? @((BOOL)D.value()) : nil; auto E = i.E; - d[@\\"E\\"] = E.hasValue() ? E.value().buildUnsafeRawValue() : nil; + d[@\\"E\\"] = E.has_value() ? E.value().buildUnsafeRawValue() : nil; auto F = i.F; d[@\\"F\\"] = F; return d; @@ -1057,11 +1057,11 @@ inline JS::NativeOptionalObjectTurboModule::ConstantsE::Builder::Builder(Constan inline JS::NativeOptionalObjectTurboModule::Constants::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto D = i.D; - d[@\\"D\\"] = D.hasValue() ? @((BOOL)D.value()) : nil; + d[@\\"D\\"] = D.has_value() ? @((BOOL)D.value()) : nil; auto A = i.A; d[@\\"A\\"] = A; auto E = i.E; - d[@\\"E\\"] = E.hasValue() ? E.value().buildUnsafeRawValue() : nil; + d[@\\"E\\"] = E.has_value() ? E.value().buildUnsafeRawValue() : nil; auto F = i.F; d[@\\"F\\"] = F; return d; @@ -1111,13 +1111,13 @@ inline JS::NativeSampleTurboModuleArrays::Constants::Builder::Builder(const Inpu auto const3 = i.const3.get(); d[@\\"const3\\"] = RCTConvertVecToArray(const3, ^id(NSString * el_) { return el_; }); auto id_ = i.id_; - d[@\\"id\\"] = RCTConvertOptionalVecToArray(id_, ^id(folly::Optional el_) { return el_.hasValue() ? el_.value().buildUnsafeRawValue() : nil; }); + d[@\\"id\\"] = RCTConvertOptionalVecToArray(id_, ^id(std::optional el_) { return el_.has_value() ? el_.value().buildUnsafeRawValue() : nil; }); return d; }) {} inline JS::NativeSampleTurboModuleArrays::Constants::Builder::Builder(Constants i) : _factory(^{ return i.unsafeRawValue(); }) {} -inline folly::Optional JS::NativeSampleTurboModuleNullable::SpecGetObjectShapeArg::prop() const +inline std::optional JS::NativeSampleTurboModuleNullable::SpecGetObjectShapeArg::prop() const { id const p = _v[@\\"prop\\"]; return RCTBridgingToOptionalDouble(p); @@ -1130,9 +1130,9 @@ inline NSString *JS::NativeSampleTurboModuleNullable::Animal::name() const inline JS::NativeSampleTurboModuleNullable::Constants::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto const1 = i.const1.get(); - d[@\\"const1\\"] = const1.hasValue() ? @((BOOL)const1.value()) : nil; + d[@\\"const1\\"] = const1.has_value() ? @((BOOL)const1.value()) : nil; auto const2 = i.const2.get(); - d[@\\"const2\\"] = const2.hasValue() ? @((double)const2.value()) : nil; + d[@\\"const2\\"] = const2.has_value() ? @((double)const2.value()) : nil; auto const3 = i.const3.get(); d[@\\"const3\\"] = const3; return d; @@ -1140,7 +1140,7 @@ inline JS::NativeSampleTurboModuleNullable::Constants::Builder::Builder(const In inline JS::NativeSampleTurboModuleNullable::Constants::Builder::Builder(Constants i) : _factory(^{ return i.unsafeRawValue(); }) {} -inline folly::Optional JS::NativeSampleTurboModuleNullableAndOptional::SpecGetObjectShapeArg::prop() const +inline std::optional JS::NativeSampleTurboModuleNullableAndOptional::SpecGetObjectShapeArg::prop() const { id const p = _v[@\\"prop\\"]; return RCTBridgingToOptionalDouble(p); @@ -1153,9 +1153,9 @@ inline NSString *JS::NativeSampleTurboModuleNullableAndOptional::Animal::name() inline JS::NativeSampleTurboModuleNullableAndOptional::Constants::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto const1 = i.const1; - d[@\\"const1\\"] = const1.hasValue() ? @((BOOL)const1.value()) : nil; + d[@\\"const1\\"] = const1.has_value() ? @((BOOL)const1.value()) : nil; auto const2 = i.const2; - d[@\\"const2\\"] = const2.hasValue() ? @((double)const2.value()) : nil; + d[@\\"const2\\"] = const2.has_value() ? @((double)const2.value()) : nil; auto const3 = i.const3; d[@\\"const3\\"] = const3; return d; @@ -1163,7 +1163,7 @@ inline JS::NativeSampleTurboModuleNullableAndOptional::Constants::Builder::Build inline JS::NativeSampleTurboModuleNullableAndOptional::Constants::Builder::Builder(Constants i) : _factory(^{ return i.unsafeRawValue(); }) {} -inline folly::Optional JS::NativeSampleTurboModuleOptional::SpecGetObjectShapeArg::prop() const +inline std::optional JS::NativeSampleTurboModuleOptional::SpecGetObjectShapeArg::prop() const { id const p = _v[@\\"prop\\"]; return RCTBridgingToOptionalDouble(p); @@ -1176,9 +1176,9 @@ inline NSString *JS::NativeSampleTurboModuleOptional::Animal::name() const inline JS::NativeSampleTurboModuleOptional::Constants::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto const1 = i.const1; - d[@\\"const1\\"] = const1.hasValue() ? @((BOOL)const1.value()) : nil; + d[@\\"const1\\"] = const1.has_value() ? @((BOOL)const1.value()) : nil; auto const2 = i.const2; - d[@\\"const2\\"] = const2.hasValue() ? @((double)const2.value()) : nil; + d[@\\"const2\\"] = const2.has_value() ? @((double)const2.value()) : nil; auto const3 = i.const3; d[@\\"const3\\"] = const3; return d; @@ -1215,7 +1215,7 @@ exports[`GenerateModuleObjCpp can generate a header file NativeModule specs with #import #import #import -#import +#import #import @@ -1494,8 +1494,8 @@ namespace JS { struct Builder { struct Input { - folly::Optional D; - folly::Optional E; + std::optional D; + std::optional E; NSString *F; }; @@ -1523,8 +1523,8 @@ namespace JS { struct Builder { struct Input { - folly::Optional D; - folly::Optional E; + std::optional D; + std::optional E; NSString *F; }; @@ -1552,8 +1552,8 @@ namespace JS { struct Builder { struct Input { - folly::Optional D; - folly::Optional E; + std::optional D; + std::optional E; NSString *F; }; @@ -1581,9 +1581,9 @@ namespace JS { struct Builder { struct Input { - folly::Optional D; + std::optional D; id _Nullable A; - folly::Optional E; + std::optional E; NSString *F; }; @@ -1772,7 +1772,7 @@ namespace JS { RCTRequired> const1; RCTRequired> const2; RCTRequired> const3; - folly::Optional>> id_; + std::optional>> id_; }; /** Initialize with a set of values */ @@ -1829,7 +1829,7 @@ namespace facebook { namespace JS { namespace NativeSampleTurboModuleNullable { struct SpecGetObjectShapeArg { - folly::Optional prop() const; + std::optional prop() const; SpecGetObjectShapeArg(NSDictionary *const v) : _v(v) {} private: @@ -1862,8 +1862,8 @@ namespace JS { struct Builder { struct Input { - RCTRequired> const1; - RCTRequired> const2; + RCTRequired> const1; + RCTRequired> const2; RCTRequired const3; }; @@ -1921,7 +1921,7 @@ namespace facebook { namespace JS { namespace NativeSampleTurboModuleNullableAndOptional { struct SpecGetObjectShapeArg { - folly::Optional prop() const; + std::optional prop() const; SpecGetObjectShapeArg(NSDictionary *const v) : _v(v) {} private: @@ -1954,8 +1954,8 @@ namespace JS { struct Builder { struct Input { - folly::Optional const1; - folly::Optional const2; + std::optional const1; + std::optional const2; NSString *const3; }; @@ -2013,7 +2013,7 @@ namespace facebook { namespace JS { namespace NativeSampleTurboModuleOptional { struct SpecGetObjectShapeArg { - folly::Optional prop() const; + std::optional prop() const; SpecGetObjectShapeArg(NSDictionary *const v) : _v(v) {} private: @@ -2046,8 +2046,8 @@ namespace JS { struct Builder { struct Input { - folly::Optional const1; - folly::Optional const2; + std::optional const1; + std::optional const2; NSString *const3; }; @@ -2210,9 +2210,9 @@ inline JS::NativeObjectTurboModule::Constants::Builder::Builder(Constants i) : _ inline JS::NativeOptionalObjectTurboModule::ConstantsEEE::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto D = i.D; - d[@\\"D\\"] = D.hasValue() ? @((BOOL)D.value()) : nil; + d[@\\"D\\"] = D.has_value() ? @((BOOL)D.value()) : nil; auto E = i.E; - d[@\\"E\\"] = E.hasValue() ? @((double)E.value()) : nil; + d[@\\"E\\"] = E.has_value() ? @((double)E.value()) : nil; auto F = i.F; d[@\\"F\\"] = F; return d; @@ -2223,9 +2223,9 @@ inline JS::NativeOptionalObjectTurboModule::ConstantsEEE::Builder::Builder(Const inline JS::NativeOptionalObjectTurboModule::ConstantsEE::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto D = i.D; - d[@\\"D\\"] = D.hasValue() ? @((BOOL)D.value()) : nil; + d[@\\"D\\"] = D.has_value() ? @((BOOL)D.value()) : nil; auto E = i.E; - d[@\\"E\\"] = E.hasValue() ? E.value().buildUnsafeRawValue() : nil; + d[@\\"E\\"] = E.has_value() ? E.value().buildUnsafeRawValue() : nil; auto F = i.F; d[@\\"F\\"] = F; return d; @@ -2236,9 +2236,9 @@ inline JS::NativeOptionalObjectTurboModule::ConstantsEE::Builder::Builder(Consta inline JS::NativeOptionalObjectTurboModule::ConstantsE::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto D = i.D; - d[@\\"D\\"] = D.hasValue() ? @((BOOL)D.value()) : nil; + d[@\\"D\\"] = D.has_value() ? @((BOOL)D.value()) : nil; auto E = i.E; - d[@\\"E\\"] = E.hasValue() ? E.value().buildUnsafeRawValue() : nil; + d[@\\"E\\"] = E.has_value() ? E.value().buildUnsafeRawValue() : nil; auto F = i.F; d[@\\"F\\"] = F; return d; @@ -2249,11 +2249,11 @@ inline JS::NativeOptionalObjectTurboModule::ConstantsE::Builder::Builder(Constan inline JS::NativeOptionalObjectTurboModule::Constants::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto D = i.D; - d[@\\"D\\"] = D.hasValue() ? @((BOOL)D.value()) : nil; + d[@\\"D\\"] = D.has_value() ? @((BOOL)D.value()) : nil; auto A = i.A; d[@\\"A\\"] = A; auto E = i.E; - d[@\\"E\\"] = E.hasValue() ? E.value().buildUnsafeRawValue() : nil; + d[@\\"E\\"] = E.has_value() ? E.value().buildUnsafeRawValue() : nil; auto F = i.F; d[@\\"F\\"] = F; return d; @@ -2303,13 +2303,13 @@ inline JS::NativeSampleTurboModuleArrays::Constants::Builder::Builder(const Inpu auto const3 = i.const3.get(); d[@\\"const3\\"] = RCTConvertVecToArray(const3, ^id(NSString * el_) { return el_; }); auto id_ = i.id_; - d[@\\"id\\"] = RCTConvertOptionalVecToArray(id_, ^id(folly::Optional el_) { return el_.hasValue() ? el_.value().buildUnsafeRawValue() : nil; }); + d[@\\"id\\"] = RCTConvertOptionalVecToArray(id_, ^id(std::optional el_) { return el_.has_value() ? el_.value().buildUnsafeRawValue() : nil; }); return d; }) {} inline JS::NativeSampleTurboModuleArrays::Constants::Builder::Builder(Constants i) : _factory(^{ return i.unsafeRawValue(); }) {} -inline folly::Optional JS::NativeSampleTurboModuleNullable::SpecGetObjectShapeArg::prop() const +inline std::optional JS::NativeSampleTurboModuleNullable::SpecGetObjectShapeArg::prop() const { id const p = _v[@\\"prop\\"]; return RCTBridgingToOptionalDouble(p); @@ -2322,9 +2322,9 @@ inline NSString *JS::NativeSampleTurboModuleNullable::Animal::name() const inline JS::NativeSampleTurboModuleNullable::Constants::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto const1 = i.const1.get(); - d[@\\"const1\\"] = const1.hasValue() ? @((BOOL)const1.value()) : nil; + d[@\\"const1\\"] = const1.has_value() ? @((BOOL)const1.value()) : nil; auto const2 = i.const2.get(); - d[@\\"const2\\"] = const2.hasValue() ? @((double)const2.value()) : nil; + d[@\\"const2\\"] = const2.has_value() ? @((double)const2.value()) : nil; auto const3 = i.const3.get(); d[@\\"const3\\"] = const3; return d; @@ -2332,7 +2332,7 @@ inline JS::NativeSampleTurboModuleNullable::Constants::Builder::Builder(const In inline JS::NativeSampleTurboModuleNullable::Constants::Builder::Builder(Constants i) : _factory(^{ return i.unsafeRawValue(); }) {} -inline folly::Optional JS::NativeSampleTurboModuleNullableAndOptional::SpecGetObjectShapeArg::prop() const +inline std::optional JS::NativeSampleTurboModuleNullableAndOptional::SpecGetObjectShapeArg::prop() const { id const p = _v[@\\"prop\\"]; return RCTBridgingToOptionalDouble(p); @@ -2345,9 +2345,9 @@ inline NSString *JS::NativeSampleTurboModuleNullableAndOptional::Animal::name() inline JS::NativeSampleTurboModuleNullableAndOptional::Constants::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto const1 = i.const1; - d[@\\"const1\\"] = const1.hasValue() ? @((BOOL)const1.value()) : nil; + d[@\\"const1\\"] = const1.has_value() ? @((BOOL)const1.value()) : nil; auto const2 = i.const2; - d[@\\"const2\\"] = const2.hasValue() ? @((double)const2.value()) : nil; + d[@\\"const2\\"] = const2.has_value() ? @((double)const2.value()) : nil; auto const3 = i.const3; d[@\\"const3\\"] = const3; return d; @@ -2355,7 +2355,7 @@ inline JS::NativeSampleTurboModuleNullableAndOptional::Constants::Builder::Build inline JS::NativeSampleTurboModuleNullableAndOptional::Constants::Builder::Builder(Constants i) : _factory(^{ return i.unsafeRawValue(); }) {} -inline folly::Optional JS::NativeSampleTurboModuleOptional::SpecGetObjectShapeArg::prop() const +inline std::optional JS::NativeSampleTurboModuleOptional::SpecGetObjectShapeArg::prop() const { id const p = _v[@\\"prop\\"]; return RCTBridgingToOptionalDouble(p); @@ -2368,9 +2368,9 @@ inline NSString *JS::NativeSampleTurboModuleOptional::Animal::name() const inline JS::NativeSampleTurboModuleOptional::Constants::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto const1 = i.const1; - d[@\\"const1\\"] = const1.hasValue() ? @((BOOL)const1.value()) : nil; + d[@\\"const1\\"] = const1.has_value() ? @((BOOL)const1.value()) : nil; auto const2 = i.const2; - d[@\\"const2\\"] = const2.hasValue() ? @((double)const2.value()) : nil; + d[@\\"const2\\"] = const2.has_value() ? @((double)const2.value()) : nil; auto const3 = i.const3; d[@\\"const3\\"] = const3; return d; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js index a9685f7ac11849..019724049a15bc 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js @@ -79,15 +79,15 @@ function toObjCType( ): string { const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation); const isRequired = !nullable && !isOptional; - const wrapFollyOptional = (type: string) => { - return isRequired ? type : `folly::Optional<${type}>`; + const wrapOptional = (type: string) => { + return isRequired ? type : `std::optional<${type}>`; }; switch (typeAnnotation.type) { case 'ReservedTypeAnnotation': switch (typeAnnotation.name) { case 'RootTag': - return wrapFollyOptional('double'); + return wrapOptional('double'); default: (typeAnnotation.name: empty); throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`); @@ -95,15 +95,15 @@ function toObjCType( case 'StringTypeAnnotation': return 'NSString *'; case 'NumberTypeAnnotation': - return wrapFollyOptional('double'); + return wrapOptional('double'); case 'FloatTypeAnnotation': - return wrapFollyOptional('double'); + return wrapOptional('double'); case 'Int32TypeAnnotation': - return wrapFollyOptional('double'); + return wrapOptional('double'); case 'DoubleTypeAnnotation': - return wrapFollyOptional('double'); + return wrapOptional('double'); case 'BooleanTypeAnnotation': - return wrapFollyOptional('bool'); + return wrapOptional('bool'); case 'GenericObjectTypeAnnotation': return isRequired ? 'id ' : 'id _Nullable '; case 'ArrayTypeAnnotation': @@ -111,7 +111,7 @@ function toObjCType( return isRequired ? 'id ' : 'id _Nullable '; } - return wrapFollyOptional( + return wrapOptional( `std::vector<${toObjCType( hasteModuleName, typeAnnotation.elementType, @@ -123,7 +123,7 @@ function toObjCType( hasteModuleName, structName, ); - return wrapFollyOptional(`${namespacedStructName}::Builder`); + return wrapOptional(`${namespacedStructName}::Builder`); default: (typeAnnotation.type: empty); throw new Error( @@ -144,7 +144,7 @@ function toObjCValue( function wrapPrimitive(type: string) { return !isRequired - ? `${value}.hasValue() ? @((${type})${value}.value()) : nil` + ? `${value}.has_value() ? @((${type})${value}.value()) : nil` : `@(${value})`; } @@ -199,7 +199,7 @@ function toObjCValue( ); case 'TypeAliasTypeAnnotation': return !isRequired - ? `${value}.hasValue() ? ${value}.value().buildUnsafeRawValue() : nil` + ? `${value}.has_value() ? ${value}.value().buildUnsafeRawValue() : nil` : `${value}.buildUnsafeRawValue()`; default: (typeAnnotation.type: empty); diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js index 66b08d826528e7..e17c30005d411b 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js @@ -70,15 +70,15 @@ function toObjCType( ): string { const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation); const isRequired = !nullable && !isOptional; - const wrapFollyOptional = (type: string) => { - return isRequired ? type : `folly::Optional<${type}>`; + const wrapOptional = (type: string) => { + return isRequired ? type : `std::optional<${type}>`; }; switch (typeAnnotation.type) { case 'ReservedTypeAnnotation': switch (typeAnnotation.name) { case 'RootTag': - return wrapFollyOptional('double'); + return wrapOptional('double'); default: (typeAnnotation.name: empty); throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`); @@ -86,22 +86,22 @@ function toObjCType( case 'StringTypeAnnotation': return 'NSString *'; case 'NumberTypeAnnotation': - return wrapFollyOptional('double'); + return wrapOptional('double'); case 'FloatTypeAnnotation': - return wrapFollyOptional('double'); + return wrapOptional('double'); case 'Int32TypeAnnotation': - return wrapFollyOptional('double'); + return wrapOptional('double'); case 'DoubleTypeAnnotation': - return wrapFollyOptional('double'); + return wrapOptional('double'); case 'BooleanTypeAnnotation': - return wrapFollyOptional('bool'); + return wrapOptional('bool'); case 'GenericObjectTypeAnnotation': return isRequired ? 'id ' : 'id _Nullable'; case 'ArrayTypeAnnotation': if (typeAnnotation.elementType == null) { return isRequired ? 'id ' : 'id _Nullable'; } - return wrapFollyOptional( + return wrapOptional( `facebook::react::LazyVector<${toObjCType( hasteModuleName, typeAnnotation.elementType, @@ -113,7 +113,7 @@ function toObjCType( hasteModuleName, structName, ); - return wrapFollyOptional(namespacedStructName); + return wrapOptional(namespacedStructName); default: (typeAnnotation.type: empty); throw new Error( @@ -190,7 +190,7 @@ function toObjCValue( ); return !isRequired - ? `(${value} == nil ? folly::none : folly::make_optional(${namespacedStructName}(${value})))` + ? `(${value} == nil ? std::nullopt : std::make_optional(${namespacedStructName}(${value})))` : `${namespacedStructName}(${value})`; default: (typeAnnotation.type: empty); diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/index.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/index.js index cd1aa762bbd213..8f8da790b90407 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/index.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/index.js @@ -82,7 +82,7 @@ const HeaderFileTemplate = ({ #import #import #import -#import +#import #import ` + diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap index 0a4751b99bd876..8dd68c0147fcef 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap @@ -26,7 +26,7 @@ Map { #import #import #import -#import +#import #import @@ -77,7 +77,7 @@ Map { #import #import #import -#import +#import #import namespace JS { @@ -134,11 +134,11 @@ namespace JS { namespace JS { namespace NativeSampleTurboModule { struct SpecOptionalsA { - folly::Optional optionalNumberProperty() const; - folly::Optional> optionalArrayProperty() const; - folly::Optional optionalObjectProperty() const; + std::optional optionalNumberProperty() const; + std::optional> optionalArrayProperty() const; + std::optional optionalObjectProperty() const; id _Nullable optionalGenericObjectProperty() const; - folly::Optional optionalBooleanTypeProperty() const; + std::optional optionalBooleanTypeProperty() const; SpecOptionalsA(NSDictionary *const v) : _v(v) {} private: @@ -169,9 +169,9 @@ namespace JS { namespace NativeSampleTurboModule { struct SpecGetArraysOptions { facebook::react::LazyVector arrayOfNumbers() const; - folly::Optional> optionalArrayOfNumbers() const; + std::optional> optionalArrayOfNumbers() const; facebook::react::LazyVector arrayOfStrings() const; - folly::Optional> optionalArrayOfStrings() const; + std::optional> optionalArrayOfStrings() const; facebook::react::LazyVector arrayOfObjects() const; SpecGetArraysOptions(NSDictionary *const v) : _v(v) {} @@ -250,27 +250,27 @@ inline double JS::NativeSampleTurboModule::SpecOptionalsAOptionalObjectProperty: id const p = _v[@\\"y\\"]; return RCTBridgingToDouble(p); } -inline folly::Optional JS::NativeSampleTurboModule::SpecOptionalsA::optionalNumberProperty() const +inline std::optional JS::NativeSampleTurboModule::SpecOptionalsA::optionalNumberProperty() const { id const p = _v[@\\"optionalNumberProperty\\"]; return RCTBridgingToOptionalDouble(p); } -inline folly::Optional> JS::NativeSampleTurboModule::SpecOptionalsA::optionalArrayProperty() const +inline std::optional> JS::NativeSampleTurboModule::SpecOptionalsA::optionalArrayProperty() const { id const p = _v[@\\"optionalArrayProperty\\"]; return RCTBridgingToOptionalVec(p, ^double(id itemValue_0) { return RCTBridgingToDouble(itemValue_0); }); } -inline folly::Optional JS::NativeSampleTurboModule::SpecOptionalsA::optionalObjectProperty() const +inline std::optional JS::NativeSampleTurboModule::SpecOptionalsA::optionalObjectProperty() const { id const p = _v[@\\"optionalObjectProperty\\"]; - return (p == nil ? folly::none : folly::make_optional(JS::NativeSampleTurboModule::SpecOptionalsAOptionalObjectProperty(p))); + return (p == nil ? std::nullopt : std::make_optional(JS::NativeSampleTurboModule::SpecOptionalsAOptionalObjectProperty(p))); } inline id _Nullable JS::NativeSampleTurboModule::SpecOptionalsA::optionalGenericObjectProperty() const { id const p = _v[@\\"optionalGenericObjectProperty\\"]; return p; } -inline folly::Optional JS::NativeSampleTurboModule::SpecOptionalsA::optionalBooleanTypeProperty() const +inline std::optional JS::NativeSampleTurboModule::SpecOptionalsA::optionalBooleanTypeProperty() const { id const p = _v[@\\"optionalBooleanTypeProperty\\"]; return RCTBridgingToOptionalBool(p); @@ -285,7 +285,7 @@ inline facebook::react::LazyVector JS::NativeSampleTurboModule::SpecGetA id const p = _v[@\\"arrayOfNumbers\\"]; return RCTBridgingToVec(p, ^double(id itemValue_0) { return RCTBridgingToDouble(itemValue_0); }); } -inline folly::Optional> JS::NativeSampleTurboModule::SpecGetArraysOptions::optionalArrayOfNumbers() const +inline std::optional> JS::NativeSampleTurboModule::SpecGetArraysOptions::optionalArrayOfNumbers() const { id const p = _v[@\\"optionalArrayOfNumbers\\"]; return RCTBridgingToOptionalVec(p, ^double(id itemValue_0) { return RCTBridgingToDouble(itemValue_0); }); @@ -295,7 +295,7 @@ inline facebook::react::LazyVector JS::NativeSampleTurboModule::Spec id const p = _v[@\\"arrayOfStrings\\"]; return RCTBridgingToVec(p, ^NSString *(id itemValue_0) { return RCTBridgingToString(itemValue_0); }); } -inline folly::Optional> JS::NativeSampleTurboModule::SpecGetArraysOptions::optionalArrayOfStrings() const +inline std::optional> JS::NativeSampleTurboModule::SpecGetArraysOptions::optionalArrayOfStrings() const { id const p = _v[@\\"optionalArrayOfStrings\\"]; return RCTBridgingToOptionalVec(p, ^NSString *(id itemValue_0) { return RCTBridgingToString(itemValue_0); }); @@ -335,7 +335,7 @@ Map { #import #import #import -#import +#import #import @@ -386,7 +386,7 @@ Map { #import #import #import -#import +#import #import namespace JS { @@ -442,9 +442,9 @@ namespace JS { struct Options { JS::AliasTurboModule::OptionsOffset offset() const; JS::AliasTurboModule::OptionsSize size() const; - folly::Optional displaySize() const; + std::optional displaySize() const; NSString *resizeMode() const; - folly::Optional allowExternalStorage() const; + std::optional allowExternalStorage() const; Options(NSDictionary *const v) : _v(v) {} private: @@ -512,17 +512,17 @@ inline JS::AliasTurboModule::OptionsSize JS::AliasTurboModule::Options::size() c id const p = _v[@\\"size\\"]; return JS::AliasTurboModule::OptionsSize(p); } -inline folly::Optional JS::AliasTurboModule::Options::displaySize() const +inline std::optional JS::AliasTurboModule::Options::displaySize() const { id const p = _v[@\\"displaySize\\"]; - return (p == nil ? folly::none : folly::make_optional(JS::AliasTurboModule::OptionsDisplaySize(p))); + return (p == nil ? std::nullopt : std::make_optional(JS::AliasTurboModule::OptionsDisplaySize(p))); } inline NSString *JS::AliasTurboModule::Options::resizeMode() const { id const p = _v[@\\"resizeMode\\"]; return RCTBridgingToOptionalString(p); } -inline folly::Optional JS::AliasTurboModule::Options::allowExternalStorage() const +inline std::optional JS::AliasTurboModule::Options::allowExternalStorage() const { id const p = _v[@\\"allowExternalStorage\\"]; return RCTBridgingToOptionalBool(p); @@ -557,7 +557,7 @@ Map { #import #import #import -#import +#import #import namespace JS { @@ -568,8 +568,8 @@ namespace JS { NSString *groupName() const; NSString *groupTypes() const; NSString *assetType() const; - folly::Optional maxSize() const; - folly::Optional> mimeTypes() const; + std::optional maxSize() const; + std::optional> mimeTypes() const; GetPhotosParams(NSDictionary *const v) : _v(v) {} private: @@ -609,11 +609,11 @@ namespace facebook { namespace JS { namespace NativeExceptionsManager { struct StackFrame { - folly::Optional column() const; + std::optional column() const; NSString *file() const; - folly::Optional lineNumber() const; + std::optional lineNumber() const; NSString *methodName() const; - folly::Optional collapse() const; + std::optional collapse() const; StackFrame(NSDictionary *const v) : _v(v) {} private: @@ -732,17 +732,17 @@ inline NSString *JS::NativeCameraRollManager::GetPhotosParams::assetType() const id const p = _v[@\\"assetType\\"]; return RCTBridgingToOptionalString(p); } -inline folly::Optional JS::NativeCameraRollManager::GetPhotosParams::maxSize() const +inline std::optional JS::NativeCameraRollManager::GetPhotosParams::maxSize() const { id const p = _v[@\\"maxSize\\"]; return RCTBridgingToOptionalDouble(p); } -inline folly::Optional> JS::NativeCameraRollManager::GetPhotosParams::mimeTypes() const +inline std::optional> JS::NativeCameraRollManager::GetPhotosParams::mimeTypes() const { id const p = _v[@\\"mimeTypes\\"]; return RCTBridgingToOptionalVec(p, ^NSString *(id itemValue_0) { return RCTBridgingToString(itemValue_0); }); } -inline folly::Optional JS::NativeExceptionsManager::StackFrame::column() const +inline std::optional JS::NativeExceptionsManager::StackFrame::column() const { id const p = _v[@\\"column\\"]; return RCTBridgingToOptionalDouble(p); @@ -752,7 +752,7 @@ inline NSString *JS::NativeExceptionsManager::StackFrame::file() const id const p = _v[@\\"file\\"]; return RCTBridgingToString(p); } -inline folly::Optional JS::NativeExceptionsManager::StackFrame::lineNumber() const +inline std::optional JS::NativeExceptionsManager::StackFrame::lineNumber() const { id const p = _v[@\\"lineNumber\\"]; return RCTBridgingToOptionalDouble(p); @@ -762,7 +762,7 @@ inline NSString *JS::NativeExceptionsManager::StackFrame::methodName() const id const p = _v[@\\"methodName\\"]; return RCTBridgingToString(p); } -inline folly::Optional JS::NativeExceptionsManager::StackFrame::collapse() const +inline std::optional JS::NativeExceptionsManager::StackFrame::collapse() const { id const p = _v[@\\"collapse\\"]; return RCTBridgingToOptionalBool(p); @@ -847,7 +847,7 @@ Map { #import #import #import -#import +#import #import namespace JS { @@ -953,7 +953,7 @@ Map { #import #import #import -#import +#import #import