2015-01-30 01:10:49 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
2015-02-06 23:43:59 +00:00
|
|
|
#import "RCTBridgeModule.h"
|
2015-01-30 01:10:49 +00:00
|
|
|
#import "RCTInvalidating.h"
|
|
|
|
#import "RCTJavaScriptExecutor.h"
|
|
|
|
|
2015-02-25 20:40:49 +00:00
|
|
|
@class RCTBridge;
|
2015-02-04 00:02:36 +00:00
|
|
|
@class RCTEventDispatcher;
|
2015-02-04 00:12:07 +00:00
|
|
|
@class RCTRootView;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Utilities for constructing common response objects. When sending a
|
|
|
|
* systemError back to JS, it's important to describe whether or not it was a
|
|
|
|
* system error, or API usage error. System errors should never happen and are
|
|
|
|
* therefore logged using `RCTLogError()`. API usage errors are expected if the
|
|
|
|
* API is misused and will therefore not be logged using `RCTLogError()`. The JS
|
|
|
|
* application code is expected to handle them. Regardless of type, each error
|
|
|
|
* should be logged at most once.
|
|
|
|
*/
|
|
|
|
static inline NSDictionary *RCTSystemErrorObject(NSString *msg)
|
|
|
|
{
|
|
|
|
return @{@"systemError": msg ?: @""};
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline NSDictionary *RCTAPIErrorObject(NSString *msg)
|
|
|
|
{
|
|
|
|
return @{@"apiError": msg ?: @""};
|
|
|
|
}
|
|
|
|
|
2015-02-25 20:40:49 +00:00
|
|
|
/**
|
|
|
|
* This block can be used to instantiate modules that require additional
|
|
|
|
* init parameters, or additional configuration prior to being used.
|
|
|
|
*/
|
|
|
|
typedef NSArray *(^RCTBridgeModuleProviderBlock)(RCTBridge *bridge);
|
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2015-02-06 23:43:59 +00:00
|
|
|
* Async batched bridge used to communicate with the JavaScript application.
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
@interface RCTBridge : NSObject <RCTInvalidating>
|
|
|
|
|
2015-02-06 23:43:59 +00:00
|
|
|
/**
|
|
|
|
* The designated initializer. This creates a new bridge on top of the specified
|
|
|
|
* executor. The bridge should then be used for all subsequent communication
|
2015-02-25 20:40:49 +00:00
|
|
|
* with the JavaScript code running in the executor. Modules will be automatically
|
|
|
|
* instantiated using the default contructor, but you can optionally pass in a
|
|
|
|
* module provider block to manually instantiate modules that require additional
|
|
|
|
* init parameters or configuration.
|
2015-02-06 23:43:59 +00:00
|
|
|
*/
|
2015-02-20 18:33:17 +00:00
|
|
|
- (instancetype)initWithJavaScriptExecutor:(id<RCTJavaScriptExecutor>)javaScriptExecutor
|
2015-02-25 20:40:49 +00:00
|
|
|
moduleProvider:(RCTBridgeModuleProviderBlock)block NS_DESIGNATED_INITIALIZER;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-02-06 23:43:59 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-02-04 00:15:20 +00:00
|
|
|
- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args;
|
2015-02-06 23:43:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-01-30 01:10:49 +00:00
|
|
|
- (void)enqueueApplicationScript:(NSString *)script url:(NSURL *)url onComplete:(RCTJavaScriptCompleteBlock)onComplete;
|
|
|
|
|
2015-02-06 23:43:59 +00:00
|
|
|
/**
|
|
|
|
* The event dispatcher is a wrapper around -enqueueJSCall:args: that provides a
|
|
|
|
* higher-level interface for sending UI events such as touches and text input.
|
|
|
|
*/
|
2015-02-04 00:02:36 +00:00
|
|
|
@property (nonatomic, readonly) RCTEventDispatcher *eventDispatcher;
|
2015-02-06 23:43:59 +00:00
|
|
|
|
2015-02-25 20:40:49 +00:00
|
|
|
/**
|
|
|
|
* A dictionary of all registered RCTBridgeModule instances, keyed by moduleName.
|
|
|
|
*/
|
|
|
|
@property (nonatomic, copy, readonly) NSDictionary *modules;
|
|
|
|
|
2015-02-06 23:43:59 +00:00
|
|
|
/**
|
|
|
|
* The shadow queue is used to execute callbacks from the JavaScript code. All
|
|
|
|
* native hooks (e.g. exported module methods) will be executed on the shadow
|
|
|
|
* queue.
|
|
|
|
*/
|
2015-02-04 00:12:07 +00:00
|
|
|
@property (nonatomic, readonly) dispatch_queue_t shadowQueue;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
// For use in implementing delegates, which may need to queue responses.
|
|
|
|
- (RCTResponseSenderBlock)createResponseSenderBlock:(NSInteger)callbackID;
|
|
|
|
|
2015-02-06 23:43:59 +00:00
|
|
|
/**
|
|
|
|
* Register a root view with the bridge. Theorectically, a single bridge can
|
|
|
|
* support multiple root views, however this feature is not currently exposed
|
|
|
|
* and may eventually be removed.
|
|
|
|
*/
|
2015-02-04 00:12:07 +00:00
|
|
|
- (void)registerRootView:(RCTRootView *)rootView;
|
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2015-02-06 23:43:59 +00:00
|
|
|
* Global logging function that will print to both xcode and JS debugger consoles.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
|
|
|
* NOTE: Use via RCTLog* macros defined in RCTLog.h
|
|
|
|
* TODO (#5906496): should log function be exposed here, or could it be a module?
|
|
|
|
*/
|
|
|
|
+ (void)log:(NSArray *)objects level:(NSString *)level;
|
|
|
|
|
2015-02-06 23:43:59 +00:00
|
|
|
/**
|
|
|
|
* Method to check that a valid executor exists with which to log
|
|
|
|
*/
|
2015-01-30 01:10:49 +00:00
|
|
|
+ (BOOL)hasValidJSExecutor;
|
|
|
|
|
|
|
|
@end
|