• Stars
    star
    148
  • Rank 249,912 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a pure js pull-down-refresh and pull-up-loadmore react-native listview

React Native RefreshableListView (remobile)

A awesome pull-down-refresh and pull-up-loadmore listview

Installation

npm install @remobile/react-native-refresh-infinite-listview --save

Usage

Example

'use strict';

var React = require('react');
var ReactNative = require('react-native');
var {
    View,
    Text,
    StyleSheet,
    ListView
} = ReactNative;

var TimerMixin = require('react-timer-mixin');
var RefreshInfiniteListView = require('@remobile/react-native-refresh-infinite-listview');

var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
module.exports = React.createClass({
    mixins: [TimerMixin],
    data: {index: 0, maxIndex:20, list:[]},
    getData(init) {
        var total = 5;
        if (init) {
            this.data.index = 0;
            this.data.list = [];
            total = Math.floor(Math.random()*5);
        }
        for (var i=0; i<total; i++) {
            this.data.list[this.data.index] = "Row" + (this.data.index+1);
            this.data.index++;
        }
    },
    getInitialState() {
        this.getData(true);
        return {
            dataSource: ds.cloneWithRows(this.data.list)
        }
    },
    onRefresh() {
        this.getData(true);
        this.setTimeout(()=>{
            this.list.hideHeader();
            this.setState({dataSource: ds.cloneWithRows(this.data.list)});
        }, 1000);
    },
    onInfinite() {
        this.getData();
        this.setTimeout(()=>{
            this.list.hideFooter();
            this.setState({dataSource: ds.cloneWithRows(this.data.list)});
        }, 1000);
    },
    loadedAllData() {
        return this.data.index >= this.data.maxIndex||this.data.index===0;
    },
    renderRow(text) {
        return (
            <View style={styles.row}>
                <Text >
                    {text}
                </Text>
            </View>
        )
    },
    renderSeparator(sectionID, rowID) {
        return (
            <View style={styles.separator} key={sectionID+rowID}/>
        );
    },
    render() {
        return (
            <View style={{flex:1}}>
                <View style={{height:20}} />
                <RefreshInfiniteListView
                    ref = {(list) => {this.list= list}}
                    dataSource={this.state.dataSource}
                    renderRow={this.renderRow}
                    renderSeparator={this.renderSeparator}
                    loadedAllData={this.loadedAllData}
                    initialListSize={30}
                    scrollEventThrottle={10}
                    style={{backgroundColor:'transparent'/*,top:100, left:10, width:200, height:300, position:'absolute'*/}}
                    onRefresh = {this.onRefresh}
                    onInfinite = {this.onInfinite}
                    >
                </RefreshInfiniteListView>
            </View>
        )
    }
});

var styles = StyleSheet.create({
    row: {
        height:60,
        flex: 1,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center'
    },
    list: {
        alignSelf:'stretch'
    },
    separator: {
        height: 1,
        backgroundColor: '#CCC'
    },
});

Screencasts

refresh

Props

  • footerHeight:number if you need use infinite with custom, must set footerHeight
  • pullDistance:number set pull distance, default is 50
  • renderEmptyRow:func
            renderEmptyRow: () => {
                return (
                    <View style={{height:Dimensions.get('window').height, justifyContent:'center',alignItems:'center'}}>
                        <Text style={{fontSize:40, fontWeight:'800', color:'red'}}>
                            have no data
                        </Text>
                    </View>
                )
            },
  • renderHeaderRefreshIdle:func
            renderHeaderRefreshIdle: () => {return (
                <View style={{flex:1, height:DEFAULT_HF_HEIGHT, justifyContent:'center', alignItems:'center'}}>
                    <Text style={styles.text}>
                        pull down refresh...
                    </Text>
                    <Image
                        source={require('./pull_arrow.png')}
                        resizeMode={Image.resizeMode.stretch}
                        style={styles.image}
                        />
                </View>
            )},
  • renderHeaderWillRefresh:func
            renderHeaderWillRefresh: () => {return (
                <View style={{height:DEFAULT_HF_HEIGHT, justifyContent:'center', alignItems:'center'}}>
                    <Text style={styles.text}>
                        release to refresh...
                    </Text>
                    <Image
                        source={require('./pull_arrow.png')}
                        resizeMode={Image.resizeMode.stretch}
                        style={[styles.image, styles.imageRotate]}
                        />
                </View>
            )},
  • renderHeaderRefreshing:func
            renderHeaderRefreshing: () => {return (
                <View style={{height:DEFAULT_HF_HEIGHT, justifyContent:'center', alignItems:'center'}}>
                    <Text style={styles.text}>
                        refreshing...
                    </Text>

                    <ActivityIndicatorIOS
                        size='small'
                        animating={true}/>
                </View>
            )},
  • renderHeaderRefreshing:func
            renderFooterInifiteIdle: () => {return (
                <View style={{height:DEFAULT_HF_HEIGHT, justifyContent:'center', alignItems:'center'}}>
                    <Image
                        source={require('./pull_arrow.png')}
                        resizeMode={Image.resizeMode.stretch}
                        style={[styles.image, styles.imageRotate]}
                        />
                    <Text style={styles.text}>
                        pull up to load more...
                    </Text>
                </View>
            )},
  • renderFooterWillInifite:func
            renderFooterWillInifite: () => {return (
                <View style={{height:DEFAULT_HF_HEIGHT, justifyContent:'center', alignItems:'center'}}>
                    <Image
                        source={require('./pull_arrow.png')}
                        resizeMode={Image.resizeMode.stretch}
                        style={styles.image}
                        />
                    <Text style={styles.text}>
                        release to load more...
                    </Text>
                </View>
            )},
  • renderFooterInifiting:func
            renderFooterInifiting: () => {return (
                <View style={{height:DEFAULT_HF_HEIGHT, justifyContent:'center', alignItems:'center'}}>
                    <ActivityIndicatorIOS
                        size='small'
                        animating={true}/>
                    <Text style={styles.text}>
                        loading...
                    </Text>
                </View>
            )},
  • renderFooterInifiteLoadedAll:func
            renderFooterInifiteLoadedAll: () => { return (
                <View style={{height:DEFAULT_HF_HEIGHT, justifyContent:'center', alignItems:'center'}}>
                    <Text style={styles.text}>
                        have loaded all data
                    </Text>
                </View>
            )},
  • onRefresh:func
            onRefresh: () => {
                console.log("onRefresh");
            },
  • onInfinite':func
            onInfinite: () => {
                console.log("onInfinite");
            }
  • loadedAllData':func
            loadedAllData: () => {
                return false;
            }

More Repositories

1

react-native-splashscreen

Java
373
star
2

react-native-toast

A android like toast for android and ios, android use native toast, ios use UIView+Toast
Objective-C
346
star
3

react-native-cache-image

JavaScript
161
star
4

react-native-marquee-label

A marquee label for react-native(if you use js pure marquee, use remobile/react-native-marquee[ https://github.com/remobile/react-native-marquee ])
Objective-C
116
star
5

react-native-file-transfer

A file-transfer for react-native, code come from cordova, support for android and ios
Java
85
star
6

react-native-update

Update js version and app version for ios and android
Java
79
star
7

react-native-qrcode-local-image

A local qrcode image parse for react-native
Java
55
star
8

react-native-cordova

A cordova plugin bridge for react-native
Java
50
star
9

react-native-image-animation

A pure js image animation like ios animationImages, support ios and android
JavaScript
48
star
10

react-native-zip

A unzip for react-native, code come from cordova, support for android and ios
C
46
star
11

react-native-action-sheet

JavaScript
38
star
12

react-native-template

fastly create new project for react-native
JavaScript
33
star
13

react-native-cocos2dx

A react-native wrapper cocos2d-html5
HTML
32
star
14

react-native-camera

A cordova camera for react-native, supprt for ios and android
Java
30
star
15

react-native-video

A video player for react-native, support hls
Java
26
star
16

react-native-marquee

A react-native marquee list write in js
JavaScript
26
star
17

react-native-datetime-picker

A datetime-picker for react-native support for android and ios
Java
24
star
18

react-native-mongoose

JavaScript
23
star
19

react-native-card-swiper

A react-native card swiper write in js
JavaScript
23
star
20

react-native-des

A des crypto for react-native
Objective-C
22
star
21

react-native-local-notifications

A cordova local-notifications for react-native, supprt for ios and android
Java
21
star
22

react-native-image-crop

A component for react-native crop image, such as edit user head
JavaScript
19
star
23

react-native-image-picker

A image picker for react-native, supprt for ios and android
Java
18
star
24

react-native-echarts

A react-native wrapper baidu echarts
HTML
16
star
25

react-native-battery-status

Objective-C
15
star
26

react-native-indexed-listview

A indexed listview in chat app like contacts list
JavaScript
15
star
27

react-native-dialogs

A dialogs for react-native, code come from cordova, support for android and ios
Java
15
star
28

react-native-smart-keyboard

A smart keyboard for ios base on IQKeyboardManager[android not needed]
Objective-C
14
star
29

react-native-sqlite

A cordova sqlite for react-native, supprt for ios and android
C
12
star
30

react-native-simple-button

A Simple react-native button
JavaScript
11
star
31

react-native-module

Dynamic loading third party react-native app/module for react-native
Java
11
star
32

react-native-qrcode

A pure js show string as qrcode in react-native View
JavaScript
9
star
33

atom-wx

微信小程序语法高亮(atom-wx)
9
star
34

react-native-contacts

Java
9
star
35

react-native-file

Java
8
star
36

react-native-kitchen-sink

kitchen-sink for react-native
JavaScript
8
star
37

react-native-call-state

phone call state detection module for react-native,include ios and android.
Java
7
star
38

react-native-card-list

A react-native card list write in js
JavaScript
6
star
39

react-native-clip-rect

A clip react for react-native, the shape is center highlight and around darkness
JavaScript
6
star
40

react-native-capture

Objective-C
6
star
41

react-native-audio

A audio player for react-native
Java
6
star
42

react-native-chat

react-native-chat
JavaScript
5
star
43

remobile

react mobile library
JavaScript
4
star
44

react-native-image-compress

react native base64 image compress, android and ios included.
Java
4
star
45

react-native-amap-geolocation

a react native amap geolocation moudle for android and ios
Objective-C
4
star
46

react-native-baidu-map

A baidu map for react-native, support for ios and android
Objective-C
4
star
47

react-native-call

A call for react-native
Java
4
star
48

wx-template

微信小程序模板工程
JavaScript
3
star
49

react-native-camera-roll-picker

A React Native component providing images selection from camera roll
JavaScript
3
star
50

react-native-maps-direction-uri

a map direction use uri mode for react native, ios map,qq map,baidu map,iosa map be supported.
Java
2
star
51

react-lifecycle

A react lifecycle for react and react-native
JavaScript
2
star
52

react-native-3d-panel

A 3d left menu like old version QQ(模仿老版本QQ的侧滑菜单)
JavaScript
2
star
53

react-native-cache-module

Cache dynamic loading third party react-native app/module for react-native
JavaScript
1
star
54

remobile-server

A React Content Management System Build With Redux, Relate, GraphQL, Mongoose And AntDesign
JavaScript
1
star
55

mdoc

Markdown doc web site
JavaScript
1
star
56

react-native-image-edit

react-native-image-edit
Java
1
star
57

remobile-ant

CSS
1
star