0.1.0 • Published 6 months ago

react-pull-to-refreshify v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

自定义百分比动画

English | 简体中文

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

$ npm i react-pull-to-refreshify
# or
$ yarn add react-pull-to-refreshify

Usage

function renderText(pullStatus, percent) {
  switch (pullStatus) {
    case "pulling":
      return (
        <div>
          {`Pull down `}
          <span style={{ color: "green" }}>{`${percent.toFixed(0)}%`}</span>
        </div>
      );

    case "canRelease":
      return "Release";

    case "refreshing":
      return "Loading...";

    case "complete":
      return "Refresh succeed";

    default:
      return "";
  }
}

const [refreshing, setRefreshing] = useState(false);

function handleRefresh() {
  setRefreshing(true);
  setTimeout(() => {
    setRefreshing(false);
  }, 2000);
}

<PullToRefreshify
  refreshing={refreshing}
  onRefresh={handleRefresh}
  renderText={renderText}
>
  {list.map((item, i) => (
    <div key={item.id}>{item}</div>
  ))}
</PullToRefreshify>;

Examples

Props

type PullStatus =
  | "normal"
  | "pulling"
  | "canRelease"
  | "refreshing"
  | "complete";
NameTypeRequiredDefaultDescription
refreshingbooleanfalsetrueWhether to display the refreshing status
onRefresh() => voidtrueFunction called when Refresh Event has been trigerred
renderText(status: PullStatus, percent: number) => React.ReactNodetrueFunction called when Refresh Event has been trigerred
completeDelaynumberfalse500The time for the delay to disappear after completion, the unit is ms
animationDurationnumberfalse300The time for animation duration, the unit is ms
headHeightnumberfalse50The height of the head prompt content area, the unit is px
thresholdnumberfalseConsistent with headHeightHow far to pull down to trigger refresh, unit is px
startDistancenumberfalse30How far to start the pulling status, unit is px
resistancenumberfalse0.6Scale of difficulty to pull down
prefixClsstringfalsepull-to-refreshifyprefix class
disabledbooleanfalsefalseWhether the PullToRefresh is disabled
classNamestringfalse
styleCSSPropertiesfalse
0.1.0

6 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago