Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

useHoverGesture.ts

25 lines841 Bytes

1import { useMemo, useState } from "react";
2import { Gesture, PointerType } from "react-native-gesture-handler";
3​
4export function useHoverGesture(disabled = false) {
5 const [hovered, setHovered] = useState(false);
6 const hoverGesture = useMemo(
7 () =>
8 // oxlint-disable-next-line react/capitalized-calls -- Gesture.Hover is a gesture factory, not a React component.
9 Gesture.Hover()
10 .manualActivation(true)
11 .enabled(!disabled)
12 .cancelsTouchesInView(false)
13 .runOnJS(true)
14 .onBegin((event) => {
15 setHovered(
16 event.pointerType === PointerType.MOUSE || event.pointerType === PointerType.STYLUS,
17 );
18 })
19 .onFinalize(() => {
20 setHovered(false);
21 }),
22 [disabled],
23 );
24 return { hovered: !disabled && hovered, hoverGesture };