From 32af9e6e8dd48a283a1abe3525f579b4407bbe76 Mon Sep 17 00:00:00 2001 From: Vincent Riemer Date: Tue, 23 Aug 2022 12:54:48 -0700 Subject: [PATCH] Fix buttons property value for non-hoverable pointers Summary: Changelog: [iOS][Internal] - Fix buttons property value for non-hoverable pointers The previous diff ensured that on iOS you could run through the entirety of the non-hoverable pointer event attributes test but that also revealed some failing tests related to the `buttons` property when using a non-hoverable pointer. This diff fixes that by ensuring that we only forward the result of the `buttonMask` to `buttons` when the pointer is a mouse, and assume that it is an emulated left click otherwise. Reviewed By: lunaleaps Differential Revision: D38914239 fbshipit-source-id: c573e934d0e9c0ac2af4945dc5360840ddc87d4d --- React/Fabric/RCTSurfaceTouchHandler.mm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/React/Fabric/RCTSurfaceTouchHandler.mm b/React/Fabric/RCTSurfaceTouchHandler.mm index 89d9f8c77df2a7..dc9995dcaaa71e 100644 --- a/React/Fabric/RCTSurfaceTouchHandler.mm +++ b/React/Fabric/RCTSurfaceTouchHandler.mm @@ -349,7 +349,16 @@ static PointerEvent CreatePointerEventFromActiveTouch(ActiveTouch activeTouch, R event.button = activeTouch.button; } - event.buttons = ButtonMaskToButtons(activeTouch.buttonMask); + event.buttons = 1; + if (@available(iOS 13.4, *)) { + if (activeTouch.touchType == UITouchTypeIndirectPointer) { + // Indirect pointers are the only situations where buttonMask is "accurate" + // so we override the assumed "left click" button value when those type of + // events are recieved + event.buttons = ButtonMaskToButtons(activeTouch.buttonMask); + } + } + UpdatePointerEventModifierFlags(event, activeTouch.modifierFlags); // UIEvent's button mask for touch end events still marks the button as down