react native - 踩坑笔记
当前环境
- RN 0.45
非 1
https
访问
1 | https |
在
中添加 1
Info.plist
类型 1
NSAppTransportSecurity
。
在 1
Dictionary
下添加 1
NSAppTransportSecurity
类型 1
NSAllowsArbitraryLoads
, 值设为 1
Boolean
1
YES
添加例外的方式也很简单:
左键
选择 open with source code
然后添加类似如下的配置:1
Info.plist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>qq.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>sina.com.cn</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
Text 换行问题
-
设置属性
<Text numberOfLines={3} style={indexStyle.rowTitle}>{rowData.item.title}</Text>
-
计算宽度
rowTitle: { width: Dimen.window.width - 100, margin: 5, fontSize: 12 },
图片懒加载 1
react-native-lazyload
1 | react-native-lazyload |
https://github.com/magicismight/react-native-lazyload
yarn add react-native-lazyload
1
2
3
4
5
6
<LazyloadScrollView name="lazyload-list" style={indexStyle.container}>
<LazyloadImage
host="lazyload-list"
style={indexStyle.rowImage}
source=/>
</LazyloadScrollView>
remote debugger is in a background tab …
chrome调试器,单独页打开不要跑到后台,就不会出现这个烦人的提示了~
clone对象
1
2
3
4
5
6
7
import _ from 'lodash'
const obj = {
a:1,
b:2
}
const newObj = _.cloneDeep(obj);
对两个对象进行验证
1
2
JSON.stringify(obj) == JSON.stringify(newObj) //true
obj == newObj //false
本地缓存
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { AsyncStorage } from 'react-native';
// 设置
let storageKey = `index2:toy:${params.toyType}`;
AsyncStorage.setItem(storageKey, JSON.stringify(dataList),
err => {
if(!err){
console.log(`AsyncStorage set ok => ${storageKey}`);
}
}
);
// 读取
let storageKey = `index2:toy:${toyType}`;
AsyncStorage.getItem(storageKey).then((value) => {
let jsonValue = JSON.parse(value);
if(jsonValue!=null){
console.log(`AsyncStorage get ok => ${storageKey}`);
dispatch(setupData(jsonValue, params));
}
});
import 特点
默认文件 1
index.js
判断android还是ios
var Platform = require(‘Platform’);
if (Platform.OS === ‘android’) {
//todo
}else{
//todo
}
Toast 在Modal中使用 被覆盖
https://github.com/ant-design/ant-design-mobile/issues/547
本机调试 android
- 查看设备
1
adb devices
- 安装
1
react-native run-android
- 安装发布
1
react-native run-android --variant=release
- 签名
- 打开开发者菜单
1
adb shell input keyevent 82
->1
Dev Settings
->1
Debug server host for device
->1
本机IP:8081
1
Reload JS
- 如果配置完还是白屏 ,重新安装
1
react-native run-android