npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rmc-pull-updown-to-refresh

v2.0.4

Published

react pull to refresh react component

Downloads

28

Readme

rmc-pull-updown-to-refresh

An accessible and easy component for ReactJS

简单易用的react拖拉翻页组件

8kb大小, 灵活自由,高度可配置, 支持局部滚动。

Installing

npm

npm i rmc-pull-updown-to-refresh -S

yarn

yarn add rmc-pull-updown-to-refresh

Example repo

git clone https://github.com/eightfeet/rmc-pull-updown-to-refresh.github
cd rmc-pull-updown-to-refresh
npm install
npm run build

cd example npm install
npm run start
import React, { useCallback, useState } from 'react';
import PullToRefresh from 'rmc-pull-updown-to-refresh';

function App() {
    const [list, setList] = useState<number[]>([1,2,3,4,5]);

    const onPullDown = useCallback(
        () =>
            new Promise((res, rej) => {
                setTimeout(() => {
                    rej('暂无数据');
                    setList([]);
                }, 3000);
            }),
        []
    );

    const onPullUp = useCallback(
        () =>
            new Promise((res, rej) => {
                setTimeout(() => {
                    if (list?.length < 30) {
                        setList((data) => {
                            const newData = [...data];
                            for (
                                let index = list.length;
                                index < list.length + 15;
                                index++
                            ) {
                                newData.push(index);
                            }
                            return newData;
                        });
                        res(null);
                    } else {
                        rej('别扯了!这是底线');
                    }
                }, 3000);
            }),
        [list]
    );

    return (
        <div className="App">
            <div className="wrap">
                <PullToRefresh
                    className="list"
                    loadingClassName="background"
                    onPullUp={onPullUp}
                    onPullDown={onPullDown}
                    pullDownText={
                        <div className="pulldowntext">下拉刷新</div>
                    }
                    loadingText={'请稍候'}
                >
                    {list.map((item) => (
                        <div className="item" key={item}>{item}</div>
                    ))}
                    {list.length ? null : <div className='none'>找不到数据</div>}
                </PullToRefresh>
            </div>
        </div>
    );
}

export default App;

Api

interface Props {
    disablePullDown?: boolean; // 禁止下拉
    disablePullUp?: boolean; // 禁止上拉
    pullDownText?: React.ReactNode; // 下拉时展示的文本
    pullUpText?: React.ReactNode; // 上拉时展示的文本
    onPullUp?: () => Promise<any>; // 上拉方法,要求返回promise,reject返回错误信息
    onPullDown?: () => Promise<any>; // 下拉方法,要求返回promise,reject返回错误信息
    className?: string; //样式
    children: React.ReactNode; 
    loadingClassName?: string; // 加载条样式
    loadIcon?: React.ReactNode; // 加载图标
    loadingText?: React.ReactNode; // 加载文本
    pullIcon?: React.ReactNode; // 拉动时方向图标
}

⚠️ 注意

rmc-pull-updown-to-refresh 根据父级高度来定义滚动视窗高度,组件初始化前请定义好父级HTML元素高度,如果获取不到父级HTML元素高度,滚动视窗高度高度将被设置为浏览器窗口高度

事件流 Event flow

Demo