2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
@class RCTBridge;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of a block that is capable of sending a response to a bridged
|
|
|
|
* operation. Use this for returning callback methods to JS.
|
|
|
|
*/
|
|
|
|
typedef void (^RCTResponseSenderBlock)(NSArray *response);
|
|
|
|
|
|
|
|
/**
|
2015-02-24 17:06:57 +00:00
|
|
|
* Provides the interface needed to register a bridge module.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-04-08 12:42:43 +00:00
|
|
|
@protocol RCTBridgeModule <NSObject>
|
2015-02-20 04:10:52 +00:00
|
|
|
@optional
|
|
|
|
|
|
|
|
/**
|
2015-03-01 23:33:55 +00:00
|
|
|
* A reference to the RCTBridge. Useful for modules that require access
|
|
|
|
* to bridge features, such as sending events or making JS 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;
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-04-10 14:28:10 +00:00
|
|
|
@property (nonatomic, weak) RCTBridge *bridge;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
/**
|
[Bridge] `RCT_REMAP_METHOD(js_name, selector)`
Summary:
cc @a2 @nicklockwood
This diff introduces a new macro called `RCT_EXPORT_NAMED_METHOD`, which is like `RCT_EXPORT_METHOD` but lets you choose the name of the method in JS. This diff is backwards compatible with the `RCT_EXPORT_METHOD` and legacy `RCT_EXPORT` macros.
The entries in the data segment now contain `__func__`, the Obj-C selector signature, and the JS name. If the JS name is `NULL`, we take the legacy `RCT_EXPORT` code path. If the JS name is an empty string, we use the Obj-C selector's name up to the first colon (that is, the behavior of `RCT_EXPORT_METHOD`).
Since there are three values in each data segment entry, the macros now specify 1-byte alignment. Without the byte alignment, the compiler defaults to 2-byte alignment meaning that each entry takes up 4 bytes instead of 3. The extra byte isn't a concern but being explicit about the alignment should reduce compiler surprises.
Closes https://github.com/facebook/react-native/pull/802
Github Author: James Ide <ide@jameside.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-14 20:03:16 +00:00
|
|
|
* Place this macro in your class implementation to automatically register
|
2015-04-08 12:42:43 +00:00
|
|
|
* 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.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-04-08 12:42:43 +00:00
|
|
|
#define RCT_EXPORT_MODULE(js_name) \
|
2015-04-11 22:08:00 +00:00
|
|
|
+ (NSString *)moduleName { __attribute__((used, section("__DATA,RCTExportModule" \
|
|
|
|
))) static const char *__rct_export_entry__ = { __func__ }; return @#js_name; }
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-08 15:52:48 +00:00
|
|
|
/**
|
|
|
|
* Wrap the parameter line of your method implementation with this macro to
|
[Bridge] `RCT_REMAP_METHOD(js_name, selector)`
Summary:
cc @a2 @nicklockwood
This diff introduces a new macro called `RCT_EXPORT_NAMED_METHOD`, which is like `RCT_EXPORT_METHOD` but lets you choose the name of the method in JS. This diff is backwards compatible with the `RCT_EXPORT_METHOD` and legacy `RCT_EXPORT` macros.
The entries in the data segment now contain `__func__`, the Obj-C selector signature, and the JS name. If the JS name is `NULL`, we take the legacy `RCT_EXPORT` code path. If the JS name is an empty string, we use the Obj-C selector's name up to the first colon (that is, the behavior of `RCT_EXPORT_METHOD`).
Since there are three values in each data segment entry, the macros now specify 1-byte alignment. Without the byte alignment, the compiler defaults to 2-byte alignment meaning that each entry takes up 4 bytes instead of 3. The extra byte isn't a concern but being explicit about the alignment should reduce compiler surprises.
Closes https://github.com/facebook/react-native/pull/802
Github Author: James Ide <ide@jameside.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-14 20:03:16 +00:00
|
|
|
* expose it to JS. By default the exposed method will match the first part of
|
|
|
|
* the Objective-C method selector name (up to the first colon). Use
|
|
|
|
* RCT_REMAP_METHOD to specify the JS name of the method.
|
2015-04-08 15:52:48 +00:00
|
|
|
*
|
2015-04-11 22:08:00 +00:00
|
|
|
* For example, in ModuleName.m:
|
2015-04-08 15:52:48 +00:00
|
|
|
*
|
|
|
|
* - (void)doSomething:(NSString *)aString withA:(NSInteger)a andB:(NSInteger)b
|
2015-04-11 22:08:00 +00:00
|
|
|
* { ... }
|
2015-04-08 15:52:48 +00:00
|
|
|
*
|
|
|
|
* becomes
|
|
|
|
*
|
|
|
|
* RCT_EXPORT_METHOD(doSomething:(NSString *)aString
|
|
|
|
* withA:(NSInteger)a
|
|
|
|
* andB:(NSInteger)b)
|
2015-04-11 22:08:00 +00:00
|
|
|
* { ... }
|
2015-04-08 15:52:48 +00:00
|
|
|
*
|
|
|
|
* and is exposed to JavaScript as `NativeModules.ModuleName.doSomething`.
|
|
|
|
*/
|
|
|
|
#define RCT_EXPORT_METHOD(method) \
|
[Bridge] `RCT_REMAP_METHOD(js_name, selector)`
Summary:
cc @a2 @nicklockwood
This diff introduces a new macro called `RCT_EXPORT_NAMED_METHOD`, which is like `RCT_EXPORT_METHOD` but lets you choose the name of the method in JS. This diff is backwards compatible with the `RCT_EXPORT_METHOD` and legacy `RCT_EXPORT` macros.
The entries in the data segment now contain `__func__`, the Obj-C selector signature, and the JS name. If the JS name is `NULL`, we take the legacy `RCT_EXPORT` code path. If the JS name is an empty string, we use the Obj-C selector's name up to the first colon (that is, the behavior of `RCT_EXPORT_METHOD`).
Since there are three values in each data segment entry, the macros now specify 1-byte alignment. Without the byte alignment, the compiler defaults to 2-byte alignment meaning that each entry takes up 4 bytes instead of 3. The extra byte isn't a concern but being explicit about the alignment should reduce compiler surprises.
Closes https://github.com/facebook/react-native/pull/802
Github Author: James Ide <ide@jameside.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-14 20:03:16 +00:00
|
|
|
RCT_REMAP_METHOD(, method)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Similar to RCT_EXPORT_METHOD but lets you set the JS name of the exported
|
|
|
|
* method. Example usage:
|
|
|
|
*
|
|
|
|
* RCT_REMAP_METHOD(executeQueryWithParameters,
|
|
|
|
* executeQuery:(NSString *)query parameters:(NSDictionary *)parameters)
|
|
|
|
* { ... }
|
|
|
|
*/
|
|
|
|
#define RCT_REMAP_METHOD(js_name, method) \
|
2015-04-08 15:52:48 +00:00
|
|
|
- (void)__rct_export__##method { \
|
|
|
|
__attribute__((used, section("__DATA,RCTExport"))) \
|
[Bridge] `RCT_REMAP_METHOD(js_name, selector)`
Summary:
cc @a2 @nicklockwood
This diff introduces a new macro called `RCT_EXPORT_NAMED_METHOD`, which is like `RCT_EXPORT_METHOD` but lets you choose the name of the method in JS. This diff is backwards compatible with the `RCT_EXPORT_METHOD` and legacy `RCT_EXPORT` macros.
The entries in the data segment now contain `__func__`, the Obj-C selector signature, and the JS name. If the JS name is `NULL`, we take the legacy `RCT_EXPORT` code path. If the JS name is an empty string, we use the Obj-C selector's name up to the first colon (that is, the behavior of `RCT_EXPORT_METHOD`).
Since there are three values in each data segment entry, the macros now specify 1-byte alignment. Without the byte alignment, the compiler defaults to 2-byte alignment meaning that each entry takes up 4 bytes instead of 3. The extra byte isn't a concern but being explicit about the alignment should reduce compiler surprises.
Closes https://github.com/facebook/react-native/pull/802
Github Author: James Ide <ide@jameside.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-14 20:03:16 +00:00
|
|
|
__attribute__((__aligned__(1))) \
|
|
|
|
static const char *__rct_export_entry__[] = { __func__, #method, #js_name }; \
|
2015-04-08 15:52:48 +00:00
|
|
|
} \
|
|
|
|
- (void)method
|
2015-02-20 04:10:52 +00:00
|
|
|
|
[Bridge] `RCT_REMAP_METHOD(js_name, selector)`
Summary:
cc @a2 @nicklockwood
This diff introduces a new macro called `RCT_EXPORT_NAMED_METHOD`, which is like `RCT_EXPORT_METHOD` but lets you choose the name of the method in JS. This diff is backwards compatible with the `RCT_EXPORT_METHOD` and legacy `RCT_EXPORT` macros.
The entries in the data segment now contain `__func__`, the Obj-C selector signature, and the JS name. If the JS name is `NULL`, we take the legacy `RCT_EXPORT` code path. If the JS name is an empty string, we use the Obj-C selector's name up to the first colon (that is, the behavior of `RCT_EXPORT_METHOD`).
Since there are three values in each data segment entry, the macros now specify 1-byte alignment. Without the byte alignment, the compiler defaults to 2-byte alignment meaning that each entry takes up 4 bytes instead of 3. The extra byte isn't a concern but being explicit about the alignment should reduce compiler surprises.
Closes https://github.com/facebook/react-native/pull/802
Github Author: James Ide <ide@jameside.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-14 20:03:16 +00:00
|
|
|
/**
|
|
|
|
* Deprecated, do not use.
|
|
|
|
*/
|
|
|
|
#define RCT_EXPORT(js_name) \
|
|
|
|
_Pragma("message(\"RCT_EXPORT is deprecated. Use RCT_EXPORT_METHOD instead.\")") \
|
|
|
|
__attribute__((used, section("__DATA,RCTExport"))) \
|
|
|
|
__attribute__((__aligned__(1))) \
|
|
|
|
static const char *__rct_export_entry__[] = { __func__, #js_name, NULL }
|
|
|
|
|
2015-04-18 17:43:20 +00:00
|
|
|
/**
|
|
|
|
* The queue that will be used to call all exported methods. If omitted, this
|
2015-04-20 19:06:02 +00:00
|
|
|
* will call on the 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:
|
|
|
|
*
|
|
|
|
* - (dispatch_queue_t)methodQueue
|
|
|
|
* {
|
|
|
|
* return dispatch_get_main_queue();
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* If your methods perform heavy work such as synchronous filesystem or network
|
|
|
|
* access, you probably don't want to block the default background queue, as
|
|
|
|
* this will stall other methods. Instead, you should return a custom serial
|
|
|
|
* queue, like this:
|
2015-04-18 17:43:20 +00:00
|
|
|
*
|
|
|
|
* - (dispatch_queue_t)methodQueue
|
|
|
|
* {
|
|
|
|
* return dispatch_queue_create("com.mydomain.FileQueue", DISPATCH_QUEUE_SERIAL);
|
|
|
|
* }
|
|
|
|
*
|
2015-04-20 19:06:02 +00:00
|
|
|
* Alternatively, if only some methods of the module should be executed on a
|
|
|
|
* particular queue you can leave this method unimplemented, and simply
|
|
|
|
* dispatch_async() to the required queue within the method itself.
|
2015-04-18 17:43:20 +00:00
|
|
|
*/
|
|
|
|
- (dispatch_queue_t)methodQueue;
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
|
|
|
* Injects constants into JS. These constants are made accessible via
|
2015-03-01 23:33:55 +00:00
|
|
|
* NativeModules.ModuleName.X. This method is called when the module is
|
|
|
|
* registered by the bridge. It is only called once for the lifetime of the
|
|
|
|
* bridge, so it is not suitable for returning dynamic values, but may be
|
|
|
|
* used for long-lived values such as session keys, that are regenerated only
|
|
|
|
* as part of a reload of the entire React application.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-02-24 17:06:57 +00:00
|
|
|
- (NSDictionary *)constantsToExport;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies the module that a batch of JS method invocations has just completed.
|
|
|
|
*/
|
|
|
|
- (void)batchDidComplete;
|
|
|
|
|
|
|
|
@end
|