...
|
...
|
@@ -35,10 +35,11 @@ extern NSString * const YH_CallServiceObserverKey; |
|
|
@protocol YH_BridgeModule <NSObject>
|
|
|
|
|
|
/**
|
|
|
* Place this macro in your class implementation to automatically register
|
|
|
* your module with the bridge when it loads. The optional js_name argument
|
|
|
* will be used as the JS module name. If omitted, the JS module name will
|
|
|
* match the Objective-C class name.
|
|
|
*
|
|
|
* 用于将module自动注册到bridge
|
|
|
* 注册的动作发生在module class被load的时
|
|
|
* export_name 注册的module名称,若不指定则使用module class名称的字符串表示
|
|
|
*
|
|
|
*/
|
|
|
#define YH_EXPORT_MODULE(export_name) \
|
|
|
extern void YH_RegisterModule(Class); \
|
...
|
...
|
@@ -51,38 +52,38 @@ extern void YH_RegisterModule(Class); \ |
|
|
@optional
|
|
|
|
|
|
/**
|
|
|
* A reference to the YH_WatchDog. Useful for modules that require access
|
|
|
* to bridge features, such as sending events or making service calls. This
|
|
|
* will be set automatically by the bridge when it initializes the module.
|
|
|
* To implement this in your module, just add `@synthesize bridge = _bridge;`
|
|
|
*
|
|
|
* 指向YH_WatchDog的引用
|
|
|
* 用于发起module提供的service调用
|
|
|
* module初始化时自动设置
|
|
|
* 如果需要在创建的module中使用,在module实现中加上`@synthesize bridge = _bridge;`即可
|
|
|
*
|
|
|
*/
|
|
|
@property (nonatomic, weak, readonly) YH_WatchDog *bridge;
|
|
|
|
|
|
/**
|
|
|
* The queue that will be used to call all exported methods. If omitted, this
|
|
|
* will call on a default background queue, which is avoids blocking the main
|
|
|
* thread.
|
|
|
*
|
|
|
* If the methods in your module need to interact with UIKit methods, they will
|
|
|
* probably need to call those on the main thread, as most of UIKit is main-
|
|
|
* thread-only. You can tell React Native to call your module methods on the
|
|
|
* main thread by returning a reference to the main queue, like this:
|
|
|
* 调用service时使用的队列。若不指定则在默认的后台队列调用,这样不会阻塞主线程
|
|
|
* 如果需要指定module服务调用所在队列,可以如下实现:
|
|
|
*
|
|
|
* - (dispatch_queue_t)methodQueue
|
|
|
* {
|
|
|
* return dispatch_get_main_queue();
|
|
|
* }
|
|
|
*
|
|
|
* If you don't want to specify the queue yourself, but you need to use it
|
|
|
* inside your class (e.g. if you have internal methods that need to dispatch
|
|
|
* onto that queue), you can just add `@synthesize methodQueue = _methodQueue;`
|
|
|
* and the bridge will populate the methodQueue property for you automatically
|
|
|
* when it initializes the module.
|
|
|
* 如果不想指定队列,但又需要在module中使用,在module实现中添加 `@synthesize methodQueue = _methodQueue;`
|
|
|
* methodQueue property会在module初始化时自动设置
|
|
|
*
|
|
|
*/
|
|
|
@property (nonatomic, strong, readonly) dispatch_queue_t serviceQueue;
|
|
|
|
|
|
/**
|
|
|
* Export service without operation queue
|
|
|
* 注册没有operation queue支持的service
|
|
|
* 此时调用service时步骤:
|
|
|
* 1.调用service
|
|
|
* 2.封装生成NSInvocation调用
|
|
|
* 3.调用NSInvocation
|
|
|
*
|
|
|
* eg:
|
|
|
* YH_EXPORT_SERVICE(login) {...}
|
|
|
* |
|
...
|
...
|
@@ -101,7 +102,7 @@ extern void YH_RegisterModule(Class); \ |
|
|
YH_REMAP_SERVICE(service, YH_CONCAT_SERVICE_NAME(service))
|
|
|
|
|
|
/**
|
|
|
* Translate service method name from service name
|
|
|
* 根据service名称拼接出service方法的名称
|
|
|
*
|
|
|
* eg:
|
|
|
* YH_CONCAT_SERVICE_NAME(login)
|
...
|
...
|
@@ -115,10 +116,12 @@ YH_CONCAT(service, Service:(NSDictionary *)parameters) |
|
|
|
|
|
|
|
|
/**
|
|
|
* Similar to YH_EXPORT_SERVICE but lets you set the name of the exported
|
|
|
* service. Example usage:
|
|
|
* export_name service名称
|
|
|
* service service方法名称
|
|
|
*
|
|
|
* YH_REMAP_SERVICE(login)
|
|
|
* Example usage:
|
|
|
*
|
|
|
* YH_REMAP_SERVICE(login, loginService:(NSDictionary *)parameters)
|
|
|
* { ... }
|
|
|
*/
|
|
|
#define YH_REMAP_SERVICE(export_name, service) \
|
...
|
...
|
@@ -134,6 +137,13 @@ return @[@#export_name, @#service]; \ |
|
|
|
|
|
/**
|
|
|
* Export service with operation queue
|
|
|
* 注册有operation queue支持的service
|
|
|
* 此时调用service时步骤:
|
|
|
* 1.调用service
|
|
|
* 2.service调用放入队列
|
|
|
* 3.封装生成NSInvocation调用
|
|
|
* 4.调用NSInvocation
|
|
|
*
|
|
|
* eg:
|
|
|
* YH_EXPORT_SERVICE_WITH_QUEUE(login) {...}
|
|
|
* |
|
...
|
...
|
@@ -164,7 +174,8 @@ YH_REMAP_SERVICE(service, YH_CONCAT_SERVICE_NAME(service)) |
|
|
|
|
|
|
|
|
/**
|
|
|
* Service queue getter and setter
|
|
|
* 生成Service调用所用queue的getter和setter
|
|
|
*
|
|
|
* eg:
|
|
|
* YH_EXTERN_SERVICE_QUEUE(login)
|
|
|
* |
|
...
|
...
|
@@ -190,7 +201,8 @@ static char YH_SERVICE_QUEUE_KEY(service); \ |
|
|
|
|
|
|
|
|
/**
|
|
|
* Declare service callback signal
|
|
|
* 声明用于回调service结果的signal
|
|
|
*
|
|
|
* eg:
|
|
|
* YH_DECLARE_SIGNAL_PROPERTY(login, Dictionary)
|
|
|
* |
|
...
|
...
|
@@ -203,7 +215,8 @@ static char YH_SERVICE_QUEUE_KEY(service); \ |
|
|
|
|
|
|
|
|
/**
|
|
|
* Init service callback signal
|
|
|
* 初始化用于回调service结果的signal
|
|
|
*
|
|
|
* eg:
|
|
|
* YH_INIT_SIGNAL_PROPERTY(login, type)
|
|
|
* |
|
...
|
...
|
|