From 47bfbbb1d3f2b67c053d31d9ed79ec3c50a127cf Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Tue, 17 Oct 2017 06:12:11 -0700 Subject: [PATCH] iOS: introduce RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD() macro to provide the return type of a sync method Summary: This provides a way to customize the return type of a sync exported method, instead of just using `id`. ``` RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSString *, sync1:(NSString *)x) { return @"hello"; } ``` The return type needs to be a sub type of `id` - so scalars like `double` won't work (the bridge will crash). Differential Revision: D6068884 fbshipit-source-id: 43a98141f1d0aef335aa0b33a24219f8e574e58b --- React/Base/RCTBridgeModule.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/React/Base/RCTBridgeModule.h b/React/Base/RCTBridgeModule.h index 1ab00bb5cfb..25bff04134e 100644 --- a/React/Base/RCTBridgeModule.h +++ b/React/Base/RCTBridgeModule.h @@ -171,7 +171,11 @@ RCT_EXTERN void RCTRegisterModule(Class); \ * is currently not supported. */ #define RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(method) \ - RCT_REMAP_BLOCKING_SYNCHRONOUS_METHOD(, method) + RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(id, method) + +#define RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(returnType, method) \ + RCT_REMAP_BLOCKING_SYNCHRONOUS_METHOD(, returnType, method) + /** * Similar to RCT_EXPORT_METHOD but lets you set the JS name of the exported @@ -193,9 +197,9 @@ RCT_EXTERN void RCTRegisterModule(Class); \ * executeQuery:(NSString *)query parameters:(NSDictionary *)parameters) * { ... } */ -#define RCT_REMAP_BLOCKING_SYNCHRONOUS_METHOD(js_name, method) \ +#define RCT_REMAP_BLOCKING_SYNCHRONOUS_METHOD(js_name, returnType, method) \ _RCT_EXTERN_REMAP_METHOD(js_name, method, YES) \ - - (id)method; + - (returnType)method; /** * Use this macro in a private Objective-C implementation file to automatically