alibaba/hooks

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

Open

#2861 aperta il 24 set 2025

Vedi su GitHub
 (4 commenti) (1 reazione) (1 assegnatario)TypeScript (2471 fork)batch import
bughelp wanted

Metriche repository

Star
 (12.849 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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;

Guida contributor