Skip to content

Commit

Permalink
feat: FingerProxy 的 target 新增支持 "nearest" | "farthest"
Browse files Browse the repository at this point in the history
  • Loading branch information
Houfeng committed Nov 26, 2024
1 parent f0cd252 commit 26da052
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-finger",
"version": "2.2.7",
"version": "2.3.0",
"description": "React Finger is a library of gesture events for React that allows developers to use a single set of events for both desktop and mobile devices.",
"keywords": [
"Gesture",
Expand Down
10 changes: 6 additions & 4 deletions src/helpers/FingerProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function toNativeEventName(name: string) {
return name.slice(2).toLocaleLowerCase();
}

function createDOMTarget(node: EventTarget): FingerProxyEventTarget | undefined {
function createDOMTarget(
node: EventTarget
): FingerProxyEventTarget | undefined {
const addEventListener = (e: string, f: AnyFunction, o: unknown) => {
const name = toNativeEventName(e);
node.addEventListener(name, f, o);
Expand All @@ -62,8 +64,8 @@ function createDOMTarget(node: EventTarget): FingerProxyEventTarget | undefined
return { addEventListener, removeEventListener };
}

const GlobalTarget = typeof document !== 'undefined'
? createDOMTarget(document) : void 0;
const GlobalTarget =
typeof document !== "undefined" ? createDOMTarget(document) : void 0;

const FingerProxyContext = createContext<FingerProxyEventTarget>(null);

Expand Down Expand Up @@ -103,7 +105,7 @@ export const FingerProxy = memo(function FingerProxy(props: FingerProxyProps) {
// * 当使用 useFingerEvents 返回结果再作为属性用于 FingerProxy 时,
// * 在 Provider 中的 handle 方法看起来会进入两次,是因为经历了两次 compose
// * 在 FingerProxy 上直接使用事件,便不会两次。此外,进入两次并不会产生问题。
const { target = 'nearest', passive = true, ...others } = props;
const { target = "nearest", passive = true, ...others } = props;
const normalizeTarget = useFingerProxyTarget(target);
const events = useFingerEvents(others);
useLayoutEffect(() => {
Expand Down

0 comments on commit 26da052

Please sign in to comment.