GithubHelp home page GithubHelp logo

minhuaf / reactrefreshinfinitetableview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from calvinchankf/reactrefreshinfinitetableview

0.0 1.0 0.0 326 KB

A Subclass-able React Component to make your table ViewPull-To-Refresh and Infinite in just a minute

Home Page: https://goo.gl/xi2R26

JavaScript 94.57% CSS 3.16% HTML 2.27%

reactrefreshinfinitetableview's Introduction

Thank you guys so much for all your support. The project has been discontinued. Instead, I will make another one with better performance on both desktop and mobile

React-Refresh-Infinite-TableView

npm version npm downloads


demo

Features ๐Ÿ‘€

  • Pull to Refresh
  • Pull to Load More
  • Fully Customizable Loading Indicator
  • Subclass-able React Component

How to Install ๐Ÿ˜?

  1. via npm install
npm install --save react-refresh-infinite-tableview
  1. or manually
  • extract the rri.js and spinner.css from lib/, and use them in your projects.

How to Use ๐Ÿค”?

  • You can use it with default spinners or your custom spinners
  • Below are some setups, if you are looking for detail, please take a look at /examples
import ReactRefreshInfiniteTableView from 'react-refresh-infinite-tableview'
  • Use Default Spinners

    • subclass the ReactRefreshInfiniteTableView
    class ExampleTableView extends ReactRefreshInfiniteTableView {
      //...
    }
  • attach an scroll event listener to your scrollview

<div className="tableView" onScroll={this.viewDidScroll}>
  • set props to your tableview component
<ExampleTableView dataSource={this.state.data} onScrollToTop={this.handleScrollToTop} onScrollToBottom={this.handleScrollToBottom}
/>
  • handle scroll events
// handle onScrollToTop
handleScrollToTop(completed) {
  // refresh data
  // ...

  // once received data
  completed()
  this.setState({data: newData})
}

// handle onScrollToBottom
handleScrollToBottom(completed) {
  // load more data
  // ...

  // once received data
  completed()
  this.setState({data1: newData})
}
  • see ExampleTableView1 for details

  • Use your own loading indicators

    • first, you need to follow the basic set up as the above(use default spinner)
    • set useDefaultIndicator to false for your component
    useDefaultIndicator={false}
    • construct your own indicators with jsx
    // customize your Refresh Indicator here
    refreshIndicator() {
      if (this.state.isRefreshing) {
        return (
          <div className="list-group-item text-center indicator">๐Ÿƒ...</div>
        )
      }
      return
    }
    // customize your Load-more Indicator here
    loadMoreIndicator() {
      if (this.state.isLoadingMore) {
        return (
          <div className="list-group-item text-center indicator">...๐Ÿƒ</div>
        )
      }
      return
    }
    • render your indicators with your tableview
    <div className="tableView" onScroll={this.viewDidScroll}>
      {this.refreshIndicator()}
      {cells}
      {this.loadMoreIndicator()}
    </div>
    • see ExampleTableView2 for details
  • You can also disable the scrollToTop or scrollToBottom by just by just not setting the props.

<ExampleTableView dataSource={this.state.data} onScrollToBottom={this.handleScrollToBottom} />

TODO:

  • Customizable default spinner
  • Trigger scroll-to-top event when pull down if the tableview is already at the top

Demo ๐Ÿ˜ฎ

  • Run the demo with
npm install
npm start

then go to http://localhost:3000/

  • P.S. In the demo, you may notice that the page will auto-refresh after you change the code because the demo is based on my another repo React-SPA-Starter, which is a very handy starter-kit for react dev.

reactrefreshinfinitetableview's People

Contributors

calvinchankf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.