@@ -228,6 +228,7 @@ @implementation RCTModuleMethod
228228 NSMethodSignature *_methodSignature;
229229 NSArray *_argumentBlocks;
230230 NSString *_methodName;
231+ dispatch_block_t _methodQueue;
231232}
232233
233234static Class _globalExecutorClass;
@@ -762,6 +763,7 @@ @implementation RCTBridge
762763{
763764 RCTSparseArray *_modulesByID;
764765 RCTSparseArray *_queuesByID;
766+ dispatch_queue_t _methodQueue;
765767 NSDictionary *_modulesByName;
766768 id <RCTJavaScriptExecutor> _javaScriptExecutor;
767769 Class _executorClass;
@@ -787,7 +789,6 @@ - (instancetype)initWithBundleURL:(NSURL *)bundleURL
787789 [self setUp ];
788790 [self bindKeys ];
789791 }
790-
791792 return self;
792793}
793794
@@ -797,6 +798,7 @@ - (void)setUp
797798 _javaScriptExecutor = RCTCreateExecutor (executorClass);
798799 _latestJSExecutor = _javaScriptExecutor;
799800 _eventDispatcher = [[RCTEventDispatcher alloc ] initWithBridge: self ];
801+ _methodQueue = dispatch_queue_create (" com.facebook.React.BridgeMethodQueue" , DISPATCH_QUEUE_SERIAL);
800802 _displayLink = [[RCTDisplayLink alloc ] initWithBridge: self ];
801803 _frameUpdateObservers = [[NSMutableSet alloc ] init ];
802804 _scheduledCalls = [[NSMutableArray alloc ] init ];
@@ -850,11 +852,14 @@ - (void)setUp
850852 }
851853 }
852854
853- // Get method queue
855+ // Get method queues
854856 _queuesByID = [[RCTSparseArray alloc ] init ];
855857 [_modulesByID enumerateObjectsUsingBlock: ^(id <RCTBridgeModule> module, NSNumber *moduleID, BOOL *stop) {
856858 if ([module respondsToSelector: @selector (methodQueue )]) {
857- _queuesByID[moduleID] = [module methodQueue ] ?: dispatch_get_main_queue ();
859+ dispatch_queue_t queue = [module methodQueue ];
860+ if (queue) {
861+ _queuesByID[moduleID] = queue;
862+ }
858863 }
859864 }];
860865
@@ -895,11 +900,6 @@ - (void)setUp
895900 } else {
896901 [[NSNotificationCenter defaultCenter ] postNotificationName: RCTJavaScriptDidLoadNotification
897902 object: self ];
898-
899- [[NSNotificationCenter defaultCenter ] addObserver: self
900- selector: @selector (reload )
901- name: RCTReloadNotification
902- object: nil ];
903903 }
904904 [[NSNotificationCenter defaultCenter ] addObserver: self
905905 selector: @selector (reload )
@@ -1205,7 +1205,7 @@ - (void)_handleBuffer:(id)buffer context:(NSNumber *)context
12051205 [_modulesByID enumerateObjectsUsingBlock: ^(id <RCTBridgeModule> module, NSNumber *moduleID, BOOL *stop) {
12061206 if ([module respondsToSelector: @selector (batchDidComplete )]) {
12071207 dispatch_queue_t queue = _queuesByID[moduleID];
1208- dispatch_async (queue ?: dispatch_get_main_queue () , ^{
1208+ dispatch_async (queue ?: _methodQueue , ^{
12091209 [module batchDidComplete ];
12101210 });
12111211 }
@@ -1240,7 +1240,7 @@ - (BOOL)_handleRequestNumber:(NSUInteger)i
12401240
12411241 __weak RCTBridge *weakSelf = self;
12421242 dispatch_queue_t queue = _queuesByID[moduleID];
1243- dispatch_async (queue ?: dispatch_get_main_queue () , ^{
1243+ dispatch_async (queue ?: _methodQueue , ^{
12441244 RCTProfileBeginEvent ();
12451245 __strong RCTBridge *strongSelf = weakSelf;
12461246
@@ -1320,13 +1320,15 @@ - (void)removeFrameUpdateObserver:(id<RCTFrameUpdateObserver>)observer
13201320
13211321- (void )reload
13221322{
1323- if (!_loading) {
1324- // If the bridge has not loaded yet, the context will be already invalid at
1325- // the time the javascript gets executed.
1326- // It will crash the javascript, and even the next `load` won't render.
1327- [self invalidate ];
1328- [self setUp ];
1329- }
1323+ dispatch_async (dispatch_get_main_queue (), ^{
1324+ if (!_loading) {
1325+ // If the bridge has not loaded yet, the context will be already invalid at
1326+ // the time the javascript gets executed.
1327+ // It will crash the javascript, and even the next `load` won't render.
1328+ [self invalidate ];
1329+ [self setUp ];
1330+ }
1331+ });
13301332}
13311333
13321334+ (void )logMessage:(NSString *)message level:(NSString *)level
0 commit comments