Permalink
Browse files

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
  • Loading branch information...
fkgozali authored and facebook-github-bot committed Oct 17, 2017
1 parent dc16150 commit 47bfbbb1d3f2b67c053d31d9ed79ec3c50a127cf
Showing with 7 additions and 3 deletions.
  1. +7 −3 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

0 comments on commit 47bfbbb

Please sign in to comment.