ios原生项目展示reactnavtive界面(RN学习二)

基础:ios工程集成好reactnactive(可参考https://www.jianshu.com/p/23364db81a08),不足之处请指出

本文介绍在ViewController中加载reactnative界面,其实很简单,主要代码如下:

#import <React/RCTRootView.h>(先导入)

 NSString*urlStr =@"http://127.0.0.1:8081/index.bundle?platform=ios&dev=true";//index为要展示的rn界面,很多老项目为index.ios.js,那么此时这里就是index.ios

    NSURL*jsCodeLocation = [NSURLURLWithString:urlStr];

    RCTRootView *rootView = [[RCTRootView alloc]initWithBundleURL:jsCodeLocation moduleName:@"rntest" initialProperties:nil launchOptions:nil]; rootView.backgroundColor= [[UIColor alloc]initWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f];

    rootView.frame= [[UIScreen mainScreen]bounds];

    [self.viewaddSubview:rootView];

若想在开发模式下运行程序,请先在工程根目录执行npm start

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容