alibaba/hooks

`useLongPress` 在 macOS 的 Tauri 应用中无法生效。

Open

#2,861 opened on Sep 24, 2025

View on GitHub
 (4 comments) (1 reaction) (1 assignee)TypeScript (2,471 forks)batch import
bughelp wanted

Repository metrics

Stars
 (12,849 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

https://github.com/user-attachments/assets/49616b1f-d4cf-48f8-b479-7b01e68ccbd6

import { convertFileSrc } from "@tauri-apps/api/core";
import { openPath } from "@tauri-apps/plugin-opener";
import { useLongPress } from "ahooks";
import { type FC, useRef } from "react";
import type { App as AppProps } from "@/stores/app";
import { hidePanel } from "@/utils/nsPanel";

const App: FC<AppProps> = (props) => {
  const { name, icon, path } = props;
  const containerRef = useRef<HTMLDivElement>(null);

  const handleLongPress = () => {
    console.log("handleLongPress");
  };

  const openApp = () => {
    console.log("openApp");

    openPath(path);

    hidePanel();
  };

  useLongPress(handleLongPress, containerRef, {
    onClick: openApp,
  });

  return (
    <div
      className="grid place-items-center active:opacity-70"
      ref={containerRef}
    >
      <img alt={name} className="size-24" src={convertFileSrc(icon)} />

      <span className="truncate">{name}</span>
    </div>
  );
};

export default App;

Contributor guide