gpt4 book ai didi

react-native - React Native 中的 RCTBridge

转载 作者:行者123 更新时间:2023-12-02 03:45:28 25 4
gpt4 key购买 nike

如果我的移动应用程序有多个 RCTRootView 使用情况。我应该重复使用相同的 RCTBridge 还是为每个 RCTBridge 创建一个。假设两个 RCTRootView 可以位于同一 VC 上,也可以位于不同 VC 上。谢谢。

最佳答案

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

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

AppDelegate.h

    @interface AppDelegate : UIResponder<UIApplicationDelegate,RCTBridgeDelegate>
@property (nonatomic, strong) UIWindow *window;
@property (strong) RCTBridge *reactBridge;
@end

AppDelegate.m

- (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;
}

你可以像这样访问任何地方的桥。

  AppDelegate *appdelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];

[[RCTRootView alloc] initWithBridge:appdelegate.reactBridge moduleName:@"ListViewNetworking" initialProperties:nil];

关于react-native - React Native 中的 RCTBridge,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46944197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com