Skip to content

Commit f56bf1f

Browse files
authored
[RN][iOS] Fix warning when loading RCTUIManager and A11yManager (#42734)
1 parent 53061d7 commit f56bf1f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/react-native/React/Modules/RCTUIManager.m

+10-5
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,20 @@ - (void)setBridge:(RCTBridge *)bridge
179179
_componentDataByName[componentData.name] = componentData;
180180
}
181181
}
182-
182+
// Preload the a11yManager as the RCTUIManager needs it to listen for notification
183+
// By eagerly preloading it in the setBridge method, we make sure that the manager is
184+
// properly initialized in the Main Thread and that we do not incur in any race condition
185+
// or concurrency problem.
186+
id<RCTBridgeModule> a11yManager = [self->_bridge moduleForName:@"AccessibilityManager"
187+
lazilyLoadIfNecessary:YES];
188+
__weak NSObject * a11yManagerWeakObject = a11yManager;
183189
// This dispatch_async avoids a deadlock while configuring native modules
184-
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
185-
id a11yManager = [self->_bridge moduleForName:@"AccessibilityManager"
186-
lazilyLoadIfNecessary:YES];
190+
dispatch_async(dispatch_get_main_queue(), ^{
191+
__strong NSObject * a11yManagerStrongObject = a11yManagerWeakObject;
187192
[[NSNotificationCenter defaultCenter] addObserver:self
188193
selector:@selector(didReceiveNewContentSizeMultiplier)
189194
name:@"RCTAccessibilityManagerDidUpdateMultiplierNotification"
190-
object:a11yManager];
195+
object:a11yManagerStrongObject];
191196
});
192197
[[NSNotificationCenter defaultCenter] addObserver:self
193198
selector:@selector(namedOrientationDidChange)

0 commit comments

Comments
 (0)