Giter VIP home page Giter VIP logo

react-pullload's Introduction

Refreshing and Loading more component for react.

pullLoad is another refreshing and loading more lib without react, support require.js to load lib.

examples

demo1 use ReactPullLoad root DOM as container

demo2 use ReactPullLoad root DOM as container

demo3 use document.body as container, and config UI component (HeadNode and FooterNode).

demo4 forbidden pull refresh

version 1.2.0

Support Typescript

Description

  1. Only depend on react/react-dom, without any other package.
  2. Use less.
  3. Support body or root Dom as container.
  4. Bind touch event on component root Dom.
  5. It.s develop as Pure react component.
  6. Support config UI component (HeadNode and FooterNode).
  7. Can apply refreshing or loading through modify STATE.
  8. Only support mobile device

How to use

npm install --save react-pullload
import ReactPullLoad, { STATS } from "react-pullload";
import "node_modules/react-pullload/dist/ReactPullLoad.css";

export class App extends Component {
  constructor() {
    super();
    this.state = {
      hasMore: true,
      data: cData,
      action: STATS.init,
      index: loadMoreLimitNum //loading more test time limit
    };
  }

  handleAction = action => {
    console.info(action, this.state.action, action === this.state.action);
    //new action must do not equel to old action
    if (action === this.state.action) {
      return false;
    }

    if (action === STATS.refreshing) {
      this.handRefreshing();
    } else if (action === STATS.loading) {
      this.handLoadMore();
    } else {
      //DO NOT modify below code
      this.setState({
        action: action
      });
    }
  };

  handRefreshing = () => {
    if (STATS.refreshing === this.state.action) {
      return false;
    }

    setTimeout(() => {
      //refreshing complete
      this.setState({
        data: cData,
        hasMore: true,
        action: STATS.refreshed,
        index: loadMoreLimitNum
      });
    }, 3000);

    this.setState({
      action: STATS.refreshing
    });
  };

  handLoadMore = () => {
    if (STATS.loading === this.state.action) {
      return false;
    }
    //无更多内容则不执行后面逻辑
    if (!this.state.hasMore) {
      return;
    }

    setTimeout(() => {
      if (this.state.index === 0) {
        this.setState({
          action: STATS.reset,
          hasMore: false
        });
      } else {
        this.setState({
          data: [...this.state.data, cData[0], cData[0]],
          action: STATS.reset,
          index: this.state.index - 1
        });
      }
    }, 3000);

    this.setState({
      action: STATS.loading
    });
  };

  render() {
    const { data, hasMore } = this.state;

    const fixHeaderStyle = {
      position: "fixed",
      width: "100%",
      height: "50px",
      color: "#fff",
      lineHeight: "50px",
      backgroundColor: "#e24f37",
      left: 0,
      top: 0,
      textAlign: "center",
      zIndex: 1
    };

    return (
      <div>
        <div style={fixHeaderStyle}>fixed header</div>
        <ReactPullLoad
          downEnough={150}
          action={this.state.action}
          handleAction={this.handleAction}
          hasMore={hasMore}
          style={{ paddingTop: 50 }}
          distanceBottom={1000}
        >
          <ul className="test-ul">
            <button onClick={this.handRefreshing}>refreshing</button>
            <button onClick={this.handLoadMore}>loading more</button>
            {data.map((str, index) => {
              return (
                <li key={index}>
                  <img src={str} alt="" />
                </li>
              );
            })}
          </ul>
        </ReactPullLoad>
      </div>
    );
  }
}

API:

Property Description Type default Remarks
action sync component status string isRequired
handleAction handle status func isRequired
hasMore flag for are there any more content to load bool false
downEnough how long distance is enough to refreshing num 100 use px as unit
distanceBottom current position is apart from bottom num 100 use px as unit
isBlockContainer set root dom as container bool false
HeadNode custom header UI compoent any ReactPullLoad HeadNode must be a react component
FooterNode custom footer UI compoent any ReactPullLoad FooterNode must be a react component

Remarks: ReactPullLoad support set root dom className and style.

STATS list

Property Value root className explain
init '' component initial status
pulling 'pulling' state-pulling pull status
enough 'pulling enough' state-pulling.enough pull down enough status
refreshing 'refreshing' state-refreshing refreshing status fetch data
refreshed 'refreshed' state-refreshed refreshed
reset 'reset' state-reset reset status
loading 'loading' state-loading fetching data

init/reset -> pulling -> enough -> refreshing -> refreshed -> reset

init/reset -> pulling -> reset

init/reset -> loading -> reset

Custom UI components

Please refer to the default HeadNode and FooterNode components

ReactPullLoad HeadNode

ReactPullLoad FooterNode

Or refer to demo3, show different dom style through compare props loaderState width STATS.

demo3

License

MIT

react-pullload's People

Contributors

lidianhao123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-pullload's Issues

请问 我不重写head和footer,是不是有默认的?

我看demo1,您的代码里没有特别加headnode和footernode,但是展示时候有头部和尾部显示文字,但是我在集成时候,写的却没有这部分东西,还有回到顶部需要设置什么,引一些依赖包之类的么?我的一直不起作用,还有get到的值一直是0
image

image
刚刚接触react,有好多东西不太熟悉,还在学习,请大佬帮忙看看...

建议将下拉刷新时候的下移距离做成可设置的

现在这个距离是3rem,建议控件不要用rem作单位,因为独立的第三方控件不应该依赖于(限制住)使用者的html的字体大小,如果使用者设置了很大或者很小的html的font-size,控件在刷新的时候就会变得十分诡异。
建议使用vh这种相对单位,或者可以让用户手动配置

是否可以开放一个滚动监听事件

当滚动条滚动时可以获取到滚动的距离,在列表情况下,滚动一段距离后进入子页面,在返回到页面上是定位不到之前滚动的地方

如何将下拉刷新禁止掉

有些页面不需要下拉刷新, 每次获取数据都会从调出下拉的动画 有什么方法将下拉刷新禁止掉

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.