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