• Stars
    star
    1,384
  • Rank 33,956 (Top 0.7 %)
  • Language
    JavaScript
  • Created over 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

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

React Native RefreshableListView

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

Deprecated: now you can use the built-in RefreshControl instead.

Build Status

In action (from ReactNativeHackerNews):

React Native Hacker News

Usage

Note: these are the docs for the 2.x branch, currently in beta. If you are looking for the docs for a 1.x version, see the 1.x branch.

You can install the latest beta with npm install react-native-refreshable-listview@next

RefreshableListView

Replace a ListView with a RefreshableListView to add pulldown-to-refresh functionality. Accepts the same props as ListView, plus a few extras (see the props definitions below).

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 !== r2}) // assumes immutable objects

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() {
    // returns a Promise of reload completion
    // for a Promise-free version see ControlledRefreshableListView below
    return ArticleStore.reload()
  },
  renderArticle(article) {
    return <ArticleView article={article} />
  },
  render() {
    return (
      <RefreshableListView
        dataSource={this.state.dataSource}
        renderRow={this.renderArticle}
        loadData={this.reloadArticles}
        refreshDescription="Refreshing articles"
      />
    )
  }
})

Props

  • loadData: func.isRequired A function returning a Promise or taking a callback, invoked upon pulldown. The refreshing indicator (spinner) will show until the Promise resolves or the callback is called.
  • refreshDescription: oneOfType([string, element]) Text/element to show alongside spinner. If a custom refreshingIndicatorComponent is used this value will be passed as its description prop.
  • refreshingIndicatorComponent: oneOfType([func, element]) Content to show in list header when refreshing. Can be a component class or instantiated element. Defaults to RefreshableListView.RefreshingIndicator. You can easily customise the appearance of the indicator by passing in a customised <RefreshableListView.RefreshingIndicator />, or provide your own entirely custom content to be displayed.
  • minDisplayTime: number Minimum time the spinner will show for.
  • minBetweenTime: number Minimum time after a refresh before another refresh can be performed.
  • minPulldownDistance: number Minimum distance (in px) which the list has to be scrolled off the top to trigger a refresh.
  • ignoreInertialScroll: bool Require the user to be actually touching the screen when the pulldown distance exceeds minPulldownDistance to trigger a refresh (eg. not just inertially scrolling off the top). Defaults to true.
  • onScroll: func An event handler for the onScroll event which will be chained after the one defined by the RefreshableListView.
  • scrollEventThrottle: number How often ListView produces scroll events, in ms. Defaults to a fairly low value, try setting it higher if you encounter performance issues. Keep in mind that a higher value will make the pulldown-to-refresh behaviour less responsive.
  • colors: array of strings Colors to be used for pull to refresh indicator in Android
  • progressBackgroundColor: string Color to be used for pull to refresh indicator background in Android

ControlledRefreshableListView

Low level component used by RefreshableListView. Use this directly if you want to manually control the refreshing status (rather than using a Promise).

This component is more suitable for use in a Redux-style connected component.

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

var ArticleView = require('./ArticleView')

var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}) // assumes immutable objects

var ArticlesScreen = React.createClass({
  propTypes: {
    // eg. props mapped from store state
    articles: React.PropTypes.array.isRequired,
    isRefreshingArticles: React.PropTypes.bool.isRequired,
    // eg. a bound action creator
    refreshArticles: React.PropTypes.func.isRequired,
  },
  getInitialState() {
    return {dataSource: ds.cloneWithRows(this.props.articles)}
  },
  componentWillReceiveProps(nextProps) {
    if (this.props.articles !== nextProps.articles) {
      this.setState({dataSource: ds.cloneWithRows(nextProps.articles)})
    }
  },
  renderArticle(article) {
    return <ArticleView article={article} />
  },
  render() {
    return (
      <ControlledRefreshableListView
        dataSource={this.state.dataSource}
        renderRow={this.renderArticle}
        isRefreshing={this.props.isRefreshingArticles}
        onRefresh={this.props.refreshArticles}
        refreshDescription="Refreshing articles"
      />
    )
  }
})

Props

  • onRefresh: func.isRequired Called when user pulls listview down to refresh.
  • isRefreshing: bool.isRequired Whether or not to show the refreshing indicator.
  • refreshDescription: oneOfType([string, element]) See RefreshableListView
  • refreshingIndicatorComponent: oneOfType([func, element]) See RefreshableListView
  • minPulldownDistance: number See RefreshableListView
  • ignoreInertialScroll: bool See RefreshableListView
  • onScroll: func See RefreshableListView
  • scrollEventThrottle: number See RefreshableListView

RefreshableListView.RefreshingIndicator

Component with activity indicator to be displayed in list header when refreshing. (also exposed as ControlledRefreshableListView.RefreshingIndicator)

Props

  • description: oneOfType([string, element]) Text/element to show alongside spinner.
  • stylesheet: object A stylesheet object which overrides one or more of the styles defined in the RefreshingIndicator stylesheet.
  • activityIndicatorComponent: oneOfType([func, element]) The spinner to display. Defaults to <ActivityIndicatorIOS />.

RefreshableListView.DataSource, ControlledRefreshableListView.DataSource

Aliases of ListView.DataSource, for convenience.

Howto

Customise the refresh indicator (spinner)

Your first option is to style the default RefreshingIndicator:

var indicatorStylesheet = StyleSheet.create({
  wrapper: {
    backgroundColor: 'red',
    height: 60,
    marginTop: 10,
  },
  content: {
    backgroundColor: 'blue',
    marginTop: 10,
    height: 60,
  },
})

<RefreshableListView
  refreshingIndicatorComponent={
    <RefreshableListView.RefreshingIndicator stylesheet={indicatorStylesheet} />
  }
/>

Alternatively, you can provide a custom RefreshingIndicator:

var MyRefreshingIndicator = React.createClass({
  render() {
    return (
      <View>
        <MySpinner />
        <Text>{this.props.description}</Text>
      </View>
    )
  },
})

<RefreshableListView refreshingIndicatorComponent={MyRefreshingIndicator} />
// or
<RefreshableListView refreshingIndicatorComponent={<MyRefreshingIndicator />} />

Changelog

  • 2.0.0-beta4

    • added Android support! (@maraujop)
  • 2.0.0-beta3

    • fixed proptype warnings from internal component
    • adjusted default styling of refreshing indicator
  • 2.0.0-beta2

    • pulling down now reveals refreshing indicator behind current view, rather than the refreshing indicator moving down from the top of the screen
    • renderHeaderWrapper is no longer used
    • fixed infinite refreshing when pulled down
  • 1.2.0

    • deprecated renderHeader in favour of renderHeaderWrapper as some developers seemed to be confused by the fact that a renderHeader handler for a standard ListView will not automatically just work with this component, but rather needs to be modified as described in the documentation. The new prop renderHeaderWrapper works identically to the previous one, however hopefully now it is named differently it will be more apparent that its behaviour is not the same as with ListView. The renderHeader prop will be removed in 2.0.
  • 1.1.0

    • added behaviour to ignore inertial scrolling (@dhrrgn)
    • exposed props: ignoreInertialScroll, scrollEventThrottle
  • 1.0.0

    • Split RefreshableListView into 3 parts:
      • RefreshableListView handles 'refreshing' state by invoking 'loadData' callback and waiting for resolution.
      • ControlledRefreshableListView handles rendering of ListView header, depending on isRefreshing prop. Calls onRefresh handler when pulldown-to-refresh scroll motion occurs.
      • RefreshingIndicator is the component rendered in the header of the ListView when refreshing. Pass in a customised version of this (or a completely different component) to RefreshableListView or ControlledRefreshableListView if you want to customise refresh indicator appearance.
    • Added Jest unit tests
  • 0.3.0 added minPulldownTime & minBetweenTime props, fixed bug where refresh could happen twice

  • 0.2.0 added support for ListView props setNativeProps and getScrollResponder (@almost & @sscotth)

More Repositories

1

react-native-htmlview

A React Native component which renders HTML content as native views
JavaScript
2,710
star
2

little-virtual-computer

Learn how computers work by simulating them in Javascript
JavaScript
854
star
3

pce

Emulates Mac Plus, PC, & Atari ST in the browser using WebAssembly
C
829
star
4

coffee-react-transform

DEPRECATED โ€“ย Provides React JSX support for Coffeescript
CoffeeScript
433
star
5

coffee-react

DEPRECATED โ€“ย Unfancy JavaScript with React JSX markup
CoffeeScript
413
star
6

ReactNativeHackerNews

React Native Hacker News app
JavaScript
256
star
7

browserify-incremental

incremental rebuild for browserify
JavaScript
175
star
8

webpack-combine-loaders

Combine an array of webpack loaders into a loader string
JavaScript
105
star
9

react-ratchet

React components for the Ratchet mobile app UI library
JavaScript
86
star
10

sprockets-coffee-react

DEPRECATED โ€“ย Sprockets preprocessor for CJSX (Coffeescript with React JSX markup)
Ruby
85
star
11

react-layout

Dynamic subview layout for React
CoffeeScript
83
star
12

goose64

untitled goose game demake for nintendo 64
C++
78
star
13

n64-sdk-demo

n64 homebrew demo app
Objective-C
66
star
14

github-reason-react-tutorial

OCaml
39
star
15

react-commits-graph

react component to render an svg graph of git commits
CoffeeScript
37
star
16

react-form-for

An expressive and intuitive form builder for React in the style of Rails' form_for
JavaScript
37
star
17

deep-freeze

recursively Object.freeze() on objects and functions
JavaScript
32
star
18

hacker-news-mobile

Hacker News mobile web app built in 'Isomorphic' React
JavaScript
27
star
19

lisp.rs

Scheme Interpreter in Rust
Rust
25
star
20

ed64log

printf() and error stacktraces for n64 sdk-based homebrew games running on everdrive64 flashcarts
C
19
star
21

only-if-changed-webpack-plugin

Webpack plugin to only run build if dependent files have changed
JavaScript
18
star
22

flux-coffee

Implements Facebook's Flux pattern in CoffeeScript
CoffeeScript
16
star
23

lisp.re

A LISP interpreter written in ReasonML, targeting native and browser environments
OCaml
16
star
24

inspect-react-element

Prettyprints ReactElements and their children
JavaScript
16
star
25

reason-routing-tutorial

A tutorial for routing in Reason React
JavaScript
15
star
26

applescript-raytracer

a raytracer written in applescript
AppleScript
14
star
27

hacker-news-mobile-api

Turns official Hacker News Firebase API into a REST JSON API
JavaScript
14
star
28

duktape64

javascript on nintendo 64
C
12
star
29

cjsx-codemod

A codemod for migrating off of coffee-react CJSX
JavaScript
11
star
30

strictify

browserify v2 plugin for enforcing strict mode
JavaScript
11
star
31

BussIK-js

Selectively Damped Least Squares for Inverse Kinematics, in JavaScript
JavaScript
11
star
32

find-index

finds an item in an array matching a predicate function, and returns its index
JavaScript
11
star
33

n64soundtools

tools for compiling sound and music data for n64 sdk homebrew games
JavaScript
11
star
34

hacker-news-serverless-api

A hacker news API published as JSON files on S3 by an AWS Lambda function
JavaScript
10
star
35

loader64

USB uploader tool for Everdrive64
C
10
star
36

browserify-cache-api

JavaScript
10
star
37

webpack_rails

DEPRECATED โ€“ย Integrates Webpack with Rails/Sprockets
Ruby
9
star
38

traceviewer

simple traceviewer renderer
JavaScript
7
star
39

webserial-ed64log

connect to an everdrive 64 from your web browser
JavaScript
6
star
40

oky

An okayish framework for mobile apps with Backbone.
JavaScript
6
star
41

they-live

serverless server monitoring with near-zero running costs
JavaScript
5
star
42

perv

A tool to watch your filesystem and display logged activity via a web interface. Originally created to assist with time tracking.
JavaScript
5
star
43

nvm_auto

automatically `nvm use` when entering a directory with an .nvmrc
Shell
5
star
44

robot-control

3d web ui to simulate and control a robotic arm
JavaScript
4
star
45

cached-loader

DEPRECATED. Adds persistent on-disk caching to webpack loaders
JavaScript
4
star
46

n64-gameoflife

conway's game of life on n64
C
4
star
47

theunarchiver

Automatically exported from code.google.com/p/theunarchiver
C
4
star
48

jamesfriend.com.au

my website
JavaScript
3
star
49

jest-alias-module-loader

JavaScript
3
star
50

rinsefm-feed

Generates iTunes-compatible podcast feeds of Rinse FM via scraping
CoffeeScript
3
star
51

pcejs-embed

easily embed a pcejs emulator anywhere
JavaScript
3
star
52

cosmos

reactjs based cms
CoffeeScript
3
star
53

podcastgen

generate itunes-compatible podcasts from cson or json
CoffeeScript
3
star
54

ruby_node_task

Run node.js scripts from Ruby with a persistent worker
Ruby
3
star
55

bit-packing-explorer

play around with storing multiple pieces of data in a single number value using bit packing
JavaScript
2
star
56

css-modules-loader-core-sync

synchronous version of css-modules-loader-core
JavaScript
2
star
57

minivmac

Browser port of Mini vMac classic mac emulator (and repo mirror)
C
2
star
58

exif2csv

Mac app for dumping image EXIF data to a CSV
Python
2
star
59

aiff-explorer

visualize the contents of an AIFF file
JavaScript
2
star
60

bantam

super lightweight python game engine
Python
1
star
61

fridgemagnets

Realtime alphabet fridgemagnets node.js/browser demo
JavaScript
1
star
62

jspace

space shooter written with only built-in java stuff
Java
1
star
63

spaaaace

love2d game
Lua
1
star
64

scaletoy

chord palette with webmidi output
TypeScript
1
star
65

ReasonPhysics

simple physics simulation for reasonml
OCaml
1
star
66

webaudio

JavaScript
1
star
67

jsdf

github pages
1
star
68

melb-react-animation-talk

JavaScript
1
star
69

robot-arm

robot arm based on the Adafruit PCA9685 board
Python
1
star
70

planetarium

a beat-synced music visualization which controls rgb led strips via bluetooth
JavaScript
1
star