1.0.5 • Published 4 years ago

react-pullable v1.0.5

Weekly downloads
1,126
License
MIT
Repository
github
Last release
4 years ago

🙋 React Pullable

Simple, customizable React component for pull to refresh on touch devices.

Play with the demo

GIF

Usage

Install with yarn add react-pullable or npm install react-pullable

Import in your components with import Pullable from 'react-pullable'

Component styles

To prevent Chrome overscroll set overscroll-behavior-y: contain [or] none; on <body> (learn more).

Required props

PropTypeDescription
onRefreshFunctionCalled when a pull is triggered

Optional props

PropTypeDefaultDescription
classNameStringpullableClass applied to the component
centerSpinnerBooleantrueIs the spinner vertically centered or top-aligned?
fadeSpinnerBooleantrueDoes the spinner fade in/out when pulled?
rotateSpinnerBooleantrueDoes the spinner rotate when pulled?
spinnerSizeNumber24Pixel width/height of the spinner
spinnerOffsetNumber0Pixel offset of the spinner (from the top)
spinnerColorString#000000Color of the spinner
spinSpeedNumber1200Time to rotate the spinner 360° (in ms)
popDurationNumber200Time to expand the spinner before it rotates (0 = skip pop)
distThresholdNumberspinnerSize * 3Distance where refresh is triggered
resistanceNumber2.5How hard it is to pull down
refreshDurationNumber1000Time spent spinning before resetting (in ms)
resetDurationNumber400Time to reset (in ms)
resetEaseStringcubic-bezier(0.215, 0.61, 0.355, 1)Ease when resetting
shouldPullToRefreshFunction() => window.scrollY <= 0When to allow pulling
disabledBooleanDisables all functionality

Examples

Using only the required onRefresh prop:

<Pullable onRefresh={() => this.getData()}>
  {this.state.cards.map(card => <Card data={card}/>)}
</Pullable>

Using some optional props:

<Pullable
  onRefresh={() => this.getTasks(currentUser)}
  centerSpinner={false}
  spinnerColor="#FFFFFF"
  disabled={!currentUser}
>
  {this.state.tasks.map(task => <Task data={task}/>)}
</Pullable>

Credits

Inspired by BoxFactura’s PulltoRefresh.js

Spinner SVG from Feather Icons

Built using NWB

Contributing

To test using the included demo app:

  1. Clone the repo
  2. Open the directory and run npm install and npm start
  3. The demo app will update to reflect any changes to it or the component

To test in your own local app:

  1. Clone the repo
  2. Open the directory and run npm install and npm link
  3. Open a directory with a test project and run npm link [package name]
  4. Back in the react-preload-image directory run npm run build