react-native ListView 封装 实现 下拉刷新/上拉加载更多

1.PageListView 组件封装

src/components/PageListView/index.js

2.页面调用

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
<PageListView
  pageLen={10}
  renderRow={this._renderRow.bind(this)}
  refresh={this._refresh.bind(this)}
  loadMore={this._loadMore.bind(this)}
/>
 
 
// 20180730 刷新
_refresh(callBack){
  // fetch(分页接口url+'?page=1')
  //   .then((response)=>response.json())
  //   .then((responseData)=>{
  //     //根据接口返回结果得到数据数组
  //     let arr=responseData.result;
  //     callBack(arr);
  //   });
 
  request
    .get(config.api.base + config.api.comment, {
      accessToken: 'abc',
      page: 1,
      creation: '123'
    })
    .then((data) => {
        //根据接口返回结果得到数据数组
        let arr = data.data;
        callBack(arr);
    })
    .catch((error) => {
      console.log('请求失败!');
    })
}
 
// 20180730 加载更多
_loadMore(page,callBack){
  // fetch(分页接口url+'?page='+page)
  //   .then((response)=>response.json())
  //   .then((responseData)=>{
  //     //根据接口返回结果得到数据数组
  //     let arr=responseData.result;
  //     callBack(arr);
  //   });
 
  request
    .get(config.api.base + config.api.comment, {
      accessToken: 'abc',
      page: page,
      creation: '123'
    })
    .then((data) => {
        //根据接口返回结果得到数据数组
        let arr = data.data;
        callBack(arr);
    })
    .catch((error) => {
      console.log(error);
    })
}
 
// 20180730 子组件渲染
_renderRow(row) {
  return (
    <CommentItem row={row} />
  )
}

3.效果图

posted @   每天都要进步一点点  阅读(1734)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示