Skip to content

Commit eade47d

Browse files
author
z50902677
committed
新增list点击时间
1 parent 39eb11e commit eade47d

File tree

8 files changed

+109
-22
lines changed

8 files changed

+109
-22
lines changed

src/actions/listViewActions.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Created by zhaohang on 2016/7/28.
3+
*/
4+
5+
import { createAction } from 'redux-actions';
6+
import listViewActionEnum from '../constants/listViewActionEnum'
7+
import { api, callApi } from '../apis/api'
8+
import { Actions } from "react-native-router-flux";
9+
const listViewActions = {
10+
setListView:createAction(listViewActionEnum.SET_LIST_VIEW),
11+
toDesOfList: (data)=> {
12+
return dispatch=> {
13+
dispatch(
14+
listViewActions.setListView(data)
15+
);
16+
}
17+
},
18+
getListRequest: (data)=> {
19+
return dispatch=> {
20+
callApi(
21+
api.allList(data),
22+
(data)=>dispatch(listViewActions.requestListSuccess(data)),
23+
(err)=>console.warn(err)
24+
);
25+
}
26+
},
27+
requestListSuccess: (data)=> {
28+
return dispatch=> {
29+
dispatch(
30+
listViewActions.setListView(data)
31+
);
32+
}
33+
}
34+
};
35+
36+
export default listViewActions;

src/apis/api.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const api = {
66
`${appConfig.serviceRoot}app/login`,
77
fetchMethod.Get,
88
{parameter: parameter}
9+
),
10+
allList: (parameter)=> createFetch(
11+
`${appConfig.serviceRoot}app/listAll`,
12+
fetchMethod.Get,
13+
{parameter: parameter}
914
)
1015
};
1116

src/constants/appConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const appConfig = {
2-
serviceRoot: 'http://172.23.61.139:3000/'
2+
serviceRoot: 'http://172.23.61.142:3000/'
33
};
44

55
export default appConfig;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Created by zhaohang on 2016/7/28.
3+
*/
4+
const listViewActionEnum = {
5+
SET_LIST_VIEW: 'SET_LIST_VIEW'
6+
};
7+
8+
export default listViewActionEnum;

src/containers/android/ListView.js

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* Created by zhaohang on 2016/7/25.
33
*/
44
import React ,{Component}from 'react';
5-
import {View, Text, StyleSheet,TextInput,Image,ListView} from "react-native";
5+
import {View, Text, StyleSheet,TextInput,Image,ListView,TouchableHighlight} from "react-native";
66
import { connect } from 'react-redux'
77
import Button from "react-native-button";
88
import Swipeout from "react-native-swipeout";
9-
import loginActions from '../../actions/loginActions'
9+
import listViewActions from '../../actions/listViewActions'
1010
import {bindActionCreators} from 'redux'
1111
const styles = StyleSheet.create({
1212
row: {
@@ -34,27 +34,42 @@ const styles = StyleSheet.create({
3434
class listView extends Component {
3535
constructor(props) {
3636
super(props);
37-
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
37+
//let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
3838
this.state = {
39-
dataSource :ds.cloneWithRows([{
40-
url: '../image/logo.png', title: '第四代活塞,谁发的第四代活塞,谁发的第四代活塞,谁发的', author: '张三', data: '2016-01-01'
41-
}, {
42-
url: '/src/image/login.png',
43-
title: '库克将怒火几年级',
44-
author: 'lily',
45-
data: '2016-08-08'
46-
}])
39+
4740
};
41+
this.getAllList = this.getAllList.bind(this);
42+
this.pressRow = this.pressRow.bind(this);
43+
}
44+
componentWillReceiveProps(nextProps) {
45+
this.setState({
46+
47+
});
48+
}
49+
50+
componentWillMount() {
51+
//控件加载的时候先发起服务请求
52+
this.props.getListRequest(1);
53+
}
54+
pressRow(id) {
55+
this.props.toDesOfList(id);
56+
}
57+
getAllList(aa) {
58+
alert(aa);
4859
}
4960
render() {
61+
let data = this.props.state.listData;
62+
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
63+
let dataSource = ds.cloneWithRows(data);
5064
return (
51-
<ListView
52-
dataSource={this.state.dataSource}
65+
<ListView enableEmptySections = {true} onEndReached = {this.getAllList} onEndReachedThreshold = {20}
66+
dataSource={dataSource}
5367
renderRow={(rowData) =>
54-
<Swipeout right={[{text:'删除',backgroundColor:'red'}]} backgroundColor={'#FFF'}>
68+
<Swipeout right={[{text:'删除',backgroundColor:'red'}]} backgroundColor={'#FFF'}>
69+
<TouchableHighlight onPress={() => this.pressRow(rowData.id)}>
5570
<View style={styles.row}>
5671
<View>
57-
<Image style={styles.thumb} source={require('../../image/login.png')} />
72+
<Image style={styles.thumb} source={{uri:rowData.image}} />
5873
</View>
5974
<View>
6075
<View>
@@ -64,12 +79,15 @@ class listView extends Component {
6479
</View>
6580
<View>
6681
<Text style={styles.desc}>
67-
{rowData.author} {rowData.data}
82+
{rowData.author} {rowData.date}
6883
</Text>
6984
</View>
7085
</View>
7186
</View>
87+
</TouchableHighlight>
7288
</Swipeout>
89+
90+
7391
}
7492
/>
7593
);
@@ -78,13 +96,12 @@ class listView extends Component {
7896

7997
function mapStateToProps(state) {
8098
return {
81-
state:{
82-
}
99+
state:state.listViewReducer
83100
}
84101
}
85102

86103
function mapDispatchToProps(dispatch) {
87-
return bindActionCreators(loginActions, dispatch);
104+
return bindActionCreators(listViewActions, dispatch);
88105
}
89106

90107
export default connect(

src/containers/android/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class App extends React.Component {
3232
<Scene key="main" direction="vertical" component={main} title="Main"
3333
hideNavBar/>
3434
<Scene key="ListView" direction="vertical" component={ListView} title="ListView"
35-
hideNavBar/>
35+
hideNavBar/>
3636
</Scene>
3737
<Scene key="error" component={Error}/>
3838
</Scene>

src/reducers/listViewReducer.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Created by zhaohang on 2016/7/28.
3+
*/
4+
import { handleActions } from 'redux-actions'
5+
import listViewActions from '../actions/listViewActions'
6+
import {ListView} from "react-native";
7+
const initialState = {
8+
listData :[]
9+
};
10+
11+
const loginReducer = handleActions({
12+
[listViewActions.setListView]: (state, action) => {
13+
state = Object.assign({}, state);
14+
state.listData = action.payload;
15+
return state;
16+
}
17+
18+
}, initialState);
19+
20+
export default loginReducer;

src/reducers/rootReducer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
*/
44
import { combineReducers } from 'redux';
55
import loginReducer from './loginReducer';
6+
import listViewReducer from './listViewReducer';
67
// ... other reducers
78

89
const rootReducer = combineReducers({
9-
loginReducer
10+
loginReducer,listViewReducer
1011
// ... other reducers
1112
});
1213

0 commit comments

Comments
 (0)