首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反应中的RCTBridge

反应中的RCTBridge
EN

Stack Overflow用户
提问于 2017-10-26 00:57:55
回答 1查看 3.3K关注 0票数 2

如果我的移动应用程序有一个以上的RCTRootView使用量。我是应该重用相同的RCTBridge,还是为每个创建一个。假设两个RCTRootView都可以在相同的VC或不同的VC上。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-09 06:39:07

建议整个移动应用程序只有一个网桥。我将证明iOS的代码。

我将在主应用程序中创建桥梁,并将在任何地方使用。

AppDelegate.h

代码语言:javascript
复制
    @interface AppDelegate : UIResponder<UIApplicationDelegate,RCTBridgeDelegate>
         @property (nonatomic, strong) UIWindow *window;
         @property (strong) RCTBridge *reactBridge;
    @end

AppDelegate.m

代码语言:javascript
复制
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

  self.reactBridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];


  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.reactBridge moduleName:@"ListViewNetworking" initialProperties:nil];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

,您可以像这样随时随地访问桥。

代码语言:javascript
复制
  AppDelegate *appdelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];

   [[RCTRootView alloc] initWithBridge:appdelegate.reactBridge moduleName:@"ListViewNetworking" initialProperties:nil];
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46944197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档