Skip to content

Commit a750192

Browse files
Saadnajmiclaude
andcommitted
Align onAuxClick with upstream pointer event system
Port the shared changes from facebook#56298: - Add onAuxClick/onAuxClickCapture to TouchEventEmitter (shared C++) - Add AuxClick/AuxClickCapture to ViewEvents in primitives.h - Add prop conversions in propsConversions.h - Register topAuxClick as a bubbling event in BaseViewConfig.ios.js - Add dispatch logic in RCTSurfacePointerHandler.mm (iOS path) - Type onAuxClick as PointerEvent in PointerEventProps (Flow + TS) Remove redundant macOS-specific JS registrations since macOS now inherits the bubbling event from the iOS base config. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0c56c09 commit a750192

File tree

10 files changed

+29
-8
lines changed

10 files changed

+29
-8
lines changed

packages/react-native/Libraries/Components/View/ViewPropTypes.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ export interface ViewPropsMacOS {
139139
enableFocusRing?: boolean | undefined;
140140
onMouseEnter?: ((event: MouseEvent) => void) | undefined;
141141
onMouseLeave?: ((event: MouseEvent) => void) | undefined;
142-
onAuxClick?: ((event: MouseEvent) => void) | undefined;
143142
onDoubleClick?: ((event: MouseEvent) => void) | undefined;
144143
onDragEnter?: ((event: DragEvent) => void) | undefined;
145144
onDragLeave?: ((event: DragEvent) => void) | undefined;

packages/react-native/Libraries/Components/View/ViewPropTypes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,13 @@ export type KeyboardEventProps = $ReadOnly<{|
130130
type MouseEventProps = $ReadOnly<{
131131
onMouseEnter?: ?(event: MouseEvent) => void,
132132
onMouseLeave?: ?(event: MouseEvent) => void,
133-
onAuxClick?: ?(event: MouseEvent) => void, // [macOS]
134133
onDoubleClick?: ?(event: MouseEvent) => void, // [macOS]
135134
}>;
136135

137136
// Experimental/Work in Progress Pointer Event Callbacks (not yet ready for use)
138137
type PointerEventProps = $ReadOnly<{
138+
onAuxClick?: ?(event: PointerEvent) => void,
139+
onAuxClickCapture?: ?(event: PointerEvent) => void,
139140
onClick?: ?(event: PointerEvent) => void,
140141
onClickCapture?: ?(event: PointerEvent) => void,
141142
onPointerEnter?: ?(event: PointerEvent) => void,

packages/react-native/Libraries/NativeComponent/BaseViewConfig.ios.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ const bubblingEventTypes = {
8989
},
9090

9191
// Experimental/Work in Progress Pointer Events (not yet ready for use)
92+
topAuxClick: {
93+
phasedRegistrationNames: {
94+
captured: 'onAuxClickCapture',
95+
bubbled: 'onAuxClick',
96+
},
97+
},
9298
topClick: {
9399
phasedRegistrationNames: {
94100
captured: 'onClickCapture',
@@ -394,6 +400,8 @@ const validAttributesForEventProps = ConditionallyIgnoredEventHandlers({
394400
onTouchCancel: true,
395401

396402
// Pointer events
403+
onAuxClick: true,
404+
onAuxClickCapture: true,
397405
onClick: true,
398406
onClickCapture: true,
399407
onPointerUp: true,

packages/react-native/Libraries/NativeComponent/BaseViewConfig.macos.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ const bubblingEventTypes = {
3434

3535
const directEventTypes = {
3636
...PlatformBaseViewConfigIos.directEventTypes,
37-
topAuxClick: {
38-
registrationName: 'onAuxClick',
39-
},
4037
topDoubleClick: {
4138
registrationName: 'onDoubleClick',
4239
},
@@ -73,7 +70,6 @@ const validAttributesForNonEventProps = {
7370

7471
// Props for bubbling and direct events
7572
const validAttributesForEventProps = ConditionallyIgnoredEventHandlers({
76-
onAuxClick: true,
7773
onBlur: true,
7874
onDoubleClick: true,
7975
onDragEnter: true,

packages/react-native/React/Fabric/RCTSurfacePointerHandler.mm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,12 @@ - (void)_dispatchActivePointers:(std::vector<ActivePointer>)activePointers event
703703
}
704704
case RCTPointerEventTypeEnd: {
705705
eventEmitter->onPointerUp(pointerEvent);
706-
if (pointerEvent.isPrimary && pointerEvent.button == 0 && IsPointerWithinInitialTree(activePointer)) {
707-
eventEmitter->onClick(std::move(pointerEvent));
706+
if (pointerEvent.isPrimary && pointerEvent.button == 0) {
707+
if (IsPointerWithinInitialTree(activePointer)) {
708+
eventEmitter->onClick(std::move(pointerEvent));
709+
}
710+
} else if (IsPointerWithinInitialTree(activePointer)) {
711+
eventEmitter->onAuxClick(std::move(pointerEvent));
708712
}
709713
break;
710714
}

packages/react-native/ReactCommon/react/renderer/components/view/TouchEventEmitter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ void TouchEventEmitter::onTouchCancel(TouchEvent event) const {
8686
"touchCancel", std::move(event), RawEvent::Category::ContinuousEnd);
8787
}
8888

89+
void TouchEventEmitter::onAuxClick(PointerEvent event) const {
90+
dispatchPointerEvent("auxClick", std::move(event), RawEvent::Category::Discrete);
91+
}
92+
8993
void TouchEventEmitter::onClick(PointerEvent event) const {
9094
dispatchPointerEvent("click", std::move(event), RawEvent::Category::Discrete);
9195
}

packages/react-native/ReactCommon/react/renderer/components/view/TouchEventEmitter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TouchEventEmitter : public EventEmitter {
2929
void onTouchEnd(TouchEvent event) const;
3030
void onTouchCancel(TouchEvent event) const;
3131

32+
void onAuxClick(PointerEvent event) const;
3233
void onClick(PointerEvent event) const;
3334
void onPointerCancel(PointerEvent event) const;
3435
void onPointerDown(PointerEvent event) const;

packages/react-native/ReactCommon/react/renderer/components/view/primitives.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct ViewEvents {
6767
PointerDownCapture = 35,
6868
PointerUp = 36,
6969
PointerUpCapture = 37,
70+
AuxClick = 38,
71+
AuxClickCapture = 39,
7072
};
7173

7274
constexpr bool operator[](const Offset offset) const {

packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,10 @@ static inline ViewEvents convertRawProp(
830830
"onPointerOutCapture",
831831
sourceValue[Offset::PointerOutCapture],
832832
defaultValue[Offset::PointerOutCapture]);
833+
result[Offset::AuxClick] =
834+
convertRawProp(context, rawProps, "onAuxClick", sourceValue[Offset::AuxClick], defaultValue[Offset::AuxClick]);
835+
result[Offset::AuxClickCapture] = convertRawProp(
836+
context, rawProps, "onAuxClickCapture", sourceValue[Offset::AuxClickCapture], defaultValue[Offset::AuxClickCapture]);
833837
result[Offset::Click] = convertRawProp(
834838
context,
835839
rawProps,

packages/react-native/ReactNativeApi.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,6 +3676,8 @@ declare type PlatformType =
36763676
| WindowsPlatform
36773677
declare type PointerEvent = NativeSyntheticEvent<NativePointerEvent>
36783678
declare type PointerEventProps = {
3679+
readonly onAuxClick?: (event: PointerEvent) => void
3680+
readonly onAuxClickCapture?: (event: PointerEvent) => void
36793681
readonly onClick?: (event: PointerEvent) => void
36803682
readonly onClickCapture?: (event: PointerEvent) => void
36813683
readonly onGotPointerCapture?: (e: PointerEvent) => void

0 commit comments

Comments
 (0)