react-native开发问题以及处理

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

解决初始化TypeScript模板的RN项目报错问题

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<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值