mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React, {
2 useState,
3 useCallback,
4 PropsWithChildren,
5 forwardRef,
6 Ref,
7} from 'react'
8import {Pressable, PressableProps, StyleProp, ViewStyle} from 'react-native'
9import {addStyle} from 'lib/styles'
10
11interface PressableWithHover extends PressableProps {
12 hoverStyle: StyleProp<ViewStyle>
13}
14
15export const PressableWithHover = forwardRef(function PressableWithHoverImpl(
16 {
17 children,
18 style,
19 hoverStyle,
20 ...props
21 }: PropsWithChildren<PressableWithHover>,
22 ref: Ref<any>,
23) {
24 const [isHovering, setIsHovering] = useState(false)
25
26 const onHoverIn = useCallback(() => setIsHovering(true), [setIsHovering])
27 const onHoverOut = useCallback(() => setIsHovering(false), [setIsHovering])
28 style =
29 typeof style !== 'function' && isHovering
30 ? addStyle(style, hoverStyle)
31 : style
32
33 return (
34 <Pressable
35 {...props}
36 style={style}
37 onHoverIn={onHoverIn}
38 onHoverOut={onHoverOut}
39 ref={ref}>
40 {children}
41 </Pressable>
42 )
43})