【问题标题】:How can i solve: "RCTBridge required dispatch_sync to load" in React Native using yarn workspaces?我该如何解决:使用纱线工作区在 React Native 中“加载 RCTBridge 需要 dispatch_sync 加载”?
【发布时间】:2021-07-09 14:38:28
【问题描述】:
我关注了中篇文章:React Native 0.63 Monorepo walkthrough,以使纱线工作区与 react-native 一起使用。 Everhtings 可以工作,我可以构建我的 iOS 和 Android 应用程序,Metro Bundler 也可以工作,但是当我使用 yarn workspace mobile ios 构建我的 iOS 应用程序时,我从 Metro Bundler 收到以下警告
RCTBridge required dispatch_sync to load RCTDevLoadingView. This may lead to deadlocks
除非我将 react-native 与 yarn 工作区一起使用,否则我不会收到此警告。因此,我怀疑该错误是由我的 monorepo 设置产生的。
您知道如何删除此警告吗?
【问题讨论】:
标签:
react-native
yarn-workspaces
metro-bundler
【解决方案1】:
打开你的/ios/YourAppName/AppDelegate.m
#import "AppDelegate.h"
// ADD THIS
#if RCT_DEV
#import <React/RCTDevLoadingView.h>
#endif
// TILL HERE
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation
moduleProvider:nil
launchOptions:launchOptions];
// THIS CONDITION
#if RCT_DEV
[bridge moduleForClass:[RCTDevLoadingView class]];
#endif
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"Test"
initialProperties:nil];
// TILL HERE
...
}
来源here