-
Notifications
You must be signed in to change notification settings - Fork 427
/
Copy pathDynamicPage.js
154 lines (138 loc) · 4.49 KB
/
DynamicPage.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* Created by guoshuyu on 2017/11/10.
*/
import React, {Component} from 'react';
import {
View, AppState, StatusBar, InteractionManager
} from 'react-native';
import styles from "../style"
import loginActions from '../store/actions/login'
import userActions from '../store/actions/user'
import eventActions from '../store/actions/event'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import {getActionAndDes, ActionUtils} from '../utils/eventUtils'
import EventItem from './widget/EventItem'
import PullListView from './widget/PullLoadMoreListView'
import * as Config from '../config'
import {getNewsVersion} from './AboutPage'
/**
* 动态 -> 我的关注,我的仓库
*/
@connect(
state => ({
userState: state.user,
loginState: state.login,
eventState: state.event,
}),
dispatch => ({
loginAction: bindActionCreators(loginActions, dispatch),
userAction: bindActionCreators(userActions, dispatch),
eventAction: bindActionCreators(eventActions, dispatch)
})
)
export default class DynamicPage extends Component {
constructor(props) {
super(props);
this._renderRow = this._renderRow.bind(this);
this._refresh = this._refresh.bind(this);
this._loadMore = this._loadMore.bind(this);
this._handleAppStateChange = this._handleAppStateChange.bind(this);
this.startRefresh = this.startRefresh.bind(this);
this.page = 1;
this.appState = 'active';
}
componentDidMount() {
InteractionManager.runAfterInteractions(() => {
this.startRefresh();
getNewsVersion();
});
AppState.addEventListener('change', this._handleAppStateChange);
/*setTimeout(() => {
if (__DEV__) {
Actions.VersionPage({
ownerName: "CarGuo",
repositoryName:"GSYGithubApp",
title: "CarGuo/GSYGithubApp"
})
}
}, 1000)*/
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}
startRefresh() {
if (this.refs.pullList)
this.refs.pullList.showRefreshState();
this._refresh();
}
_handleAppStateChange = (nextAppState) => {
if (this.appState.match(/inactive|background/) && nextAppState === 'active') {
if (this.refs.pullList)
this.refs.pullList.scrollToTop();
this.startRefresh();
}
this.appState = nextAppState;
};
_renderRow(rowData) {
let res = getActionAndDes(rowData);
return (
<EventItem
actionTime={rowData.created_at}
actionUser={rowData.actor.display_login}
actionUserPic={rowData.actor.avatar_url}
des={res.des}
onPressItem={() => {
ActionUtils(rowData)
}}
actionTarget={res.actionStr}/>
)
}
/**
* 刷新
* */
_refresh() {
let {eventAction} = this.props;
eventAction.getEventReceived(0, (res) => {
this.page = 2;
setTimeout(() => {
if (this.refs.pullList) {
this.refs.pullList.refreshComplete((res && res.length >= Config.PAGE_SIZE));
}
}, 500);
})
}
/**
* 加载更多
* */
_loadMore() {
let {eventAction} = this.props;
eventAction.getEventReceived(this.page, (res) => {
this.page++;
setTimeout(() => {
if (this.refs.pullList) {
this.refs.pullList.loadMoreComplete((res && res.length >= Config.PAGE_SIZE));
}
}, 300);
});
}
render() {
let {eventState, userState} = this.props;
let dataSource = (eventState.received_events_data_list);
return (
<View style={styles.mainBox}>
<StatusBar hidden={false} backgroundColor={'transparent'} translucent barStyle={'light-content'}/>
<PullListView
style={{flex: 1}}
ref="pullList"
renderRow={(rowData, index) =>
this._renderRow(rowData)
}
refresh={this._refresh}
loadMore={this._loadMore}
dataSource={dataSource}
/>
</View>
)
}
}