2017-07-26 56 views
1

Integration with existing apps显示集成阵营原生成exsting应用

RCTRootView *rootView = 
    [[RCTRootView alloc] initWithBundleURL: jsCodeLocation 
           moduleName: @"RNHighScores" 
         initialProperties: nil 
          launchOptions: nil]; 
UIViewController *vc = [[UIViewController alloc] init]; 
vc.view = rootView; 
[self presentViewController:vc animated:YES completion:nil]; 

这是你构造从所述呈现视图控制器RN视图,而不是在所呈现的视图控制器。

对于android,doc显示了一种从呈现的(创建的)活动创建ReactRootView的方法。

public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler { 
    private ReactRootView mReactRootView; 
    private ReactInstanceManager mReactInstanceManager; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     mReactRootView = new ReactRootView(this); 
     mReactInstanceManager = ReactInstanceManager.builder() 
       .setApplication(getApplication()) 
       .setBundleAssetName("index.android.bundle") 
       .setJSMainModuleName("index.android") 
       .addPackage(new MainReactPackage()) 
       .setUseDeveloperSupport(BuildConfig.DEBUG) 
       .setInitialLifecycleState(LifecycleState.RESUMED) 
       .build(); 
     mReactRootView.startReactApplication(mReactInstanceManager, "HelloWorld", null); 

     setContentView(mReactRootView); 
    } 

} 

iOS应用程序可以做类似上面的android代码吗?这是创建一个自定义视图控制器,并在viewDidLoad中实例化RCTRootView。
这样做有什么缺点吗?

回答

0

是的,它工作。虽然我不知道是否有任何缺点。