Skip to content
Merged
Show file tree
Hide file tree
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,4 +1,4 @@
import React, {useCallback, useEffect, useState, useMemo, forwardRef} from 'react';
import React, {useCallback, useEffect, useMemo, forwardRef} from 'react';
// eslint-disable-next-line no-restricted-imports
import {Pressable} from 'react-native';
import _ from 'underscore';
Expand Down Expand Up @@ -43,6 +43,7 @@ const GenericPressable = forwardRef((props, ref) => {
keyboardShortcut,
shouldUseAutoHitSlop,
enableInScreenReaderStates,
isExecuting,
onPressIn,
onPressOut,
...rest
Expand All @@ -64,7 +65,7 @@ const GenericPressable = forwardRef((props, ref) => {
return props.disabled || shouldBeDisabledByScreenReader;
}, [isScreenReaderActive, enableInScreenReaderStates, props.disabled]);

const [shouldUseDisabledCursor, setShouldUseDisabledCursor] = useState(isDisabled);
const shouldUseDisabledCursor = useMemo(() => isDisabled && !isExecuting, [isDisabled, isExecuting]);

const onLongPressHandler = useCallback(
(event) => {
Expand Down Expand Up @@ -118,14 +119,6 @@ const GenericPressable = forwardRef((props, ref) => {
[onPressHandler],
);

useEffect(() => {
if (isDisabled) {
const timer = setTimeout(() => setShouldUseDisabledCursor(true), 1000);
return () => clearTimeout(timer);
}
setShouldUseDisabledCursor(false);
}, [isDisabled]);

useEffect(() => {
if (!keyboardShortcut) {
return () => {};
Expand Down
4 changes: 4 additions & 0 deletions src/components/Pressable/GenericPressable/PropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const pressablePropTypes = {
*/
shouldUseHapticsOnLongPress: PropTypes.bool,

/** Whether the button is executing */
isExecuting: PropTypes.bool,

/**
* style for when the component is disabled. Can be a function that receives the component's state (active, disabled, hover, focus, pressed, isScreenReaderActive)
* @default {}
Expand Down Expand Up @@ -125,6 +128,7 @@ const defaultProps = {
keyboardShortcut: undefined,
shouldUseHapticsOnPress: false,
shouldUseHapticsOnLongPress: false,
isExecuting: false,
disabledStyle: {},
hoverStyle: {},
focusStyle: {},
Expand Down
1 change: 1 addition & 0 deletions src/components/Pressable/PressableWithFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const PressableWithFeedback = forwardRef((props, ref) => {
// eslint-disable-next-line react/jsx-props-no-spreading
{...propsWithoutWrapperStyles}
disabled={isDisabled}
isExecuting={isExecuting}
onHoverIn={() => {
setIsHovered(true);
if (props.onHoverIn) props.onHoverIn();
Expand Down