2017-10-26 6 views
1

私のモバイルアプリケーションに複数のRCTRootViewがある場合。私は同じRCTBridgeを再利用するか、それぞれを作成する必要があります。両方のRCTRootViewが同じVCまたは異なるVC上にあると仮定します。ありがとうございました。RCTBridge in Reactネイティブ

答えて

1

モバイルアプリ全体にブリッジを1つだけ使用することをおすすめします。私は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];