mirror of
https://github.com/status-im/react-native.git
synced 2025-01-09 09:12:02 +00:00
dc13115445
Summary:Initializing native modules can block the main thread for tens of milliseconds when it starts up, making it difficult to instantiate the bridge on demand without causing a performance blip. This diff splits up the initialization of modules so that - although they still happen on the main thread - they don't block the thread continuously. Reviewed By: javache Differential Revision: D2965438 fb-gh-sync-id: 38c9c9d281e4672b5874d68b57d4c60d1d268344 shipit-source-id: 38c9c9d281e4672b5874d68b57d4c60d1d268344
84 lines
2.7 KiB
Objective-C
84 lines
2.7 KiB
Objective-C
/**
|
|
* 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.
|
|
*/
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import "RCTInvalidating.h"
|
|
|
|
@protocol RCTBridgeMethod;
|
|
@protocol RCTBridgeModule;
|
|
@class RCTBridge;
|
|
|
|
@interface RCTModuleData : NSObject <RCTInvalidating>
|
|
|
|
- (instancetype)initWithModuleClass:(Class)moduleClass
|
|
bridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
|
|
|
|
- (instancetype)initWithModuleInstance:(id<RCTBridgeModule>)instance
|
|
bridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
|
|
|
|
/**
|
|
* Calls `constantsToExport` on the module and stores the result. Note that
|
|
* this will init the module if it has not already been created. This method
|
|
* can be called on any thread, but may block the main thread briefly if the
|
|
* module implements `constantsToExport`.
|
|
*/
|
|
- (void)gatherConstants;
|
|
|
|
@property (nonatomic, strong, readonly) Class moduleClass;
|
|
@property (nonatomic, copy, readonly) NSString *name;
|
|
|
|
/**
|
|
* Returns the module methods. Note that this will gather the methods the first
|
|
* time it is called and then memoize the results.
|
|
*/
|
|
@property (nonatomic, copy, readonly) NSArray<id<RCTBridgeMethod>> *methods;
|
|
|
|
/**
|
|
* Returns YES if module instance has already been initialized; NO otherwise.
|
|
*/
|
|
@property (nonatomic, assign, readonly) BOOL hasInstance;
|
|
|
|
/**
|
|
* Returns YES if module instance must be created on the main thread.
|
|
*/
|
|
@property (nonatomic, assign, readonly) BOOL requiresMainThreadSetup;
|
|
|
|
/**
|
|
* Returns the current module instance. Note that this will init the instance
|
|
* if it has not already been created. To check if the module instance exists
|
|
* without causing it to be created, use `hasInstance` instead.
|
|
*/
|
|
@property (nonatomic, strong, readonly) id<RCTBridgeModule> instance;
|
|
|
|
/**
|
|
* Returns the module method dispatch queue. Note that this will init both the
|
|
* queue and the module itself if they have not already been created.
|
|
*/
|
|
@property (nonatomic, strong, readonly) dispatch_queue_t methodQueue;
|
|
|
|
/**
|
|
* Returns the module config. Calls `gatherConstants` internally, so the same
|
|
* usage caveats apply.
|
|
*/
|
|
@property (nonatomic, copy, readonly) NSArray *config;
|
|
|
|
/**
|
|
* Whether the receiver has a valid `instance` which implements -batchDidComplete.
|
|
*/
|
|
@property (nonatomic, assign, readonly) BOOL implementsBatchDidComplete;
|
|
|
|
/**
|
|
* Whether the receiver has a valid `instance` which implements
|
|
* -partialBatchDidFlush.
|
|
*/
|
|
@property (nonatomic, assign, readonly) BOOL implementsPartialBatchDidFlush;
|
|
|
|
@end
|