Skip to content

Commit

Permalink
iOS: introduce RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD() macro to provide…
Browse files Browse the repository at this point in the history
… 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 47bfbbb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions React/Base/RCTBridgeModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 47bfbbb

Please sign in to comment.