study

主要是先参考如下篇文章:

http://www.open-open.com/lib/view/open1461512056952.html

第一次接触redux,概念还比较模糊,同时js开发水平也一般,对一些语法学习还不是很懂,这里做个记录:
代码中的很多function func(): type的用法,我之前接触的基本都是无返回值类型的,这里添加一个 :Action类型,貌似就是确定了返回值类型的,不知道理解的对不对。

rac_willDeallocSignal的加载时机

今天看了下RAC的rac_willDeallocSignal的方法实现。我最初的猜测是NSObject (RACDeallocating)添加load方法,然后在里面进行method swzziling,添加dealloc方法,但是发现源码不是这样的。他只是通过常用的category 添加 associated 来进行的。先看他的简单实现:

React Native 双listView交互动画

此demo算是自己学习React Natvie的一个小例子的。效果如下

因为开发过程中,经常需要使用两个ListView进行交互,具体实现参考DEMO

可以通过点击左边的菜品分类,切换到对应的section中,也可以通过滑动右边的菜品,同步更新到左边的分类。
主要思路是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
componentDidUpdate() {
let scrollResponder = this.refs.listView.getScrollResponder();
scrollResponder.scrollResponderScrollTo({x: 0, y:this.pscroll(), animated: true});
}
shouldComponentUpdate(nextProps, nextState) {
return nextProps.needUpdate;
}
pscroll() {
console.log(this.props.section);
var height = 0;
for (var x in spuMenuItemList) {
if (parseInt(x) < parseInt(this.props.section)) {
height += spuMenuItemList[x].length * 100;
height += 20;
}
}
return height;
}
_onScroll(event: Object) {
var scrollProperties = this.refs.listView.scrollProperties;
// console.log(scrollProperties);
// console.log(scrollProperties.offset);
// console.log(this.props.section)
if (this.props.fromLeftTouched) {
return;
}
var height = 0;
for (var x in spuMenuItemList) {
height += spuMenuItemList[x].length * 100;
height += 20;
if (height > scrollProperties.offset) {
if (x != this.state.currentIndex) {
this.props.needChangeSection(parseInt(x));
this.state.currentIndex = parseInt(x);
}
break;
}
}
}

React Native学习笔记

在学习react Native的过程中,对一些知识的记录,不定期更新。。。

1. React 里直接修改 this.state 和调用 setState() 修改 state 的值有什么区别?

https://segmentfault.com/q/1010000002958584

使用对this.state赋值并没有什么作用,官方提醒,应该把this.state当成不可变变量。
而使用this.setState方法,会触发异步修改状态,状态改变的同时,会重新执行一次willUpdate,render等流程。需要注意的是,避免在执行完this.setState后马上读取this.state,此操作并不会获得最新修改的状态。

iOS下载内容保存在document中需要设置不同步

之前因为在document,保存了下载数据,导致app审核不通过。这个苹果是严格要求,网络下载的数据一般是不能保存在document目录中,建议是保存在cache中,如果真的需要保存在document中,就需要对保存的内容设置不同步标识。具体代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
if (![[NSFileManager defaultManager] fileExistsAtPath:[URL path]])
{
return NO;
}
BOOL success = NO;
NSError *error = nil;
success = [URL setResourceValue:[NSNumber numberWithBool: YES]
forKey:NSURLIsExcludedFromBackupKey error: &error];
return success;
}

iOS横屏应用旋转无动画

最近开发一个仅支持横屏的应用,发现进行180°旋转的时候没有动画,Google也没有找到有用的信息,显示的情况跟下面链接中的比较像无动画效果. 最后在苹果的官网资料上找到了灵感:https://developer.apple.com/library/ios/technotes/tn2244/_index.html
自己就是根据这个里面的内容,全部进行了操作,最后发现是LaunchScreen.stroyboard的问题,在
设置 中对Main Interface 和 Launch Screen File都设置成了空,将Launch Images Source 另外指定了图片,然后就解决了此问题。

我的解决方案不一定完全使用所有的情况,这里仅仅是做一个记录,有需要的可以试一下。