Skip to content

A pull-to-refresh ListView which shows a loading spinner while your data reloads

Notifications You must be signed in to change notification settings

soldotno/react-native-refreshable-listview

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Native RefreshableListView

A pull-to-refresh ListView which shows a loading spinner while your data reloads

In action (from ReactNativeHackerNews):

React Native Hacker News

usage

props:

  • loadData: a function returning a promise or taking a callback, invoked upon pulldown. spinner will show until the promise resolves or the callback is called.
  • refreshDescription: text/element to show alongside spinner.

example

var React = require('react-native')
var {Text, View, ListView} = React
var RefreshableListView = require('react-native-refreshable-listview')

var ArticleStore = require('../stores/ArticleStore')
var StoreWatchMixin = require('./StoreWatchMixin')
var ArticleView = require('./ArticleView')

var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1.id !== r2.id})

var ArticlesScreen = React.createClass({
  mixins: [StoreWatchMixin],
  getInitialState() {
    return {dataSource: ds.cloneWithRows(ArticleStore.all())}
  },
  getStoreWatches() {
    this.watchStore(ArticleStore, () => {
      this.setState({dataSource: ds.cloneWithRows(ArticleStore.all())})
    })
  },
  reloadArticles() {
    return ArticleStore.reload() // returns a promise of reload completion
  },
  renderArticle(article) {
    return <ArticleView article={article} />
  },
  render() {
    return (
      <RefreshableListView
        dataSource={this.state.dataSource}
        renderRow={this.renderArticle}
        loadData={this.reloadArticles}
        refreshDescription="Refreshing articles"
      />
    )
  }
})

Under Construction

I just wrote this... use at your own risk. Not API stable.

About

A pull-to-refresh ListView which shows a loading spinner while your data reloads

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%