Skip to content

Commit

Permalink
Added non-class-scanning-based approach fror registering js methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Apr 8, 2015
1 parent 21a054e commit bf4868e
Show file tree
Hide file tree
Showing 55 changed files with 283 additions and 237 deletions.
2 changes: 0 additions & 2 deletions Examples/SampleApp/SampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
00481BE81AC0C86700671115 /* libRCTWebSocketDebugger.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00481BE61AC0C7FA00671115 /* libRCTWebSocketDebugger.a */; };
00481BEA1AC0C89D00671115 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 00481BE91AC0C89D00671115 /* libicucore.dylib */; };
008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 008F07F21AC5B25A0029DE68 /* main.jsbundle */; };
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; };
00C302E61ABCBA2D00DB3ED1 /* libRCTAdSupport.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302B41ABCB8E700DB3ED1 /* libRCTAdSupport.a */; };
Expand Down Expand Up @@ -116,7 +115,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
00481BEA1AC0C89D00671115 /* libicucore.dylib in Frameworks */,
146834051AC3E58100842450 /* libReact.a in Frameworks */,
00481BE81AC0C86700671115 /* libRCTWebSocketDebugger.a in Frameworks */,
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */,
Expand Down
4 changes: 0 additions & 4 deletions Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
004D28A31AAF61C70097A701 /* UIExplorerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 004D28A21AAF61C70097A701 /* UIExplorerTests.m */; };
00D2771A1AB8C3E100DC1E48 /* libRCTWebSocketDebugger.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D277131AB8C2C700DC1E48 /* libRCTWebSocketDebugger.a */; };
00D2771C1AB8C55500DC1E48 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D2771B1AB8C55500DC1E48 /* libicucore.dylib */; };
13417FE91AA91432003F314A /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13417FE81AA91428003F314A /* libRCTImage.a */; };
134180011AA9153C003F314A /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13417FEF1AA914B8003F314A /* libRCTText.a */; };
1341802C1AA9178B003F314A /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1341802B1AA91779003F314A /* libRCTNetwork.a */; };
Expand Down Expand Up @@ -118,7 +117,6 @@
004D28A11AAF61C70097A701 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
004D28A21AAF61C70097A701 /* UIExplorerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIExplorerTests.m; sourceTree = "<group>"; };
00D2770E1AB8C2C700DC1E48 /* RCTWebSocketDebugger.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocketDebugger.xcodeproj; path = ../../Libraries/RCTWebSocketDebugger/RCTWebSocketDebugger.xcodeproj; sourceTree = "<group>"; };
00D2771B1AB8C55500DC1E48 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; };
13417FE31AA91428003F314A /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = ../../Libraries/Image/RCTImage.xcodeproj; sourceTree = "<group>"; };
13417FEA1AA914B8003F314A /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = ../../Libraries/Text/RCTText.xcodeproj; sourceTree = "<group>"; };
134180261AA91779003F314A /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = ../../Libraries/Network/RCTNetwork.xcodeproj; sourceTree = "<group>"; };
Expand Down Expand Up @@ -150,7 +148,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
00D2771C1AB8C55500DC1E48 /* libicucore.dylib in Frameworks */,
14AADF051AC3DBB1002390C9 /* libReact.a in Frameworks */,
00D2771A1AB8C3E100DC1E48 /* libRCTWebSocketDebugger.a in Frameworks */,
58005BF21ABA80A60062E044 /* libRCTTest.a in Frameworks */,
Expand Down Expand Up @@ -207,7 +204,6 @@
13417FEA1AA914B8003F314A /* RCTText.xcodeproj */,
00D2770E1AB8C2C700DC1E48 /* RCTWebSocketDebugger.xcodeproj */,
D85B82911AB6D5CE003F4FE2 /* RCTVibration.xcodeproj */,
00D2771B1AB8C55500DC1E48 /* libicucore.dylib */,
);
name = Libraries;
sourceTree = "<group>";
Expand Down
5 changes: 4 additions & 1 deletion Libraries/ActionSheetIOS/RCTActionSheetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ @interface RCTActionSheetManager() <UIActionSheetDelegate>

@end

@implementation RCTActionSheetManager {
@implementation RCTActionSheetManager
{
NSMutableDictionary *_callbacks;
}

RCT_EXPORT_MODULE()

- (instancetype)init
{
if ((self = [super init])) {
Expand Down
2 changes: 2 additions & 0 deletions Libraries/AdSupport/RCTAdSupport.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

@implementation RCTAdSupport

RCT_EXPORT_MODULE()

- (void)getAdvertisingId:(RCTResponseSenderBlock)callback withErrorCallback:(RCTResponseSenderBlock)errorCallback
{
RCT_EXPORT();
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Animation/RCTAnimationExperimentalManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ @implementation RCTAnimationExperimentalManager
RCTSparseArray *_animationRegistry; // Main thread only; animation tag -> view tag
}

RCT_EXPORT_MODULE()

@synthesize bridge = _bridge;

- (instancetype)init
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Geolocation/RCTLocationObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ @implementation RCTLocationObserver
RCTLocationOptions _observerOptions;
}

RCT_EXPORT_MODULE()

@synthesize bridge = _bridge;

#pragma mark - Lifecycle
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Image/RCTCameraRollManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

@implementation RCTCameraRollManager

RCT_EXPORT_MODULE()

- (void)saveImageWithTag:(NSString *)imageTag successCallback:(RCTResponseSenderBlock)successCallback errorCallback:(RCTResponseSenderBlock)errorCallback
{
RCT_EXPORT();
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Image/RCTNetworkImageViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

@implementation RCTNetworkImageViewManager

RCT_EXPORT_MODULE()

- (UIView *)view
{
RCTNetworkImageView *view = [[RCTNetworkImageView alloc] initWithFrame:CGRectZero imageDownloader:[RCTImageDownloader sharedInstance]];
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Image/RCTStaticImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

@implementation RCTStaticImageManager

RCT_EXPORT_MODULE()

- (UIView *)view
{
return [[RCTStaticImage alloc] init];
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LinkingIOS/RCTLinkingManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

@implementation RCTLinkingManager

RCT_EXPORT_MODULE()

@synthesize bridge = _bridge;

- (instancetype)init
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Network/RCTDataManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

@implementation RCTDataManager

RCT_EXPORT_MODULE()

/**
* Executes a network request.
* The responseSender block won't be called on same thread as called.
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Network/RCTReachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ @implementation RCTReachability
NSString *_status;
}

RCT_EXPORT_MODULE()

@synthesize bridge = _bridge;

static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void *info)
Expand Down
2 changes: 2 additions & 0 deletions Libraries/PushNotificationIOS/RCTPushNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ @implementation RCTPushNotificationManager
NSDictionary *_initialNotification;
}

RCT_EXPORT_MODULE()

@synthesize bridge = _bridge;

- (instancetype)init
Expand Down
5 changes: 4 additions & 1 deletion Libraries/RCTTest/RCTTestModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
#import "RCTAssert.h"
#import "RCTLog.h"

@implementation RCTTestModule {
@implementation RCTTestModule
{
__weak FBSnapshotTestController *_snapshotController;
__weak UIView *_view;
NSMutableDictionary *_snapshotCounter;
}

RCT_EXPORT_MODULE()

- (instancetype)initWithSnapshotController:(FBSnapshotTestController *)controller view:(UIView *)view
{
if ((self = [super init])) {
Expand Down
9 changes: 6 additions & 3 deletions Libraries/RCTWebSocketDebugger/SRWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@

#import <Availability.h>

#if TARGET_OS_IPHONE
#define HAS_ICU
#endif
//NOTE: libicucore ins't actually needed for the socket to function
//and by commenting this out, we avoid the need to import it into every app.

//#if TARGET_OS_IPHONE
//#define HAS_ICU
//#endif

#ifdef HAS_ICU
#import <unicode/utf8.h>
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Text/RCTRawTextManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

@implementation RCTRawTextManager

RCT_EXPORT_MODULE()

- (UIView *)view
{
return nil;
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Text/RCTTextManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

@implementation RCTTextManager

RCT_EXPORT_MODULE()

- (UIView *)view
{
return [[RCTText alloc] init];
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Vibration/RCTVibration.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

@implementation RCTVibration

RCT_EXPORT_MODULE()

- (void)vibrate
{
RCT_EXPORT();
Expand Down
34 changes: 25 additions & 9 deletions React/Base/RCTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
*/
typedef NSArray *(^RCTBridgeModuleProviderBlock)(void);

extern NSString *const RCTReloadBridge;

/**
* This function returns the module name for a given class.
*/
Expand All @@ -38,8 +36,6 @@ extern NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
*/
@interface RCTBridge : NSObject <RCTInvalidating>

@property (nonatomic, assign, readonly, getter=isLoaded) BOOL loaded;

/**
* The designated initializer. This creates a new bridge on top of the specified
* executor. The bridge should then be used for all subsequent communication
Expand All @@ -55,16 +51,31 @@ extern NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
/**
* This method is used to call functions in the JavaScript application context.
* It is primarily intended for use by modules that require two-way communication
* with the JavaScript code.
* with the JavaScript code. Method should be regsitered using the
* RCT_IMPORT_METHOD macro below. Attempting to call a method that has not been
* registered will result in an error.
*/
- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args;

/**
* This macro is used to register a JS method to be called via the enqueueJSCall
* bridge method. You should place this macro inside any file that uses the
* imported method. If a method has already been registered by another class, it
* is not necessary to register it again, but it is good practice. Registering
* the same method more than once will not result in an error.
*/
#define RCT_IMPORT_METHOD(module, method) \
__attribute__((used, section("__DATA,RCTImport"))) \
static const char *__rct_import_##module##_##method##__ = #module"."#method;

/**
* This method is used to execute a new application script. It is called
* internally whenever a JS application bundle is loaded/reloaded, but should
* probably not be used at any other time.
*/
- (void)enqueueApplicationScript:(NSString *)script url:(NSURL *)url onComplete:(RCTJavaScriptCompleteBlock)onComplete;
- (void)enqueueApplicationScript:(NSString *)script
url:(NSURL *)url
onComplete:(RCTJavaScriptCompleteBlock)onComplete;

@property (nonatomic, strong) Class executorClass;

Expand All @@ -86,14 +97,19 @@ extern NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
*/
@property (nonatomic, readonly) dispatch_queue_t shadowQueue;

/**
* The launch options that were used to initialize the bridge.
*/
@property (nonatomic, copy, readonly) NSDictionary *launchOptions;


/**
* Method to check that a valid executor exists with which to log
* Use this to check if the bridge is currently loading.
*/
+ (BOOL)hasValidJSExecutor;
@property (nonatomic, readonly, getter=isLoaded) BOOL loaded;

/**
* Reload the bundle and reset executor and modules.
*/
- (void)reload;

@end
Loading

0 comments on commit bf4868e

Please sign in to comment.