diff --git a/packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js b/packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js index cdd9eceaead2..f0edfac50f39 100644 --- a/packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js +++ b/packages/react-native/Libraries/NativeComponent/BaseViewConfig.android.js @@ -112,6 +112,18 @@ const bubblingEventTypes = { bubbled: 'onPointerOver', }, }, + topGotPointerCapture: { + phasedRegistrationNames: { + captured: 'onGotPointerCaptureCapture', + bubbled: 'onGotPointerCapture', + }, + }, + topLostPointerCapture: { + phasedRegistrationNames: { + captured: 'onLostPointerCaptureCapture', + bubbled: 'onLostPointerCapture', + }, + }, topClick: { phasedRegistrationNames: { captured: 'onClickCapture', @@ -424,6 +436,10 @@ const validAttributesForEventProps = { onPointerOutCapture: true, onPointerOver: true, onPointerOverCapture: true, + onGotPointerCapture: true, + onGotPointerCaptureCapture: true, + onLostPointerCapture: true, + onLostPointerCaptureCapture: true, } as const; /** diff --git a/packages/react-native/src/private/renderer/core/__tests__/EventDispatching-itest.js b/packages/react-native/src/private/renderer/core/__tests__/EventDispatching-itest.js index eec975e62174..46339e19f518 100644 --- a/packages/react-native/src/private/renderer/core/__tests__/EventDispatching-itest.js +++ b/packages/react-native/src/private/renderer/core/__tests__/EventDispatching-itest.js @@ -157,6 +157,58 @@ describe('Event Dispatching', () => { expect(onPointerUpPriority).toBe(UIManager.unstable_DiscreteEventPriority); }); + it('dispatches pointer capture events', () => { + const root = Fantom.createRoot(); + + const ref = React.createRef>(); + const order: Array = []; + + Fantom.runTask(() => { + root.render( + { + order.push('got-capture'); + }} + onGotPointerCapture={() => { + order.push('got-bubble'); + }} + onLostPointerCaptureCapture={() => { + order.push('lost-capture'); + }} + onLostPointerCapture={() => { + order.push('lost-bubble'); + }} + />, + ); + }); + + Fantom.dispatchNativeEvent( + ref, + 'onGotPointerCapture', + {pointerId: 1}, + { + category: Fantom.NativeEventCategory.Discrete, + }, + ); + + Fantom.dispatchNativeEvent( + ref, + 'onLostPointerCapture', + {pointerId: 1}, + { + category: Fantom.NativeEventCategory.Discrete, + }, + ); + + expect(order).toEqual([ + 'got-capture', + 'got-bubble', + 'lost-capture', + 'lost-bubble', + ]); + }); + it('dispatches events with continuous priority', () => { const root = Fantom.createRoot();