Skip to content

Commit

Permalink
Align Pressibility.win32 to Pressibility.windows (#11864) (#11895)
Browse files Browse the repository at this point in the history
* add isDefaultButto check to win32

* Change files

* edit change file typo

* run link:fix

(cherry picked from commit 00d2242)

Co-authored-by: Chiara Mooney <34109996+chiaramooney@users.noreply.github.com>
Co-authored-by: Andrew Coates <30809111+acoates-ms@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 1, 2023
1 parent 14786ba commit 958bd7b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "add isDefaultButton check to win32",
"packageName": "@office-iss/react-native-win32",
"email": "email not defined",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ export default class Pressability {
|}>;
_touchActivateTime: ?number;
_touchState: TouchState = 'NOT_RESPONDER';
_isKeyDown: boolean = false;

constructor(config: PressabilityConfig) {
this.configure(config);
Expand Down Expand Up @@ -468,6 +469,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 @@ -596,14 +598,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 @@ -616,6 +621,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 Expand Up @@ -780,6 +786,12 @@ export default class Pressability {
}
}

// [Win32]
// $FlowFixMe - button typing
_isDefaultPressButton(button): boolean {
return !button; // Treat 0 or undefined as default press
}

/**
* Performs a transition between touchable states and identify any activations
* or deactivations (and callback invocations).
Expand Down Expand Up @@ -808,7 +820,10 @@ export default class Pressability {

if (isPressInSignal(prevState) && signal === 'LONG_PRESS_DETECTED') {
const {onLongPress} = this._config;
if (onLongPress != null) {
if (
onLongPress != null &&
this._isDefaultPressButton(getTouchFromPressEvent(event).button)
) {
onLongPress(event);
}
}
Expand All @@ -829,7 +844,11 @@ export default class Pressability {
this._deactivate(event);
}
const {onLongPress, onPress, android_disableSound} = this._config;
if (onPress != null) {

if (
onPress != null &&
this._isDefaultPressButton(getTouchFromPressEvent(event).button)
) {
const isPressCanceledByLongPress =
onLongPress != null &&
prevState === 'RESPONDER_ACTIVE_LONG_PRESS_IN' &&
Expand All @@ -848,17 +867,20 @@ export default class Pressability {

_activate(event: PressEvent): void {
const {onPressIn} = this._config;
const {pageX, pageY} = getTouchFromPressEvent(event);
const {pageX, pageY, button} = getTouchFromPressEvent(event);
this._touchActivatePosition = {pageX, pageY};
this._touchActivateTime = Date.now();
if (onPressIn != null) {
if (onPressIn != null && this._isDefaultPressButton(button)) {
onPressIn(event);
}
}

_deactivate(event: PressEvent): void {
const {onPressOut} = this._config;
if (onPressOut != null) {
if (
onPressOut != null &&
this._isDefaultPressButton(getTouchFromPressEvent(event).button)
) {
const minPressDuration = normalizeDelay(
this._config.minPressDuration,
0,
Expand Down

0 comments on commit 958bd7b

Please sign in to comment.