Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC]useSwipeEvent #2541

Open
Inchill opened this issue Apr 29, 2024 · 0 comments
Open

[RFC]useSwipeEvent #2541

Inchill opened this issue Apr 29, 2024 · 0 comments
Labels
feature New feature or request pr welcomed

Comments

@Inchill
Copy link

Inchill commented Apr 29, 2024

用于在移动端监听手势划动,便于处理上下左右划动时对应的操作。

API

interface Options {
    threshold?: number; // 最小划动距离
    maxTime?: number; // 快速划动最长时间
    onSwipeLeft?: (event: TouchEvent) => void;
    onSwipeRight?: (event: TouchEvent) => void;
    onSwipeUp?: (event: TouchEvent) => void;
    onSWipeDown?: (event: TouchEvent) => void;
}

type useSwipeEvent = <T>(options: Options) => T;

Demo

const onSwipeLeft = () => {
    // page change
}
const onSwipeRight = () => {
    // page change
};

useSwipeEvent({
    threshold: 100,
    maxTime: 500,
    onSwipeLeft,
    onSwipeRight
})

使用场景

  1. 从一个列表页进入详情页后,希望可以不返回列表页,就在详情页通过手势划动切换页面。
  2. 纵向滑动翻页,例如年度报告等活动页,可以通过上下划动切换页面。
@liuyib liuyib added feature New feature or request pr welcomed labels Apr 30, 2024
This was referenced May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request pr welcomed
Projects
None yet
Development

No branches or pull requests

2 participants