about summary refs log tree commit diff
path: root/src/view/com/util/PressableWithHover.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/com/util/PressableWithHover.tsx')
-rw-r--r--src/view/com/util/PressableWithHover.tsx46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/view/com/util/PressableWithHover.tsx b/src/view/com/util/PressableWithHover.tsx
index 77276f184..48659e229 100644
--- a/src/view/com/util/PressableWithHover.tsx
+++ b/src/view/com/util/PressableWithHover.tsx
@@ -1,39 +1,35 @@
-import React, {
-  useState,
-  useCallback,
-  PropsWithChildren,
-  forwardRef,
-  Ref,
-} from 'react'
+import React, {forwardRef, PropsWithChildren} from 'react'
 import {Pressable, PressableProps, StyleProp, ViewStyle} from 'react-native'
-import {addStyle} from 'lib/styles'
+import {View} from 'react-native'
+
+import {addStyle} from '#/lib/styles'
+import {useInteractionState} from '#/components/hooks/useInteractionState'
 
 interface PressableWithHover extends PressableProps {
   hoverStyle: StyleProp<ViewStyle>
 }
 
-export const PressableWithHover = forwardRef(function PressableWithHoverImpl(
-  {
-    children,
-    style,
-    hoverStyle,
-    ...props
-  }: PropsWithChildren<PressableWithHover>,
-  ref: Ref<any>,
+export const PressableWithHover = forwardRef<
+  View,
+  PropsWithChildren<PressableWithHover>
+>(function PressableWithHoverImpl(
+  {children, style, hoverStyle, ...props},
+  ref,
 ) {
-  const [isHovering, setIsHovering] = useState(false)
-
-  const onHoverIn = useCallback(() => setIsHovering(true), [setIsHovering])
-  const onHoverOut = useCallback(() => setIsHovering(false), [setIsHovering])
-  style =
-    typeof style !== 'function' && isHovering
-      ? addStyle(style, hoverStyle)
-      : style
+  const {
+    state: hovered,
+    onIn: onHoverIn,
+    onOut: onHoverOut,
+  } = useInteractionState()
 
   return (
     <Pressable
       {...props}
-      style={style}
+      style={
+        typeof style !== 'function' && hovered
+          ? addStyle(style, hoverStyle)
+          : style
+      }
       onHoverIn={onHoverIn}
       onHoverOut={onHoverOut}
       ref={ref}>