mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
[ReactNative] Remove module info from the data section + allow external modules
Summary: @public The information we required about the exported methods were previously stored on the binary's DATA section, which didn't allow to access methods on different static libraries, or in any dynamic library at all. Instead of fetching information from all the DATA segments, this diff changes the macro in order to create a new method, that returns the required information about the original method. The module itself is registered at load time, and on the bridge initialization all the auto-generated methods are called to gather the methods' information. Test Plan: UIExplorer previously had a dependency on `RCTTest`, because it had a `TestModule` that had to be on the same library. `RCTTest` is now a dependency of `UIExplorerIntegrationTests`. So the tests themselves running should test it.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "RCTDefines.h"
|
||||
|
||||
@class RCTBridge;
|
||||
|
||||
/**
|
||||
@@ -62,8 +64,9 @@ extern const dispatch_queue_t RCTJSThread;
|
||||
* match the Objective-C class name.
|
||||
*/
|
||||
#define RCT_EXPORT_MODULE(js_name) \
|
||||
+ (NSString *)moduleName { __attribute__((used, section("__DATA,RCTExportModule" \
|
||||
))) static const char *__rct_export_entry__ = { __func__ }; return @#js_name; }
|
||||
RCT_EXTERN void RCTRegisterModule(Class); \
|
||||
+ (NSString *)moduleName { return @#js_name; } \
|
||||
+ (void)load { RCTRegisterModule([self class]); }
|
||||
|
||||
/**
|
||||
* Wrap the parameter line of your method implementation with this macro to
|
||||
@@ -173,11 +176,10 @@ extern const dispatch_queue_t RCTJSThread;
|
||||
* Like RCT_EXTERN_REMAP_METHOD, but allows setting a custom JavaScript name.
|
||||
*/
|
||||
#define RCT_EXTERN_REMAP_METHOD(js_name, method) \
|
||||
- (void)__rct_export__##method { \
|
||||
__attribute__((used, section("__DATA,RCTExport"))) \
|
||||
__attribute__((__aligned__(1))) \
|
||||
static const char *__rct_export_entry__[] = { __func__, #method, #js_name }; \
|
||||
}
|
||||
+ (NSArray *)RCT_CONCAT(__rct_export__, __COUNTER__) { \
|
||||
return @[@#js_name, @#method]; \
|
||||
} \
|
||||
|
||||
|
||||
/**
|
||||
* The queue that will be used to call all exported methods. If omitted, this
|
||||
|
||||
Reference in New Issue
Block a user