From 310ca1451ffc44319bc9c143578b93ba0449a115 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Wed, 1 Oct 2025 12:10:55 -0700 Subject: [PATCH 1/2] Move diffs to HostPlatformTouch --- .../renderer/components/view/BaseTouch.cpp | 14 ----- .../renderer/components/view/BaseTouch.h | 26 ---------- .../components/view/HostPlatformTouch.cpp | 51 +++++++++++++++++++ .../components/view/HostPlatformTouch.h | 29 ++++++++++- 4 files changed, 79 insertions(+), 41 deletions(-) create mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformTouch.cpp diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.cpp index 2f67bcf75f8016..944d290e85e9e2 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.cpp @@ -23,13 +23,6 @@ void setTouchPayloadOnObject( object.setProperty(runtime, "target", touch.target); object.setProperty(runtime, "timestamp", touch.timestamp * 1000); object.setProperty(runtime, "force", touch.force); -#if TARGET_OS_OSX // [macOS - object.setProperty(runtime, "button", touch.button); - object.setProperty(runtime, "altKey", touch.altKey); - object.setProperty(runtime, "ctrlKey", touch.ctrlKey); - object.setProperty(runtime, "shiftKey", touch.shiftKey); - object.setProperty(runtime, "metaKey", touch.metaKey); -#endif // macOS] } #if RN_DEBUG_STRING_CONVERTIBLE @@ -49,13 +42,6 @@ std::vector getDebugProps( {"target", getDebugDescription(touch.target, options)}, {"force", getDebugDescription(touch.force, options)}, {"timestamp", getDebugDescription(touch.timestamp, options)}, -#if TARGET_OS_SX // [macOS - {"button", getDebugDescription(touch.button, options)}, - {"altKey", getDebugDescription(touch.altKey, options)}, - {"ctrlKey", getDebugDescription(touch.ctrlKey, options)}, - {"shiftKey", getDebugDescription(touch.shiftKey, options)}, - {"metaKey", getDebugDescription(touch.metaKey, options)}, -#endif // macOS] }; } diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.h b/packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.h index 55d6090719a373..0d658310f27a45 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/BaseTouch.h @@ -55,32 +55,6 @@ struct BaseTouch { * The time in seconds when the touch occurred or when it was last mutated. */ Float timestamp; -#if TARGET_OS_OSX // [macOS - /* - * The button indicating which pointer is used. - */ - int button; - - /* - * A flag indicating if the alt key is pressed. - */ - bool altKey; - - /* - * A flag indicating if the control key is pressed. - */ - bool ctrlKey; - - /* - * A flag indicating if the shift key is pressed. - */ - bool shiftKey; - - /* - * A flag indicating if the meta key is pressed. - */ - bool metaKey; -#endif // macOS] /* * The particular implementation of `Hasher` and (especially) `Comparator` diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformTouch.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformTouch.cpp new file mode 100644 index 00000000000000..eb533c78322c52 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformTouch.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include "HostPlatformTouch.h" +#include "Touch.h" + +namespace facebook::react { + +void setTouchPayloadOnObject( + jsi::Object& object, + jsi::Runtime& runtime, + const HostPlatformTouch& touch) { + setTouchPayloadOnObject(object, runtime, static_cast(touch)); +#if TARGET_OS_OSX // [macOS + object.setProperty(runtime, "button", touch.button); + object.setProperty(runtime, "altKey", touch.altKey); + object.setProperty(runtime, "ctrlKey", touch.ctrlKey); + object.setProperty(runtime, "shiftKey", touch.shiftKey); + object.setProperty(runtime, "metaKey", touch.metaKey); +#endif // macOS] +} + +#if RN_DEBUG_STRING_CONVERTIBLE + +std::string getDebugName(const HostPlatformTouch& /*touch*/) { + return "Touch"; +} + +std::vector getDebugProps( + const HostPlatformTouch& touch, + DebugStringConvertibleOptions options) { + auto debugProps = getDebugProps(static_cast(touch), options); + debugProps.insert( + debugProps.end(), + { + {"button", getDebugDescription(touch.button, options)}, + {"altKey", getDebugDescription(touch.altKey, options)}, + {"ctrlKey", getDebugDescription(touch.ctrlKey, options)}, + {"shiftKey", getDebugDescription(touch.shiftKey, options)}, + {"metaKey", getDebugDescription(touch.metaKey, options)}, + }); + return debugProps; +}; + +#endif + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformTouch.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformTouch.h index ef3b407272250e..e7691efb3217d6 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformTouch.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformTouch.h @@ -12,5 +12,32 @@ #include namespace facebook::react { -using HostPlatformTouch = BaseTouch; + +struct HostPlatformTouch : public BaseTouch { + /* + * The button indicating which pointer is used. + */ + int button; + + /* + * A flag indicating if the alt key is pressed. + */ + bool altKey; + + /* + * A flag indicating if the control key is pressed. + */ + bool ctrlKey; + + /* + * A flag indicating if the shift key is pressed. + */ + bool shiftKey; + + /* + * A flag indicating if the meta key is pressed. + */ + bool metaKey; +}; + } // namespace facebook::react From d9393fcfe40660ac8f01e475edf0fcee5e9e8121 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Wed, 1 Oct 2025 12:25:28 -0700 Subject: [PATCH 2/2] move macos keys to end --- .../react-native/Libraries/Types/CoreEventTypes.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/react-native/Libraries/Types/CoreEventTypes.js b/packages/react-native/Libraries/Types/CoreEventTypes.js index b568c59f6bcaab..5c156b9e97062c 100644 --- a/packages/react-native/Libraries/Types/CoreEventTypes.js +++ b/packages/react-native/Libraries/Types/CoreEventTypes.js @@ -221,13 +221,10 @@ export interface NativePointerEvent extends NativeMouseEvent { export type PointerEvent = NativeSyntheticEvent; export type NativeTouchEvent = $ReadOnly<{ - altKey?: ?boolean, // [macOS] - button?: ?number, // [macOS] /** * Array of all touch events that have changed since the last event */ changedTouches: $ReadOnlyArray, - ctrlKey?: ?boolean, // [macOS] /** * 3D Touch reported force * @platform ios @@ -245,7 +242,6 @@ export type NativeTouchEvent = $ReadOnly<{ * The Y position of the touch, relative to the element */ locationY: number, - metaKey?: ?boolean, // [macOS] /** * The X position of the touch, relative to the screen */ @@ -254,7 +250,7 @@ export type NativeTouchEvent = $ReadOnly<{ * The Y position of the touch, relative to the screen */ pageY: number, - shiftKey?: ?boolean, // [macOS] + /** * The node id of the element receiving the touch event */ @@ -267,6 +263,11 @@ export type NativeTouchEvent = $ReadOnly<{ * Array of all current touches on the screen */ touches: $ReadOnlyArray, + button?: ?number, // [macOS] + altKey?: ?boolean, // [macOS] + ctrlKey?: ?boolean, // [macOS] + shiftKey?: ?boolean, // [macOS] + metaKey?: ?boolean, // [macOS] }>; export type GestureResponderEvent = ResponderSyntheticEvent;