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

react-touch-swiper-container

v1.0.2

Published

A react touch swiper mobile component

Downloads

10

Readme

React-Touch-Swiper-Container

一个用于react的滑动切换库

HomePage

https://kawayilinlin.github.io/react-touch-swiper-container/

示例 Example

  • 在线示例 Online Example

View in mobile browser:https://kawayilinlin.github.io/react-touch-swiper-container/examples/touch-swiper-container.html

  • 安装
npm install react-touch-swiper-container -S
  • 使用
import React, { useState } from "react";
import ReactDOM from "react-dom";

import TouchSwiperContainer, { useTouchSwiperPage } from "react-touch-swiper-container";

const createPage = () => {
  const start = -100000;
  const end = start * -1;

  const result = [];
  for (let i = start; i < end; i++) {
    result.push({
      id: i,
      name: i,
    });
  }
  return result;
};

const TouchSwiperContainerDemo: React.FC = () => {
  const [myPage] = useState(createPage);
  const { pages, handleAnimationEndChange, getPage } = useTouchSwiperPage(
    myPage,
    "id"
  );

  const [isShowBackground, setIsShow] = useState(false)

  return (
    <div className={isShowBackground ? 'show-background' : undefined} style={{ width: "100%", height: "100%" }}>
      <button onClick={() => setIsShow(!isShowBackground)}>切换展示背景颜色</button>
      <TouchSwiperContainer
        onAnimationEnd={handleAnimationEndChange}
        pages={pages}
      >
        {(id) => {
          return (
            <div
              style={{
                fontSize: 50,
                fontWeight: 700,
                textAlign: "center",
                lineHeight: "170px",
              }}
            >
              {getPage(id)?.name}
            </div>
          );
        }}
      </TouchSwiperContainer>
    </div>
  );
};

ReactDOM.render(
  <TouchSwiperContainerDemo />,
  document.getElementById("app")
);

参数 Props

| 参数名 prop name | 类型 type | 默认值 default | 说明 description | | ---------------- | ----------------------------------------- | -------------- | ------------------------------------------------------------ | | hideWhenNotReady | boolean | true | 组件在自动计算容器宽度后,才可使用,在这之前,你可以设置它为隐藏 | | animationTime | number | 100 | 当手指释放后,组件由当前页面过渡到下(上)一个页面所需要的时间 | | pages | number[] | [0, 1, 2] | 组件需要你提供一个长度的3的数组,用于渲染页面,组件一次最多只会在视图中渲染3个页面,即使你有很多个页面 | | onAnimationEnd | (next: number) => void | | 切换页面的动画结束后触发,你应该在这个回调中设置下一个需要展示的页面 | | onReady | () => void | | 组件计算完容器宽高后,在下一个宏任务中触发 | | onChange | (next: number) => void | | 手指释放后,检测到将要切换到上一页或下一页就会立即触发 | | children | (item: number | null) => React.ReactNode | | 需要给组件提供一个函数,并返回需要渲染在视图中的内容 |

工具 tools

  • useTouchSwiperPage

    组件仅接受三个页面的id,但你可能有很多页面,因此,你可以使用该 hook,传入你的所有页面,和id对应的键名,得到需要传递给组件的三个页面