@@ -299,52 +299,52 @@ void RCTExecuteOnMainQueue(dispatch_block_t block)
299
299
// unless you know what you are doing.
300
300
void RCTUnsafeExecuteOnMainQueueSync (dispatch_block_t block)
301
301
{
302
- if (RCTIsMainQueue ()) {
303
- block ();
304
- } else {
305
- if (facebook::react::ReactNativeFeatureFlags::disableMainQueueSyncDispatchIOS ()) {
306
- RCTLogError (@" RCTUnsafeExecuteOnMainQueueSync: Sync dispatches to the main queue can deadlock React Native." );
307
- }
308
- dispatch_sync (dispatch_get_main_queue (), ^{
309
- block ();
310
- });
311
- }
302
+ RCTUnsafeExecuteOnMainQueueSyncWithError (block, nil );
312
303
}
313
304
314
305
// Please do not use this method
315
306
// unless you know what you are doing.
316
- void RCTUnsafeExecuteOnMainQueueSyncWithError (dispatch_block_t block, NSString *context)
307
+ void RCTUnsafeExecuteOnMainQueueSyncWithError (dispatch_block_t block, NSString *_Nullable context)
317
308
{
318
309
if (RCTIsMainQueue ()) {
319
310
block ();
320
- } else {
321
- if (facebook::react::ReactNativeFeatureFlags::disableMainQueueSyncDispatchIOS ()) {
322
- RCTLogError (@" RCTUnsafeExecuteOnMainQueueSync: %@ " , context);
323
- }
324
- dispatch_sync (dispatch_get_main_queue (), ^{
325
- block ();
326
- });
311
+ return ;
327
312
}
313
+
314
+ if (facebook::react::ReactNativeFeatureFlags::disableMainQueueSyncDispatchIOS ()) {
315
+ RCTLogError (
316
+ @" RCTUnsafeExecuteOnMainQueueSync: %@ " ,
317
+ context ?: @" Sync dispatches to the main queue can deadlock React Native." );
318
+ }
319
+
320
+ dispatch_sync (dispatch_get_main_queue (), ^{
321
+ block ();
322
+ });
328
323
}
329
324
330
325
static void RCTUnsafeExecuteOnMainQueueOnceSync (dispatch_once_t *onceToken, dispatch_block_t block)
331
326
{
332
327
// The solution was borrowed from a post by Sophie Alpert:
333
328
// https://sophiebits.com/2014/04/02/dispatch-once-initialization-on-the-main-thread
334
329
// See also: https://www.mikeash.com/pyblog/friday-qa-2014-06-06-secrets-of-dispatch_once.html
335
- if ( RCTIsMainQueue ()) {
330
+ auto executeOnce = ^ {
336
331
dispatch_once (onceToken, block);
337
- } else {
338
- if (DISPATCH_EXPECT (*onceToken == 0L , NO )) {
339
- if (facebook::react::ReactNativeFeatureFlags::disableMainQueueSyncDispatchIOS ()) {
340
- RCTLogError (
341
- @" RCTUnsafeExecuteOnMainQueueOnceSync: Sync dispatches to the main queue can deadlock React Native." );
342
- }
343
- dispatch_sync (dispatch_get_main_queue (), ^{
344
- dispatch_once (onceToken, block);
345
- });
346
- }
332
+ };
333
+
334
+ if (RCTIsMainQueue ()) {
335
+ executeOnce ();
336
+ return ;
337
+ }
338
+
339
+ if (!DISPATCH_EXPECT (*onceToken == 0L , NO )) {
340
+ return ;
341
+ }
342
+
343
+ if (facebook::react::ReactNativeFeatureFlags::disableMainQueueSyncDispatchIOS ()) {
344
+ RCTLogError (@" RCTUnsafeExecuteOnMainQueueOnceSync: Sync dispatches to the main queue can deadlock React Native." );
347
345
}
346
+
347
+ dispatch_sync (dispatch_get_main_queue (), executeOnce);
348
348
}
349
349
350
350
CGFloat RCTScreenScale (void )
0 commit comments