22 * Created by zhaohang on 2016/7/25.
33 */
44import 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" ;
66import { connect } from 'react-redux'
77import Button from "react-native-button" ;
88import Swipeout from "react-native-swipeout" ;
9- import loginActions from '../../actions/loginActions '
9+ import listViewActions from '../../actions/listViewActions '
1010import { bindActionCreators } from 'redux'
1111const styles = StyleSheet . create ( {
1212 row : {
@@ -34,27 +34,42 @@ const styles = StyleSheet.create({
3434class 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
7997function mapStateToProps ( state ) {
8098 return {
81- state :{
82- }
99+ state :state . listViewReducer
83100 }
84101}
85102
86103function mapDispatchToProps ( dispatch ) {
87- return bindActionCreators ( loginActions , dispatch ) ;
104+ return bindActionCreators ( listViewActions , dispatch ) ;
88105}
89106
90107export default connect (
0 commit comments