diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-09-23 16:35:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-23 16:35:16 +0100 |
commit | 443f3a64069f081764c2f49578108a9570e8e834 (patch) | |
tree | af11a88a6772d33cc202503e05e478312a39ab46 /src/view/com/util/PressableWithHover.tsx | |
parent | 5e333d4dfcc434f76fd54def2f965f54e112257b (diff) | |
download | voidsky-443f3a64069f081764c2f49578108a9570e8e834.tar.zst |
Use pressable for video controls (#5452)
* use pressable for video controls * add `as any` to preexisiting bad type * stop mutating prop
Diffstat (limited to 'src/view/com/util/PressableWithHover.tsx')
-rw-r--r-- | src/view/com/util/PressableWithHover.tsx | 46 |
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}> |