Make RCTAlertManager TurboModule-compatible

Summary:
**Note:** This was landed in D17722913, but reverted in D17855088. The revert had nothing to do with this NativeModule.

Changelog: [iOS][Added] Make RCTAlertManager TurboModule-compatible

Reviewed By: PeteTheHeat

Differential Revision: D17917827

fbshipit-source-id: d86ea2cddddd9535d656709296c74aebd6f45793
This commit is contained in:
Ramanpreet Nara authored and Facebook Github Bot committed 2019-10-15 09:16:56 -07:00
1 parent be89e4d928
commit da6274ba76
8 files changed
+48 -21

No files matched your search

+1 -1
View File
@@ -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<Object>, // TODO: have a better type
type?: string,
defaultValue?: string,
cancelButtonKey?: string,
@@ -196,7 +196,7 @@ namespace JS {
struct Args {
NSString *title() const;
NSString *message() const;
id<NSObject> _Nullable buttons() const;
folly::Optional<facebook::react::LazyVector<id<NSObject>>> 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<NSObject> _Nullable JS::NativeAlertManager::Args::buttons() const
inline folly::Optional<facebook::react::LazyVector<id<NSObject>>> JS::NativeAlertManager::Args::buttons() const
{
id const p = _v[@"buttons"];
return p;
return RCTBridgingToOptionalVec(p, ^id<NSObject>(id itemValue_0) { return itemValue_0; });
}
inline NSString *JS::NativeAlertManager::Args::type() const
{
+2 -2
View File
@@ -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
+3
View File
@@ -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() + [
+1
View File
@@ -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
}
+1
View File
@@ -28,6 +28,7 @@ Class RCTCoreModulesClassProvider(const char *name) {
{"I18nManager", RCTI18nManagerCls},
{"SourceCode", RCTSourceCodeCls},
{"ActionSheetManager", RCTActionSheetManagerCls},
{"AlertManager", RCTAlertManagerCls},
};
auto p = sCoreModuleClassMap.find(name);
File renamed without changes.
@@ -7,10 +7,14 @@
#import "RCTAlertManager.h"
#import "RCTAssert.h"
#import "RCTConvert.h"
#import "RCTLog.h"
#import "RCTUtils.h"
#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <RCTTypeSafety/RCTConvertHelpers.h>
#import <React/RCTAssert.h>
#import <React/RCTConvert.h>
#import <React/RCTLog.h>
#import <React/RCTUtils.h>
#import "CoreModulesPlugins.h"
@implementation RCTConvert (UIAlertViewStyle)
@@ -23,7 +27,7 @@ RCT_ENUM_CONVERTER(RCTAlertViewStyle, (@{
@end
@interface RCTAlertManager()
@interface RCTAlertManager() <NativeAlertManagerSpec>
@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<NSDictionary *> *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<NSDictionary *> *buttons = [RCTConvert NSDictionaryArray:RCTConvertOptionalVecToArray(args.buttons(), ^id(id<NSObject> 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<NSObject> 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<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
{
return std::make_shared<facebook::react::NativeAlertManagerSpecJSI>(self, jsInvoker);
}
@end
Class RCTAlertManagerCls(void) {
return RCTAlertManager.class;
}