react-native/React/Base/RCTBridge.h

164 lines
5.2 KiB
C
Raw Normal View History

/**
* 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-04-02 14:33:21 +00:00
#import <UIKit/UIKit.h>
#import "RCTBridgeDelegate.h"
#import "RCTBridgeModule.h"
2015-04-21 12:26:51 +00:00
#import "RCTDefines.h"
#import "RCTFrameUpdate.h"
#import "RCTInvalidating.h"
#import "RCTJavaScriptExecutor.h"
@class RCTBridge;
@class RCTEventDispatcher;
2015-04-11 22:08:00 +00:00
/**
* This notification triggers a reload of all bridges currently running.
*/
RCT_EXTERN NSString *const RCTReloadNotification;
2015-04-11 22:08:00 +00:00
/**
* This notification fires when the bridge starts loading.
*/
RCT_EXTERN NSString *const RCTJavaScriptWillStartLoadingNotification;
2015-04-11 22:08:00 +00:00
/**
* This notification fires when the bridge has finished loading.
*/
RCT_EXTERN NSString *const RCTJavaScriptDidLoadNotification;
2015-04-11 22:08:00 +00:00
/**
* This notification fires when the bridge failed to load.
*/
RCT_EXTERN NSString *const RCTJavaScriptDidFailToLoadNotification;
/**
* This notification fires when the bridge created all registered native modules
*/
RCT_EXTERN NSString *const RCTDidCreateNativeModules;
/**
* This block can be used to instantiate modules that require additional
* init parameters, or additional configuration prior to being used.
* The bridge will call this block to instatiate the modules, and will
* be responsible for invalidating/releasing them when the bridge is destroyed.
* For this reason, the block should always return new module instances, and
* module instances should not be shared between bridges.
*/
typedef NSArray *(^RCTBridgeModuleProviderBlock)(void);
/**
* This function returns the module name for a given class.
*/
2015-04-21 12:26:51 +00:00
RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
/**
* Async batched bridge used to communicate with the JavaScript application.
*/
@interface RCTBridge : NSObject <RCTInvalidating>
/**
* Creates a new bridge with a custom RCTBridgeDelegate.
*
* All the interaction with the JavaScript context should be done using the bridge
* instance of the RCTBridgeModules. Modules will be automatically instantiated
* using the default contructor, but you can optionally pass in an array of
* pre-initialized module instances if they require additional init parameters
* or configuration.
*/
- (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)delegate
launchOptions:(NSDictionary *)launchOptions NS_DESIGNATED_INITIALIZER;
/**
* DEPRECATED: Use initWithDelegate:launchOptions: instead
*
* The designated initializer. This creates a new bridge on top of the specified
* executor. The bridge should then be used for all subsequent communication
* with the JavaScript code running in the executor. Modules will be automatically
* instantiated using the default contructor, but you can optionally pass in an
* array of pre-initialized module instances if they require additional init
* parameters or configuration.
*/
2015-04-11 22:08:00 +00:00
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
moduleProvider:(RCTBridgeModuleProviderBlock)block
launchOptions:(NSDictionary *)launchOptions NS_DESIGNATED_INITIALIZER;
/**
* 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. Safe to call from any thread.
*/
- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args;
/**
* DEPRECATED: Do not use.
*/
#define RCT_IMPORT_METHOD(module, method) \
_Pragma("message(\"This macro is no longer required\")")
2015-04-20 21:04:53 +00:00
/**
* URL of the script that was loaded into the bridge.
*/
@property (nonatomic, strong) NSURL *bundleURL;
2015-04-20 21:04:53 +00:00
/**
* The class of the executor currently being used *or* to be used after the next
* reload.
*/
2015-04-02 14:33:21 +00:00
@property (nonatomic, strong) Class executorClass;
/**
* The delegate provided during the bridge initialization
*/
@property (nonatomic, weak, readonly) id<RCTBridgeDelegate> delegate;
/**
* 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.
*
* NOTE: RCTEventDispatcher is now a bridge module, this is implemented as a
* category but remains declared in the bridge to avoid breaking changes
*
* To be moved.
*/
@property (nonatomic, readonly) RCTEventDispatcher *eventDispatcher;
/**
* A dictionary of all registered RCTBridgeModule instances, keyed by moduleName.
*/
@property (nonatomic, copy, readonly) NSDictionary *modules;
/**
* The launch options that were used to initialize the bridge.
*/
2015-03-26 01:59:42 +00:00
@property (nonatomic, copy, readonly) NSDictionary *launchOptions;
/**
* Use this to check if the bridge is currently loading.
*/
2015-04-11 22:08:00 +00:00
@property (nonatomic, readonly, getter=isLoading) BOOL loading;
/**
* Use this to check if the bridge has been invalidated.
*/
@property (nonatomic, readonly, getter=isValid) BOOL valid;
/**
* The block passed in the constructor with pre-initialized modules
*/
@property (nonatomic, copy, readonly) RCTBridgeModuleProviderBlock moduleProvider;
/**
* Reload the bundle and reset executor & modules. Safe to call from any thread.
*/
2015-04-02 14:33:21 +00:00
- (void)reload;
@end