diff --git a/packages/react-native/React/Base/RCTBridge.h b/packages/react-native/React/Base/RCTBridge.h index 846e17fdb1104e..ace401ec56d3fd 100644 --- a/packages/react-native/React/Base/RCTBridge.h +++ b/packages/react-native/React/Base/RCTBridge.h @@ -61,6 +61,9 @@ void RCTEnableTurboModuleSyncVoidMethods(BOOL enabled); BOOL RCTTurboModuleSharedQueueEnabled(void); void RCTEnableTurboModuleSharedQueue(BOOL enabled); +BOOL RCTUIManagerDispatchAccessibilityManagerInitOntoMain(void); +void RCTUIManagerSetDispatchAccessibilityManagerInitOntoMain(BOOL enabled); + typedef enum { kRCTBridgeProxyLoggingLevelNone, kRCTBridgeProxyLoggingLevelWarning, diff --git a/packages/react-native/React/Base/RCTBridge.mm b/packages/react-native/React/Base/RCTBridge.mm index a18b43861cbabd..263231720cffb6 100644 --- a/packages/react-native/React/Base/RCTBridge.mm +++ b/packages/react-native/React/Base/RCTBridge.mm @@ -162,6 +162,17 @@ void RCTEnableTurboModuleSharedQueue(BOOL enabled) gTurboModuleEnableSharedQueue = enabled; } +BOOL kDispatchAccessibilityManagerInitOntoMain = NO; +BOOL RCTUIManagerDispatchAccessibilityManagerInitOntoMain(void) +{ + return kDispatchAccessibilityManagerInitOntoMain; +} + +void RCTUIManagerSetDispatchAccessibilityManagerInitOntoMain(BOOL enabled) +{ + kDispatchAccessibilityManagerInitOntoMain = enabled; +} + @interface RCTBridge () @end diff --git a/packages/react-native/React/Modules/RCTUIManager.m b/packages/react-native/React/Modules/RCTUIManager.m index 4167fb122841f5..a646f95079db04 100644 --- a/packages/react-native/React/Modules/RCTUIManager.m +++ b/packages/react-native/React/Modules/RCTUIManager.m @@ -181,7 +181,10 @@ - (void)setBridge:(RCTBridge *)bridge } // This dispatch_async avoids a deadlock while configuring native modules - dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ + dispatch_queue_t accessibilityManagerInitQueue = RCTUIManagerDispatchAccessibilityManagerInitOntoMain() + ? dispatch_get_main_queue() + : dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0); + dispatch_async(accessibilityManagerInitQueue, ^{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNewContentSizeMultiplier) name:@"RCTAccessibilityManagerDidUpdateMultiplierNotification"