Skip to content

Commit 74382ca

Browse files
yaminyassinmeta-codesync[bot]
authored andcommitted
Register Android pointer capture events (#57176)
Summary: The `PointerEventsProcessor` C++ pointer-events implementation already supports pointer capture and can emit `topGotPointerCapture` and `topLostPointerCapture`. `TouchEventEmitter` has handlers for both events. Android base view config was not registering the events: - `onGotPointerCapture` / `onGotPointerCaptureCapture` - `onLostPointerCapture` / `onLostPointerCaptureCapture` This adds the missing Android registrations and adds an EventDispatching integration test covering capture and bubble dispatch for both pointer capture events. ## Changelog: [Android] [Fixed] - Register pointer capture event handlers in the Android base view config Pull Request resolved: #57176 Test Plan: Added coverage in `EventDispatching-itest.js` for `onGotPointerCapture`, `onGotPointerCaptureCapture`, `onLostPointerCapture`, and `onLostPointerCaptureCapture`. `git diff --check main...HEAD` Reviewed By: cortinico Differential Revision: D108321784 Pulled By: Abbondanzo fbshipit-source-id: ce5c6d369dae15030062457d2857ae501e02e224
1 parent cb0e55f commit 74382ca

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ const bubblingEventTypes = {
112112
bubbled: 'onPointerOver',
113113
},
114114
},
115+
topGotPointerCapture: {
116+
phasedRegistrationNames: {
117+
captured: 'onGotPointerCaptureCapture',
118+
bubbled: 'onGotPointerCapture',
119+
},
120+
},
121+
topLostPointerCapture: {
122+
phasedRegistrationNames: {
123+
captured: 'onLostPointerCaptureCapture',
124+
bubbled: 'onLostPointerCapture',
125+
},
126+
},
115127
topClick: {
116128
phasedRegistrationNames: {
117129
captured: 'onClickCapture',
@@ -424,6 +436,10 @@ const validAttributesForEventProps = {
424436
onPointerOutCapture: true,
425437
onPointerOver: true,
426438
onPointerOverCapture: true,
439+
onGotPointerCapture: true,
440+
onGotPointerCaptureCapture: true,
441+
onLostPointerCapture: true,
442+
onLostPointerCaptureCapture: true,
427443
} as const;
428444

429445
/**

packages/react-native/src/private/renderer/core/__tests__/EventDispatching-itest.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,58 @@ describe('Event Dispatching', () => {
157157
expect(onPointerUpPriority).toBe(UIManager.unstable_DiscreteEventPriority);
158158
});
159159

160+
it('dispatches pointer capture events', () => {
161+
const root = Fantom.createRoot();
162+
163+
const ref = React.createRef<React.ElementRef<typeof View>>();
164+
const order: Array<string> = [];
165+
166+
Fantom.runTask(() => {
167+
root.render(
168+
<View
169+
ref={ref}
170+
onGotPointerCaptureCapture={() => {
171+
order.push('got-capture');
172+
}}
173+
onGotPointerCapture={() => {
174+
order.push('got-bubble');
175+
}}
176+
onLostPointerCaptureCapture={() => {
177+
order.push('lost-capture');
178+
}}
179+
onLostPointerCapture={() => {
180+
order.push('lost-bubble');
181+
}}
182+
/>,
183+
);
184+
});
185+
186+
Fantom.dispatchNativeEvent(
187+
ref,
188+
'onGotPointerCapture',
189+
{pointerId: 1},
190+
{
191+
category: Fantom.NativeEventCategory.Discrete,
192+
},
193+
);
194+
195+
Fantom.dispatchNativeEvent(
196+
ref,
197+
'onLostPointerCapture',
198+
{pointerId: 1},
199+
{
200+
category: Fantom.NativeEventCategory.Discrete,
201+
},
202+
);
203+
204+
expect(order).toEqual([
205+
'got-capture',
206+
'got-bubble',
207+
'lost-capture',
208+
'lost-bubble',
209+
]);
210+
});
211+
160212
it('dispatches events with continuous priority', () => {
161213
const root = Fantom.createRoot();
162214

0 commit comments

Comments
 (0)