一、升級步驟
1拒垃、升級工具包
npm install -g react-native-cli yarn
2、生成一個與原來工程一樣名字的工程
react-native init ProjectName
如果你是搭建的sinopia私有npm服務(wù)的話瓷蛙,需要對@符號的庫進行重定向到npm的公服悼瓮,不然無法解析,會報錯
npm config set "@react-navigation:registry" http://registry.npmjs.org/
npm config set "@react-native-community:registry" http://registry.npmjs.org/
npm config set "@jest:registry" http://registry.npmjs.org/
npm config set "@cnakazawa:registry" http://registry.npmjs.org/
npm config set "@types:registry" http://registry.npmjs.org/
3艰猬、將iOS和Android原生工程先進行手動遷移到新工程中
- 工程能跑起來再進行下一步
4横堡、將JS代碼進行遷移到新工程
- 直接copy過來即可
- 先不著急升級
react-navigation
,先把第三方庫的問題找出來冠桃,有問題的就先進行升級或者替換
5命贴、升級react-navigation
- 卸載原來的react-navigation
yarn remove react-navigation
- 安裝最新的react-navigation
yarn add react-navigation
6、用Xcode10.1跑項目遇到的問題
二食听、升級之后的問題
1胸蛛、react-native-svg
解決方案:
去掉react-native-iber-svg,安裝最新的react-native-svg
去掉react-native-iber-qrcode-svg樱报,安裝最新的react-native-qrcode-svg
2葬项、stripe
報錯原因:
解決方案:
3、Slider
報錯原因:A trailing comma is not permitted after the rest property
解決方案:
4迹蛤、Malformed calls from JS:field sizes are different
報錯原因:Malformed calls from JS:field sizes are different
解決方案:
5民珍、react-navigation
解決方案:
yarn add react-native-gesture-handler
react-native link react-native-gesture-handler
6、react-navigation
解決方案:
導(dǎo)出的createStackNavigator要用createAppContainer包裹才能用
https://reactnavigation.org/docs/en/app-containers.html
7盗飒、react-navigation
在iPhone中手勢返回的時候報錯
問題分析:
該問題是由于screen沒有得到手勢返回的事件穷缤,是由于createAppContainer懶加載導(dǎo)致的,如果你的代碼是讓createAppContainer等待一些耗時事件完成之后再顯示加載的箩兽,就會出現(xiàn)改問題
解決方案:
給每一個screen手動添加手勢
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
gestureHandlerRootHOC(screen);
8津肛、react-navigation
解決方案:
NavigationActions.reset 替換成 StackActions.reset
9、Xcode10運行項目報錯node_modules/react-native/third-party/glog-0.3.5
解決方案:
cd node_modules/react-native/scripts && ./ios-install-third-party.sh && cd ../../../
cd node_modules/react-native/third-party/glog-0.3.5/ && ../../scripts/ios-configure-glog.sh
10汗贫、node_modules/@sentry/cli: Command failed.
解決方案:
升級node版本
參考鏈接
11身坐、Xcode打Release包報錯:1.ld: could not reparse object file in bitcode bundle: 'Invalid bitcode version (Producer: '902.0.39.2_0' Reader: '900.0.39.2_0')', using libLTO version 'LLVM version 9.0.0, (clang-900.0.39.2)' for architecture arm64
解決方案:
關(guān)閉bitcode
三秸脱、 其他問題
1、Slider
部蛇、ViewPagerAndroid
摊唇、WebView
、Async Storage
在未來將從react-native中移除涯鲁,需要從@react-native-community
引入
可參考:
https://github.com/react-native-community/react-native-slider
https://github.com/react-native-community/react-native-viewpager
https://github.com/react-native-community/react-native-webview
https://github.com/react-native-community/react-native-async-storage
2巷查、升級之后,View的默認背景色為白色抹腿,之前是灰色
3岛请、語法更嚴謹
- const 修飾的變量不能修改
- 組件的樣式大小不能為空(比如:width: null)