├── demo.gif ├── img ├── va-top.png ├── va-top@2x.png └── va-top@3x.png ├── TopButton.js ├── package.json ├── RefreshableListView.js └── README.md /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shigebeyond/react-native-sk-refreshable-listview/HEAD/demo.gif -------------------------------------------------------------------------------- /img/va-top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shigebeyond/react-native-sk-refreshable-listview/HEAD/img/va-top.png -------------------------------------------------------------------------------- /img/va-top@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shigebeyond/react-native-sk-refreshable-listview/HEAD/img/va-top@2x.png -------------------------------------------------------------------------------- /img/va-top@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shigebeyond/react-native-sk-refreshable-listview/HEAD/img/va-top@3x.png -------------------------------------------------------------------------------- /TopButton.js: -------------------------------------------------------------------------------- 1 | var React = require('react-native') 2 | var { 3 | StyleSheet, 4 | Image, 5 | TouchableOpacity, 6 | PropTypes 7 | } = React; 8 | 9 | var TopButton = React.createClass({ 10 | propTypes: { 11 | onPress: PropTypes.func, 12 | }, 13 | render: function(){ 14 | return ( 15 | 16 | 17 | 18 | ) 19 | } 20 | }); 21 | 22 | var styles = StyleSheet.create({ 23 | topButton:{ 24 | position:'absolute', 25 | right:5, 26 | bottom:45, 27 | width:55, 28 | height:55, 29 | backgroundColor:'rgba(0,0,0,0)', 30 | }, 31 | topButtomImg: { 32 | width:40, 33 | height:40, 34 | } 35 | }) 36 | 37 | module.exports = TopButton; 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-sk-refreshable-listview", 3 | "version": "1.0.0", 4 | "description": "Component wraps ListView, supports: 1 pull down to refresh 2 pull up to load more 3 scroll to top 4 scroll to bottom", 5 | "main": "RefreshableListView.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/shigebeyond/react-native-sk-refreshable-listview.git" 12 | }, 13 | "keywords": [ 14 | "react-native", 15 | "refreshable-list-view", 16 | "pull-down-refresh", 17 | "pull-up-loadmore" 18 | ], 19 | "dependencies": { 20 | "react-native-sk-loader": "^1.0.0" 21 | }, 22 | "author": "shigebeyond", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/shigebeyond/react-native-sk-refreshable-listview/issues" 26 | }, 27 | "homepage": "https://github.com/shigebeyond/react-native-sk-refreshable-listview#readme" 28 | } 29 | -------------------------------------------------------------------------------- /RefreshableListView.js: -------------------------------------------------------------------------------- 1 | var React = require('react-native') 2 | var { 3 | ListView, 4 | StyleSheet, 5 | View, 6 | Text, 7 | Dimensions, 8 | PropTypes, 9 | RefreshControl 10 | } = React; 11 | 12 | var TopButton = require('./TopButton'), 13 | Loader = require('react-native-sk-loader'), // 加载器 14 | {width} = Dimensions.get('window'); 15 | 16 | var RefreshableListView = React.createClass({ 17 | statics: { 18 | DataSource: ListView.DataSource, 19 | }, 20 | 21 | propTypes: { 22 | onRefresh: PropTypes.func.isRequired, // 刷新数据的回调 23 | onLoadMore: PropTypes.func.isRequired, // 加载更多数据的回调 24 | }, 25 | 26 | listHeight: 0, // listview(scrollview)高度 27 | contentHeight: 0, // contentView高度 28 | 29 | getDefaultProps() { 30 | return { 31 | showLoadMore: false, // 是否显示加载更多 32 | hasTopButton: false, // 是否显示回到顶部的按钮 33 | } 34 | }, 35 | 36 | getInitialState() { 37 | return { 38 | isRefreshing: false, // 是否正在刷新 39 | isLoadingMore: false, // 是否正在加载更多 40 | } 41 | }, 42 | 43 | // 渲染脚部 44 | renderFooter: function() { 45 | // 没有更多/下一页数据 46 | if (!this.props.showLoadMore) { 47 | return null; 48 | } 49 | 50 | // 自定义渲染 51 | if (this.props.renderFooter) { 52 | return this.props.renderFooter(this.state.isLoadingMore) 53 | } 54 | 55 | // 默认渲染 56 | return (