# ridingwind-scrolllist

> pull-up load more drop-down refresh on mobile, AND scroll load more on PC, React Compopnent

Latest version **0.0.4** (published 2020-10-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install ridingwind-scrolllist
pnpm add ridingwind-scrolllist
yarn add ridingwind-scrolllist
bun add ridingwind-scrolllist
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2020-10-23 |
| First published | 2019-01-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 36.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | RidingWind |
| Maintainers | ridingwind |
| Keywords | react, scroll, PC, mobile, pull up, refresh, drop down, load more |

## Links

- npm: https://www.npmjs.com/package/ridingwind-scrolllist
- Repository: https://github.com/LinQinTao/ridingwind-scrolllist
- Homepage: https://github.com/LinQinTao/ridingwind-scrolllist#readme
- Issues: https://github.com/LinQinTao/ridingwind-scrolllist/issues
- npm.io page: https://npm.io/package/ridingwind-scrolllist

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^16.0.0
- [react-dom](https://npm.io/package/react-dom.md) ^16.0.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.4 (latest) — 2020-10-23
- 0.0.3 — 2019-07-03
- 0.0.2 — 2019-01-08
- 0.0.1 — 2019-01-06
- 0.0.1-alpha.1 — 2019-01-06
- 1.0.0-alpha.1 — 2019-01-05

## README

# [ridingwind scrolllist](https://github.com/LinQinTao/ridingwind-scrolllist.git)

# 当前版本 0.0.4

# 简介
1. React插件
2. 只依赖 react/react-dom
3. 支持代码动态调起刷新和加载更多（组件将展示刷新和加载更多样式）
4. **支持移动触摸设备（上拉加载，下拉刷新），PC设备滚动加载更多**

# 使用说明

1. 安装

```sh
npm install --save ridingwind-scrolllist
```

2. demo

```js
import { RidingWindScrollList, RSTATES } from 'ridingwind-scrolllist';

class Demo extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      hasMore: true,
      currentState: RSTATES.init,
      datas: new Array(15).fill('-'), // 测试代码
      index: 5, // 测试代码
    };
  }

  executeFunc = (currentState) => {
    if (currentState === this.state.currentState) {
      return false;
    }

    if (currentState === RSTATES.refreshing) {
      // 刷新
      this.handRefreshing();
    } else if (currentState === RSTATES.loading) {
      // 加载更多
      this.handLoadMore();
    } else {
      this.setState({
        currentState,
      });
    }
  };

  handRefreshing = () => {
    if (RSTATES.refreshing === this.state.currentState) {
      return false;
    }

    setTimeout(() => {
      this.setState({
        hasMore: true,
        currentState: RSTATES.refreshed,
      });
    }, 3000);

    this.setState({
      currentState: RSTATES.refreshing,
    });
  };

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

    setTimeout(() => {
      if (this.state.index === 0) {
        // 测试代码
        this.setState({
          currentState: RSTATES.reset, // 必须
          hasMore: false,
        });
      } else {
        this.setState({
          datas: this.state.datas.concat(new Array(15).fill('-')), // 测试代码
          currentState: RSTATES.reset, // 必须
          index: this.state.index - 1, // 测试代码
        });
      }
    }, 3000);

    this.setState({
      currentState: RSTATES.loading,
    });
  };

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

    return (
      <div>
        <RidingWindScrollList
          id="list"
          pullDownSpace={80}
          actionSpaceBottom={300}
          currentState={currentState}
          hasMore={hasMore}
          executeFunc={this.executeFunc}
          FooterTipDOM={(<div />)}
        >
          {
            datas.map((item, index) => (
              <div
                key={index}
                className={styles.item}
              >
                <div className={styles.itemText}>
                  <div className={styles.itemTextTit}>
                    {index}: {item}国家税务总局：要将税收工作重大决策部署落实到位
                    国家税务总局：要将税收工作重大决策部署落实到位
                  </div>
                  <div className={styles.itemTextInfo}>新浪财经</div>
                </div>
              </div>
            ))
          }
        </RidingWindScrollList>
      </div>
    );
  }
}

export default Demo;

```

# 参数说明：

| 参数             | 说明                                          | 类型   | 备注                  |
| ---------------- | --------------------------------------------- | ------ | --------------------- |
| id           | id                                  | String | isRequired            |
| currentState     | 当前状态                                  | String   | isRequired            |
| executeFunc          | 执行的方法                        | func   |            isRequired           |
| hasMore          | 是否还有更多内容可以加载                | Boolean   |            isRequired           |
| pullDownSpace       | 下拉距离是否满足要求                 | Number    |      isRequired                 |
| actionSpaceBottom   | 距离底部多少距离触发加载更多                  | Number    |       isRequired        |
| FooterTipDOM   | 底部提示信息                 | Dom    |       noRequired        |


# STATS list

| 属性       | 值               | 说明                 |
| ---------- | ---------------- | -------------------- |
| init       | ''               | 组件初始状态         |
| pulling    | 'pulling'        | 下拉状态             |
| enough     | 'pullingenough' | 下拉并且已经满足阈值 |
| refreshing | 'refreshing'     | 刷新中（加载数据中） |
| refreshed  | 'refreshed'      | 完成刷新动作         |
| reset      | 'reset'          | 恢复默认状态         |
| loading    | 'loading'        | 加载中               |

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

init/reset -> pulling -> reset

init/reset -> loading -> reset

---
_Source: https://npm.io/package/ridingwind-scrolllist · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
