Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ForwardedRef} from 'react';
import React, {forwardRef, useCallback, useEffect, useMemo} from 'react';
import React, {forwardRef, useCallback, useEffect, useMemo, useState} from 'react';
import type {GestureResponderEvent, View} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import {Pressable} from 'react-native';
Expand Down Expand Up @@ -45,6 +45,7 @@ function GenericPressable(
const {isExecuting, singleExecution} = useSingleExecution();
const isScreenReaderActive = Accessibility.useScreenReaderStatus();
const [hitSlop, onLayout] = Accessibility.useAutoHitSlop();
const [isHovered, setIsHovered] = useState(false);

const isDisabled = useMemo(() => {
let shouldBeDisabledByScreenReader = false;
Expand Down Expand Up @@ -153,7 +154,7 @@ function GenericPressable(
StyleUtils.parseStyleFromFunction(style, state),
isScreenReaderActive && StyleUtils.parseStyleFromFunction(screenReaderActiveStyle, state),
state.focused && StyleUtils.parseStyleFromFunction(focusStyle, state),
state.hovered && StyleUtils.parseStyleFromFunction(hoverStyle, state),
(state.hovered || isHovered) && StyleUtils.parseStyleFromFunction(hoverStyle, state),
state.pressed && StyleUtils.parseStyleFromFunction(pressStyle, state),
isDisabled && [StyleUtils.parseStyleFromFunction(disabledStyle, state), styles.noSelect],
]}
Expand All @@ -170,8 +171,23 @@ function GenericPressable(
accessible={accessible}
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
onHoverOut={(event) => {
if (event?.type === 'pointerenter' || event?.type === 'mouseenter') {
return;
}
setIsHovered(false);
if (rest.onHoverOut) {
rest.onHoverOut(event);
}
}}
onHoverIn={(event) => {
setIsHovered(true);
if (rest.onHoverIn) {
rest.onHoverIn(event);
}
}}
>
{(state) => (typeof children === 'function' ? children({...state, isScreenReaderActive, isDisabled}) : children)}
{(state) => (typeof children === 'function' ? children({...state, isScreenReaderActive, hovered: state.hovered || isHovered, isDisabled}) : children)}
</Pressable>
);
}
Expand Down