經過前面三篇的探索,我大概瞭解了CodePush可實現的效果。本篇是記錄總結怎麼把RN的項目集成到現有的項目中來。node
進入package.json所在的文件目錄下,執行以下命令。react
npm install
複製代碼
安裝後,文件夾裏面會多出node_modules。 ios
# React Native requirements
pod 'React', :path => './node_modules/react-native', :subspecs => [
'Core',
'CxxBridge', # Include this for RN >= 0.47
'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
'RCTText',
'RCTNetwork',
'RCTWebSocket', # Needed for debugging
'RCTAnimation', # Needed for FlatList and animations running on native UI thread
# Add any other subspecs you want to use in your project
]
# Explicitly include Yoga if you are using RN >= 0.42.0
pod 'yoga', :path => './node_modules/react-native/ReactCommon/yoga'
pod 'DoubleConversion', :podspec => './node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => './node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => './node_modules/react-native/third-party-podspecs/Folly.podspec'
複製代碼
react-native bundle --entry-file App.js --bundle-output main.jsbundle --platform ios --assets-dest ./bundle --dev false
複製代碼
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTBridgeDelegate.h>
複製代碼
注意moduleName和RN中的保持一致。npm
- (void)addRNView {
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"PersonPage"
initialProperties:nil];
rootView.backgroundColor = [UIColor redColor];
rootView.frame = CGRectMake(0, 0, SCREENW, SCREENH - kTabarHeight);
[self.view addSubview:rootView];
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
return [NSURL URLWithString:@"http://192.168.2.113:8081/index.bundle?platform=ios&dev=true"];
}
複製代碼
我也是在入門的路上,若是上面有不對的,歡迎大神指點哦~json
另外,我很好奇,難道你們都是這樣複製,而後打包,讓iOS跑起來的嗎?感受這樣還挺麻煩的。小程序
以後我就開始搭界面了。簡單的界面還比較好搭,你們看看個人成果(以咱們項目的我的中心頁面練手的)~~~代碼感受跟小程序很像。佈局是yoga佈局,我到如今有些仍是須要試幾回才能出來效果。。 react-native
上面的佈局控件什麼的,看官網或者用到什麼去網上查一下~目前是在研究自定義下拉刷新~ 下篇寫RN與iOS交互~~~bash