| 1 | import type { ComponentProps, ReactNode } from "react"; |
| 2 | import { Pressable, View } from "react-native"; |
| 3 | import { GestureDetector } from "react-native-gesture-handler"; |
| 4 | |
| 5 | import { cn } from "../lib/cn"; |
| 6 | import { useHoverGesture } from "../lib/useHoverGesture"; |
| 7 | |
| 8 | /** Pointer feedback layered over selection. Touch-down may be the start of a scroll. */ |
| 9 | export function RowPressable({ |
| 10 | children, |
| 11 | className, |
| 12 | interactionClassName = "bg-row-hover", |
| 13 | interactionOpacity = 1, |
| 14 | ...props |
| 15 | }: Omit<ComponentProps<typeof Pressable>, "children"> & { |
| 16 | readonly children: ReactNode; |
| 17 | readonly interactionClassName?: string; |
| 18 | readonly interactionOpacity?: number; |
| 19 | }) { |
| 20 | const { hovered, hoverGesture } = useHoverGesture(props.disabled ?? false); |
| 21 | return ( |
| 22 | <GestureDetector gesture={hoverGesture}> |
| 23 | <Pressable {...props} className={cn("relative overflow-hidden", className)}> |
| 24 | {() => ( |
| 25 | <> |
| 26 | <View |
| 27 | pointerEvents="none" |
| 28 | className={cn("absolute inset-0", interactionClassName)} |
| 29 | style={{ opacity: props.disabled || !hovered ? 0 : interactionOpacity }} |
| 30 | /> |
| 31 | {children} |
| 32 | </> |
| 33 | )} |
| 34 | </Pressable> |
| 35 | </GestureDetector> |
| 36 | ); |
| 37 | } |