Skip to content

Commit

Permalink
Prevent onKeyUp on Pressability.windows.js from firing onPress withou…
Browse files Browse the repository at this point in the history
…t preceding onKeyDown (#10673)

* wip commmit msg

* renamed isPressed to isKeyDown

* Change files

* Change files and moved isKeyDown

* added comment about why isKeyDown is set outside of the if condition

* Updated package.json for T129776338

Co-authored-by: Helen Dong <helewxdong@gmail.com>
  • Loading branch information
helenwxdong and Helen Dong committed Nov 2, 2022
1 parent b604790 commit ed1e85e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "renamed isPressed to isKeyDown",
"packageName": "react-native-windows",
"email": "helewxdong@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
"resolved": "2.1.0",
"contentHash": "GmkKfoyerqmsHMn7OZj0AKpcBabD+GaafqphvX2Mw406IwiJRy1pKcKqdCfKJfYmkRyJ6+e+RaUylgdJoDa1jQ=="
},
"Microsoft.UI.Xaml": {
"type": "Transitive",
"resolved": "2.7.0",
"contentHash": "dB4im13tfmMgL/V3Ei+3kD2rUF+/lTxAmR4gjJ45l577eljHfdo/KUrxpq/3I1Vp6e5GCDG1evDaEGuDxypLMg=="
},
"NETStandard.Library": {
"type": "Transitive",
"resolved": "2.0.3",
Expand Down Expand Up @@ -120,38 +115,14 @@
"resolved": "2.2.9",
"contentHash": "qF6RRZKaflI+LR1YODNyWYjq5YoX8IJ2wx5y8O+AW2xO+1t/Q6Mm+jQ38zJbWnmXbrcOqUYofn7Y3/KC6lTLBQ=="
},
"common": {
"type": "Project"
},
"fmt": {
"type": "Project"
},
"folly": {
"type": "Project",
"dependencies": {
"fmt": "1.0.0"
}
},
"microsoft.reactnative": {
"type": "Project",
"dependencies": {
"Common": "1.0.0",
"Folly": "1.0.0",
"ReactCommon": "1.0.0"
}
"type": "Project"
},
"microsoft.reactnative.managed": {
"type": "Project",
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "6.2.9",
"Microsoft.ReactNative": "1.0.0",
"Microsoft.UI.Xaml": "2.7.0"
}
},
"reactcommon": {
"type": "Project",
"dependencies": {
"Folly": "1.0.0"
"Microsoft.ReactNative": "1.0.0"
}
}
},
Expand Down
8 changes: 7 additions & 1 deletion vnext/src/Libraries/Pressability/Pressability.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ export default class Pressability {
|}>;
_touchActivateTime: ?number;
_touchState: TouchState = 'NOT_RESPONDER';
_isKeyDown: boolean = false;

constructor(config: PressabilityConfig) {
this.configure(config);
Expand Down Expand Up @@ -467,6 +468,7 @@ export default class Pressability {
if (onBlur != null) {
onBlur(event);
}
this._isKeyDown = false;
},
onFocus: (event: FocusEvent): void => {
const {onFocus} = this._config;
Expand Down Expand Up @@ -593,14 +595,17 @@ export default class Pressability {
(event.nativeEvent.code === 'Space' ||
event.nativeEvent.code === 'Enter' ||
event.nativeEvent.code === 'GamepadA') &&
event.defaultPrevented != true
event.defaultPrevented != true &&
this._isKeyDown
) {
const {onPressOut, onPress} = this._config;
// $FlowFixMe: PressEvents don't mesh with keyboarding APIs. Keep legacy behavior of passing KeyEvents instead
onPressOut && onPressOut(event);
// $FlowFixMe: PressEvents don't mesh with keyboarding APIs. Keep legacy behavior of passing KeyEvents instead
onPress && onPress(event);
}
// Native windows app clears the key pressed state when another key press interrupts the current
this._isKeyDown = false;
},
onKeyDown: (event: KeyEvent): void => {
const {onKeyDown} = this._config;
Expand All @@ -613,6 +618,7 @@ export default class Pressability {
event.defaultPrevented != true
) {
const {onPressIn} = this._config;
this._isKeyDown = true;
// $FlowFixMe: PressEvents don't mesh with keyboarding APIs. Keep legacy behavior of passing KeyEvents instead
onPressIn && onPressIn(event);
}
Expand Down

0 comments on commit ed1e85e

Please sign in to comment.