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
|
|
|
|
2015-04-02 14:33:21 +00:00
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2015-07-28 22:48:46 +00:00
|
|
|
#import "RCTBridgeDelegate.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTBridgeModule.h"
|
2015-04-21 12:26:51 +00:00
|
|
|
#import "RCTDefines.h"
|
2015-04-15 14:07:19 +00:00
|
|
|
#import "RCTFrameUpdate.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTInvalidating.h"
|
|
|
|
|
2016-09-28 21:00:16 +00:00
|
|
|
@class JSValue;
|
2015-02-24 17:06:57 +00:00
|
|
|
@class RCTBridge;
|
2015-02-20 04:10:52 +00:00
|
|
|
@class RCTEventDispatcher;
|
2016-07-07 14:20:03 +00:00
|
|
|
@class RCTPerformanceLogger;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-11 22:08:00 +00:00
|
|
|
/**
|
|
|
|
* This notification triggers a reload of all bridges currently running.
|
2016-09-08 00:24:23 +00:00
|
|
|
* Deprecated, use RCTBridge::requestReload instead.
|
2015-04-11 22:08:00 +00:00
|
|
|
*/
|
2016-09-08 00:24:23 +00:00
|
|
|
RCT_EXTERN NSString *const RCTReloadNotification DEPRECATED_ATTRIBUTE;
|
2015-04-11 22:08:00 +00:00
|
|
|
|
2015-07-28 18:07:45 +00:00
|
|
|
/**
|
2015-12-15 13:42:45 +00:00
|
|
|
* This notification fires when the bridge starts loading the JS bundle.
|
2015-07-28 18:07:45 +00:00
|
|
|
*/
|
|
|
|
RCT_EXTERN NSString *const RCTJavaScriptWillStartLoadingNotification;
|
|
|
|
|
2015-04-11 22:08:00 +00:00
|
|
|
/**
|
2015-12-15 13:42:45 +00:00
|
|
|
* This notification fires when the bridge has finished loading the JS bundle.
|
2015-04-11 22:08:00 +00:00
|
|
|
*/
|
2015-06-10 10:43:55 +00:00
|
|
|
RCT_EXTERN NSString *const RCTJavaScriptDidLoadNotification;
|
2015-04-11 22:08:00 +00:00
|
|
|
|
2015-05-07 11:29:31 +00:00
|
|
|
/**
|
2015-12-15 13:42:45 +00:00
|
|
|
* This notification fires when the bridge failed to load the JS bundle. The
|
|
|
|
* `error` key can be used to determine the error that occured.
|
2015-05-07 11:29:31 +00:00
|
|
|
*/
|
2015-06-10 10:43:55 +00:00
|
|
|
RCT_EXTERN NSString *const RCTJavaScriptDidFailToLoadNotification;
|
2015-05-07 11:29:31 +00:00
|
|
|
|
2015-07-01 00:08:28 +00:00
|
|
|
/**
|
2015-12-15 13:42:45 +00:00
|
|
|
* This notification fires each time a native module is instantiated. The
|
|
|
|
* `module` key will contain a reference to the newly-created module instance.
|
|
|
|
* Note that this notification may be fired before the module is available via
|
|
|
|
* the `[bridge moduleForClass:]` method.
|
2015-07-01 00:08:28 +00:00
|
|
|
*/
|
2015-12-15 13:42:45 +00:00
|
|
|
RCT_EXTERN NSString *const RCTDidInitializeModuleNotification;
|
2015-07-01 00:08:28 +00:00
|
|
|
|
2015-02-24 17:06:57 +00:00
|
|
|
/**
|
|
|
|
* This block can be used to instantiate modules that require additional
|
|
|
|
* init parameters, or additional configuration prior to being used.
|
2015-03-01 23:33:55 +00:00
|
|
|
* 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.
|
2015-02-24 17:06:57 +00:00
|
|
|
*/
|
2015-11-03 22:45:46 +00:00
|
|
|
typedef NSArray<id<RCTBridgeModule>> *(^RCTBridgeModuleProviderBlock)(void);
|
2015-02-24 17:06:57 +00:00
|
|
|
|
2015-04-07 14:36:26 +00:00
|
|
|
/**
|
|
|
|
* This function returns the module name for a given class.
|
|
|
|
*/
|
2015-04-21 12:26:51 +00:00
|
|
|
RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
|
2015-04-07 14:36:26 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
|
|
|
* Async batched bridge used to communicate with the JavaScript application.
|
|
|
|
*/
|
|
|
|
@interface RCTBridge : NSObject <RCTInvalidating>
|
|
|
|
|
2015-07-28 22:48:46 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2016-07-12 12:51:56 +00:00
|
|
|
launchOptions:(NSDictionary *)launchOptions;
|
2015-07-28 22:48:46 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-07-28 22:48:46 +00:00
|
|
|
* DEPRECATED: Use initWithDelegate:launchOptions: instead
|
|
|
|
*
|
2015-02-20 04:10:52 +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-24 17:06:57 +00:00
|
|
|
* with the JavaScript code running in the executor. Modules will be automatically
|
2015-03-01 23:33:55 +00:00
|
|
|
* 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-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-04-11 22:08:00 +00:00
|
|
|
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
|
|
|
|
moduleProvider:(RCTBridgeModuleProviderBlock)block
|
2016-07-12 12:51:56 +00:00
|
|
|
launchOptions:(NSDictionary *)launchOptions;
|
2015-02-20 04:10:52 +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
|
2015-06-15 20:01:39 +00:00
|
|
|
* with the JavaScript code. Safe to call from any thread.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args;
|
2016-07-18 14:12:22 +00:00
|
|
|
- (void)enqueueJSCall:(NSString *)module method:(NSString *)method args:(NSArray *)args completion:(dispatch_block_t)completion;
|
|
|
|
|
2016-09-28 21:00:16 +00:00
|
|
|
/**
|
|
|
|
* This method is used to call functions in the JavaScript application context
|
|
|
|
* synchronously. This is intended for use by applications which do their own
|
|
|
|
* thread management and are careful to manage multi-threaded access to the JSVM.
|
|
|
|
* See also -[RCTBridgeDelgate shouldBridgeLoadJavaScriptSynchronously], which
|
|
|
|
* may be needed to ensure that any requires JS code is loaded before this method
|
|
|
|
* is called. If the underlying executor is not JSC, this will return nil. Safe
|
|
|
|
* to call from any thread.
|
|
|
|
*
|
|
|
|
* @experimental
|
|
|
|
*/
|
|
|
|
- (JSValue *)callFunctionOnModule:(NSString *)module
|
|
|
|
method:(NSString *)method
|
|
|
|
arguments:(NSArray *)arguments
|
|
|
|
error:(NSError **)error;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-08 12:42:43 +00:00
|
|
|
/**
|
2015-11-25 11:09:00 +00:00
|
|
|
* Retrieve a bridge module instance by name or class. Note that modules are
|
|
|
|
* lazily instantiated, so calling these methods for the first time with a given
|
|
|
|
* module name/class may cause the class to be sychronously instantiated,
|
2016-03-03 10:20:20 +00:00
|
|
|
* potentially blocking both the calling thread and main thread for a short time.
|
2015-11-25 11:09:00 +00:00
|
|
|
*/
|
|
|
|
- (id)moduleForName:(NSString *)moduleName;
|
|
|
|
- (id)moduleForClass:(Class)moduleClass;
|
|
|
|
|
2016-03-03 10:20:20 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for retrieving all modules conforming to a given protocol.
|
|
|
|
* Modules will be sychronously instantiated if they haven't already been,
|
|
|
|
* potentially blocking both the calling thread and main thread for a short time.
|
|
|
|
*/
|
|
|
|
- (NSArray *)modulesConformingToProtocol:(Protocol *)protocol;
|
|
|
|
|
2016-03-07 17:30:20 +00:00
|
|
|
/**
|
|
|
|
* Test if a module has been initialized. Use this prior to calling
|
2016-03-24 00:22:16 +00:00
|
|
|
* `moduleForClass:` or `moduleForName:` if you do not want to cause the module
|
2016-03-07 17:30:20 +00:00
|
|
|
* to be instantiated if it hasn't been already.
|
|
|
|
*/
|
|
|
|
- (BOOL)moduleIsInitialized:(Class)moduleClass;
|
|
|
|
|
2016-08-05 18:19:11 +00:00
|
|
|
/**
|
|
|
|
* Call when your delegate's `whitelistedModulesForBridge:` value has changed.
|
|
|
|
* In response to this, the bridge will immediately instantiate any (whitelisted)
|
|
|
|
* native modules that require main thread initialization. Modules that do not require
|
|
|
|
* main thread initialization will still be created lazily.
|
|
|
|
*
|
|
|
|
* This method must be called on the main thread, as any pending native modules
|
|
|
|
* will be initialized immediately.
|
|
|
|
*/
|
|
|
|
- (void)whitelistedModulesDidChange;
|
|
|
|
|
2015-11-25 11:09:00 +00:00
|
|
|
/**
|
|
|
|
* All registered bridge module classes.
|
2015-04-08 12:42:43 +00:00
|
|
|
*/
|
2015-11-25 11:09:00 +00:00
|
|
|
@property (nonatomic, copy, readonly) NSArray<Class> *moduleClasses;
|
2015-04-08 12:42:43 +00:00
|
|
|
|
2015-04-20 21:04:53 +00:00
|
|
|
/**
|
|
|
|
* URL of the script that was loaded into the bridge.
|
|
|
|
*/
|
2016-01-04 18:39:07 +00:00
|
|
|
@property (nonatomic, strong, readonly) NSURL *bundleURL;
|
2015-04-20 21:04:53 +00:00
|
|
|
|
2015-07-28 22:48:46 +00:00
|
|
|
/**
|
2016-01-04 18:39:07 +00:00
|
|
|
* The class of the executor currently being used. Changes to this value will
|
|
|
|
* take effect after the bridge is reloaded.
|
2015-07-28 22:48:46 +00:00
|
|
|
*/
|
2015-04-02 14:33:21 +00:00
|
|
|
@property (nonatomic, strong) Class executorClass;
|
|
|
|
|
2015-07-28 22:48:46 +00:00
|
|
|
/**
|
|
|
|
* The delegate provided during the bridge initialization
|
|
|
|
*/
|
|
|
|
@property (nonatomic, weak, readonly) id<RCTBridgeDelegate> delegate;
|
|
|
|
|
2015-04-08 12:42:43 +00:00
|
|
|
/**
|
|
|
|
* The launch options that were used to initialize the bridge.
|
|
|
|
*/
|
2015-03-26 01:59:42 +00:00
|
|
|
@property (nonatomic, copy, readonly) NSDictionary *launchOptions;
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-04-08 12:42:43 +00:00
|
|
|
* Use this to check if the bridge is currently loading.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-04-11 22:08:00 +00:00
|
|
|
@property (nonatomic, readonly, getter=isLoading) BOOL loading;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-08-14 08:59:42 +00:00
|
|
|
/**
|
|
|
|
* Use this to check if the bridge has been invalidated.
|
|
|
|
*/
|
|
|
|
@property (nonatomic, readonly, getter=isValid) BOOL valid;
|
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
/**
|
|
|
|
* Link to the Performance Logger that logs React Native perf events.
|
|
|
|
*/
|
|
|
|
@property (nonatomic, readonly, strong) RCTPerformanceLogger *performanceLogger;
|
|
|
|
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
/**
|
2015-11-25 11:09:00 +00:00
|
|
|
* Reload the bundle and reset executor & modules. Safe to call from any thread.
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
*/
|
2015-11-25 11:09:00 +00:00
|
|
|
- (void)reload;
|
|
|
|
|
2016-09-08 00:24:23 +00:00
|
|
|
/**
|
|
|
|
* Inform the bridge, and anything subscribing to it, that it should reload.
|
|
|
|
*/
|
|
|
|
- (void)requestReload;
|
|
|
|
|
2015-12-11 14:54:56 +00:00
|
|
|
/**
|
|
|
|
* Says whether bridge has started recieving calls from javascript.
|
|
|
|
*/
|
|
|
|
- (BOOL)isBatchActive;
|
|
|
|
|
2015-11-25 11:09:00 +00:00
|
|
|
@end
|