React Native
npm i -g react-native-cli
react-native init demo01
react-native run-ios
获取屏幕宽度
import {
Dimensions,
StatusBar,
SafeAreaView,
Text
} from 'react-native';
import React from 'react';
const App = () => React$Node = ()=>{
return(
<>
<StatusBar>
<SafeAreaView>
<Text>
获取屏幕的宽度:{Dimensions.get('window').width + '\n'}
获取屏幕的高度:{Dimensions.get('window').height + '\n'}
获取屏幕的分辨率:{Dimensions.get('window').scale + '\n'}
</Text>
</SafeAreaView>
</StatusBar>
</>
)
}
区分平台
import { Platform } from 'react-native'
import React form 'react'
const App = () => React$Node = ()=>{
console.log(Platform.OS)// ios || android
// 还有很多Platform的用法
return(
<>
</>
)
}
pod install问题
pod install --verbose --no-repo-update
# 被墙了,需要这样去安装
# 再修改GitHub的host
# https://juejin.cn/post/6844904193170341896
# Flipper的一个依赖有问题,更新到最新版本可解决 修改Podfile中的use_filpper那行,添加版本。https://github.com/reactnativecn/react-native-website/issues/370
clashX 设置sock5代理端口https://www.bokezhu.com/2021/03/04/731.html
git 配置socks代理https://blog.csdn.net/wuquan0625/article/details/47401235
使用ts模板项目
https://www.react-native.cn/docs/typescript#using-custom-path-aliases-with-typescript
npm install -g expo-cli
expo init MyTSProject
1.删除旧版本 react-native-cli
npm uninstall -g react-native-cli
2.重新安装来自"react-native-community"的cli库 :
npm i -g @react-native-community/cli
3.重新初始化项目即可:
npx react-native init MyApp --template react-native-template-typescript
react-native集成dva
文章https://www.jianshu.com/p/e7ffeb0e5971
项目https://github.com/Tzng/ReactNativeDva
列表组件
单组的列表建议使用FlatList(有重用机制)
多组的列表建议使用SectionList
网络请求
联调:在ios虚拟机快捷键呼出菜单control+command+z,再点击Debug
react-native run-ios --simulator 'iPhone 12'
React Native无法调出Dev Menu
- react-native原生支持fetch进行网络请求的处理。
- 也可以使用第三方库axios
使用react-native-debugger调试react-native
debug工具
rn网络图片无法显示问题
- https://stackoverflow.com/questions/47035899/how-come-my-image-is-not-showing-react-native
- https://www.zhihu.com/question/38046813<