diff --git a/Libraries/Alert/NativeAlertManager.js b/Libraries/Alert/NativeAlertManager.js index 345fd08c6e6..452be85c5b1 100644 --- a/Libraries/Alert/NativeAlertManager.js +++ b/Libraries/Alert/NativeAlertManager.js @@ -16,7 +16,7 @@ import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry'; export type Args = {| title?: string, message?: string, - buttons?: Object, // TODO: have a better type + buttons?: Array, // TODO: have a better type type?: string, defaultValue?: string, cancelButtonKey?: string, diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h index c3fe3f35d86..dfd5316fdd2 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h @@ -196,7 +196,7 @@ namespace JS { struct Args { NSString *title() const; NSString *message() const; - id _Nullable buttons() const; + folly::Optional>> buttons() const; NSString *type() const; NSString *defaultValue() const; NSString *cancelButtonKey() const; @@ -2504,10 +2504,10 @@ inline NSString *JS::NativeAlertManager::Args::message() const id const p = _v[@"message"]; return RCTBridgingToString(p); } -inline id _Nullable JS::NativeAlertManager::Args::buttons() const +inline folly::Optional>> JS::NativeAlertManager::Args::buttons() const { id const p = _v[@"buttons"]; - return p; + return RCTBridgingToOptionalVec(p, ^id(id itemValue_0) { return itemValue_0; }); } inline NSString *JS::NativeAlertManager::Args::type() const { diff --git a/RNTester/Podfile.lock b/RNTester/Podfile.lock index 2dcfa4d7fd2..d3973e94811 100644 --- a/RNTester/Podfile.lock +++ b/RNTester/Podfile.lock @@ -291,7 +291,7 @@ DEPENDENCIES: - Yoga (from `../ReactCommon/yoga`) SPEC REPOS: - https://github.com/CocoaPods/Specs.git: + https://github.com/cocoapods/specs.git: - boost-for-react-native EXTERNAL SOURCES: @@ -385,4 +385,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 060903e270072f1e192b064848e6c34528af1c87 -COCOAPODS: 1.8.3 +COCOAPODS: 1.7.1 diff --git a/React/CoreModules/BUCK b/React/CoreModules/BUCK index 2128fab5a96..2505b6501e2 100644 --- a/React/CoreModules/BUCK +++ b/React/CoreModules/BUCK @@ -69,6 +69,9 @@ rn_apple_library( ) + react_module_plugin_providers( name = "ActionSheetManager", native_class_func = "RCTActionSheetManagerCls", + ) + react_module_plugin_providers( + name = "AlertManager", + native_class_func = "RCTAlertManagerCls", ), plugins_header = "FBCoreModulesPlugins.h", preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + get_debug_preprocessor_flags() + rn_extra_build_flags() + [ diff --git a/React/CoreModules/CoreModulesPlugins.h b/React/CoreModules/CoreModulesPlugins.h index 6eb37cc375d..30b6b8d357d 100644 --- a/React/CoreModules/CoreModulesPlugins.h +++ b/React/CoreModules/CoreModulesPlugins.h @@ -39,6 +39,7 @@ Class RCTClipboardCls(void) __attribute__((used)); Class RCTI18nManagerCls(void) __attribute__((used)); Class RCTSourceCodeCls(void) __attribute__((used)); Class RCTActionSheetManagerCls(void) __attribute__((used)); +Class RCTAlertManagerCls(void) __attribute__((used)); #ifdef __cplusplus } diff --git a/React/CoreModules/CoreModulesPlugins.mm b/React/CoreModules/CoreModulesPlugins.mm index ddfd86244e8..3e58989e36b 100644 --- a/React/CoreModules/CoreModulesPlugins.mm +++ b/React/CoreModules/CoreModulesPlugins.mm @@ -28,6 +28,7 @@ Class RCTCoreModulesClassProvider(const char *name) { {"I18nManager", RCTI18nManagerCls}, {"SourceCode", RCTSourceCodeCls}, {"ActionSheetManager", RCTActionSheetManagerCls}, + {"AlertManager", RCTAlertManagerCls}, }; auto p = sCoreModuleClassMap.find(name); diff --git a/React/Modules/RCTAlertManager.h b/React/CoreModules/RCTAlertManager.h similarity index 100% rename from React/Modules/RCTAlertManager.h rename to React/CoreModules/RCTAlertManager.h diff --git a/React/Modules/RCTAlertManager.m b/React/CoreModules/RCTAlertManager.mm similarity index 75% rename from React/Modules/RCTAlertManager.m rename to React/CoreModules/RCTAlertManager.mm index bb1f3ceaa42..6781104e611 100644 --- a/React/Modules/RCTAlertManager.m +++ b/React/CoreModules/RCTAlertManager.mm @@ -7,10 +7,14 @@ #import "RCTAlertManager.h" -#import "RCTAssert.h" -#import "RCTConvert.h" -#import "RCTLog.h" -#import "RCTUtils.h" +#import +#import +#import +#import +#import +#import + +#import "CoreModulesPlugins.h" @implementation RCTConvert (UIAlertViewStyle) @@ -23,7 +27,7 @@ RCT_ENUM_CONVERTER(RCTAlertViewStyle, (@{ @end -@interface RCTAlertManager() +@interface RCTAlertManager() @end @@ -60,17 +64,17 @@ RCT_EXPORT_MODULE() * The key from the `buttons` dictionary is passed back in the callback on click. * Buttons are displayed in the order they are specified. */ -RCT_EXPORT_METHOD(alertWithArgs:(NSDictionary *)args +RCT_EXPORT_METHOD(alertWithArgs:(JS::NativeAlertManager::Args &)args callback:(RCTResponseSenderBlock)callback) { - NSString *title = [RCTConvert NSString:args[@"title"]]; - NSString *message = [RCTConvert NSString:args[@"message"]]; - RCTAlertViewStyle type = [RCTConvert RCTAlertViewStyle:args[@"type"]]; - NSArray *buttons = [RCTConvert NSDictionaryArray:args[@"buttons"]]; - NSString *defaultValue = [RCTConvert NSString:args[@"defaultValue"]]; - NSString *cancelButtonKey = [RCTConvert NSString:args[@"cancelButtonKey"]]; - NSString *destructiveButtonKey = [RCTConvert NSString:args[@"destructiveButtonKey"]]; - UIKeyboardType keyboardType = [RCTConvert UIKeyboardType:args[@"keyboardType"]]; + NSString *title = [RCTConvert NSString:args.title()]; + NSString *message = [RCTConvert NSString:args.message()]; + RCTAlertViewStyle type = [RCTConvert RCTAlertViewStyle:args.type()]; + NSArray *buttons = [RCTConvert NSDictionaryArray:RCTConvertOptionalVecToArray(args.buttons(), ^id(id element) { return element; })]; + NSString *defaultValue = [RCTConvert NSString:args.defaultValue()]; + NSString *cancelButtonKey = [RCTConvert NSString:args.cancelButtonKey()]; + NSString *destructiveButtonKey = [RCTConvert NSString:args.destructiveButtonKey()]; + UIKeyboardType keyboardType = [RCTConvert UIKeyboardType:args.keyboardType()]; if (!title && !message) { RCTLogError(@"Must specify either an alert title, or message, or both"); @@ -92,7 +96,16 @@ RCT_EXPORT_METHOD(alertWithArgs:(NSDictionary *)args UIViewController *presentingController = RCTPresentedViewController(); if (presentingController == nil) { - RCTLogError(@"Tried to display alert view but there is no application window. args: %@", args); + RCTLogError(@"Tried to display alert view but there is no application window. args: %@", @{ + @"title": args.title() ?: [NSNull null], + @"message": args.message() ?: [NSNull null], + @"buttons": RCTConvertOptionalVecToArray(args.buttons(), ^id(id element) { return element; }) ?: [NSNull null], + @"type": args.type() ?: [NSNull null], + @"defaultValue": args.defaultValue() ?: [NSNull null], + @"cancelButtonKey": args.cancelButtonKey() ?: [NSNull null], + @"destructiveButtonKey": args.destructiveButtonKey() ?: [NSNull null], + @"keyboardType": args.keyboardType() ?: [NSNull null], + }); return; } @@ -182,4 +195,13 @@ RCT_EXPORT_METHOD(alertWithArgs:(NSDictionary *)args }); } +- (std::shared_ptr)getTurboModuleWithJsInvoker:(std::shared_ptr)jsInvoker +{ + return std::make_shared(self, jsInvoker); +} + @end + +Class RCTAlertManagerCls(void) { + return RCTAlertManager.class; +}