我该如何解决:“RCTBridge 需要 dispatch_sync 才能加载”在 React Native 中使用 yarn 工作区?

Nik*_*las 4 react-native yarn-workspaces metro-bundler

我仔细阅读了中等文章:React Native 0.63 Monorepo 演练,以获取与 react-native 一起使用的纱线工作区。Everhtings 可以工作,我可以构建我的 iOS 和 Android 应用程序,Metro Bundler 也可以工作,但是当我使用yarn workspace mobile ios

RCTBridge required dispatch_sync to load RCTDevLoadingView. This may lead to deadlocks
Run Code Online (Sandbox Code Playgroud)

除非我在纱线工作区中使用 react-native,否则我不会收到此警告。因此,我怀疑错误是由我的 monorepo 设置产生的。

您知道如何删除此警告吗?

小智 8

打开你的 /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
  ...
}
Run Code Online (Sandbox Code Playgroud)

来源在这里

  • 这并没有解决我的问题。 (4认同)