Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix can't change currency when double click the currency symbol button #29161

Merged
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
Expand Up @@ -10,6 +10,7 @@ import styles from '../../../styles/styles';
import genericPressablePropTypes from './PropTypes';
import CONST from '../../../CONST';
import * as StyleUtils from '../../../styles/StyleUtils';
import useSingleExecution from '../../../hooks/useSingleExecution';

/**
* Returns the cursor style based on the state of Pressable
Expand Down Expand Up @@ -44,12 +45,12 @@ const GenericPressable = forwardRef((props, ref) => {
keyboardShortcut,
shouldUseAutoHitSlop,
enableInScreenReaderStates,
isExecuting,
onPressIn,
onPressOut,
...rest
} = props;

const {isExecuting, singleExecution} = useSingleExecution();
const isScreenReaderActive = Accessibility.useScreenReaderStatus();
const [hitSlop, onLayout] = Accessibility.useAutoHitSlop();

Expand All @@ -63,8 +64,8 @@ const GenericPressable = forwardRef((props, ref) => {
shouldBeDisabledByScreenReader = isScreenReaderActive;
}

return props.disabled || shouldBeDisabledByScreenReader;
}, [isScreenReaderActive, enableInScreenReaderStates, props.disabled]);
return props.disabled || shouldBeDisabledByScreenReader || isExecuting;
}, [isScreenReaderActive, enableInScreenReaderStates, props.disabled, isExecuting]);

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

Expand Down Expand Up @@ -134,7 +135,7 @@ const GenericPressable = forwardRef((props, ref) => {
hitSlop={shouldUseAutoHitSlop ? hitSlop : undefined}
onLayout={shouldUseAutoHitSlop ? onLayout : undefined}
ref={ref}
onPress={!isDisabled ? onPressHandler : undefined}
onPress={!isDisabled ? singleExecution(onPressHandler) : undefined}
// In order to prevent haptic feedback, pass empty callback as onLongPress props. Please refer https://github.com/necolas/react-native-web/issues/2349#issuecomment-1195564240
onLongPress={!isDisabled && onLongPress ? onLongPressHandler : defaultLongPressHandler}
onKeyPress={!isDisabled ? onKeyPressHandler : undefined}
Expand Down
4 changes: 0 additions & 4 deletions src/components/Pressable/GenericPressable/PropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ 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 @@ -128,7 +125,6 @@ const defaultProps = {
keyboardShortcut: undefined,
shouldUseHapticsOnPress: false,
shouldUseHapticsOnLongPress: false,
isExecuting: false,
disabledStyle: {},
hoverStyle: {},
focusStyle: {},
Expand Down
11 changes: 2 additions & 9 deletions src/components/Pressable/PressableWithFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import GenericPressable from './GenericPressable';
import GenericPressablePropTypes from './GenericPressable/PropTypes';
import OpacityView from '../OpacityView';
import variables from '../../styles/variables';
import useSingleExecution from '../../hooks/useSingleExecution';

const omittedProps = ['wrapperStyle', 'needsOffscreenAlphaCompositing'];

Expand Down Expand Up @@ -43,14 +42,12 @@ const PressableWithFeedbackDefaultProps = {

const PressableWithFeedback = forwardRef((props, ref) => {
const propsWithoutWrapperProps = _.omit(props, omittedProps);
const {isExecuting, singleExecution} = useSingleExecution();
const [isPressed, setIsPressed] = useState(false);
const [isHovered, setIsHovered] = useState(false);
const isDisabled = props.disabled || isExecuting;

return (
<OpacityView
shouldDim={Boolean(!isDisabled && (isPressed || isHovered))}
shouldDim={Boolean(!props.disabled && (isPressed || isHovered))}
dimmingValue={isPressed ? props.pressDimmingValue : props.hoverDimmingValue}
style={props.wrapperStyle}
needsOffscreenAlphaCompositing={props.needsOffscreenAlphaCompositing}
Expand All @@ -59,8 +56,7 @@ const PressableWithFeedback = forwardRef((props, ref) => {
ref={ref}
// eslint-disable-next-line react/jsx-props-no-spreading
{...propsWithoutWrapperProps}
disabled={isDisabled}
isExecuting={isExecuting}
disabled={props.disabled}
onHoverIn={() => {
setIsHovered(true);
if (props.onHoverIn) {
Expand All @@ -85,9 +81,6 @@ const PressableWithFeedback = forwardRef((props, ref) => {
props.onPressOut();
}
}}
onPress={(e) => {
singleExecution(() => props.onPress(e))();
}}
>
{(state) => (_.isFunction(props.children) ? props.children(state) : props.children)}
</GenericPressable>
Expand Down
Loading