Skip to content

Commit 3aa42a2

Browse files
vincentriemerfacebook-github-bot
authored andcommitted
Add plumbing/boilerplate for an iOS implementation of the gotpointercapture and lostpointercapture events (second try) (#37889)
Summary: Pull Request resolved: #37889 Changelog: [Internal] - Add plumbing/boilerplate for an iOS implementation of the gotpointercapture and lostpointercapture events Lets try this again: The key difference between this and D44977499 (which I previously reverted) is that in propsConversions & primitives I've ommited the "capture" versions of those methods as it was causing issues. Since we're not doing any runtime checks of those raw props it isn't particularlly necessary (at least not yet) and if we ever want to we can address that when it comes up. The original diff description follows: This diff simply adds the boilerplate necessary to hook up the gotpointercapture and lostpointercapture events to the fabric iOS touch handler. This diff does not contain any actual implementation of their behavior as that will occur in future diffs. Reviewed By: adanoff Differential Revision: D46709127 fbshipit-source-id: 339dc99e14f2e72d9116bbe84edc67cb5bfaa73b
1 parent 9a8071e commit 3aa42a2

File tree

9 files changed

+78
-24
lines changed

9 files changed

+78
-24
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ type PointerEventProps = $ReadOnly<{|
105105
onPointerOverCapture?: ?(e: PointerEvent) => void,
106106
onPointerOut?: ?(e: PointerEvent) => void,
107107
onPointerOutCapture?: ?(e: PointerEvent) => void,
108+
onGotPointerCapture?: ?(e: PointerEvent) => void,
109+
onGotPointerCaptureCapture?: ?(e: PointerEvent) => void,
110+
onLostPointerCapture?: ?(e: PointerEvent) => void,
111+
onLostPointerCaptureCapture?: ?(e: PointerEvent) => void,
108112
|}>;
109113

110114
type FocusEventProps = $ReadOnly<{|

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ const bubblingEventTypes = {
144144
bubbled: 'onPointerOut',
145145
},
146146
},
147+
topGotPointerCapture: {
148+
phasedRegistrationNames: {
149+
captured: 'onGotPointerCaptureCapture',
150+
bubbled: 'onGotPointerCapture',
151+
},
152+
},
153+
topLostPointerCapture: {
154+
phasedRegistrationNames: {
155+
captured: 'onLostPointerCaptureCapture',
156+
bubbled: 'onLostPointerCapture',
157+
},
158+
},
147159
};
148160

149161
const directEventTypes = {
@@ -366,6 +378,8 @@ const validAttributesForEventProps = ConditionallyIgnoredEventHandlers({
366378
onPointerLeave: true,
367379
onPointerOver: true,
368380
onPointerOut: true,
381+
onGotPointerCapture: true,
382+
onLostPointerCapture: true,
369383
});
370384

371385
/**

packages/react-native/React/Views/RCTView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,7 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
132132
@property (nonatomic, assign) RCTCapturingEventBlock onPointerLeave;
133133
@property (nonatomic, assign) RCTBubblingEventBlock onPointerOver;
134134
@property (nonatomic, assign) RCTBubblingEventBlock onPointerOut;
135+
@property (nonatomic, assign) RCTBubblingEventBlock onGotPointerCapture;
136+
@property (nonatomic, assign) RCTBubblingEventBlock onLostPointerCapture;
135137

136138
@end

packages/react-native/React/Views/RCTViewManager.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,5 +549,7 @@ - (void)updateAccessibilityTraitsForRole:(RCTView *)view withDefaultView:(RCTVie
549549
RCT_EXPORT_VIEW_PROPERTY(onPointerLeave, RCTCapturingEventBlock)
550550
RCT_EXPORT_VIEW_PROPERTY(onPointerOver, RCTBubblingEventBlock)
551551
RCT_EXPORT_VIEW_PROPERTY(onPointerOut, RCTBubblingEventBlock)
552+
RCT_EXPORT_VIEW_PROPERTY(onGotPointerCapture, RCTBubblingEventBlock)
553+
RCT_EXPORT_VIEW_PROPERTY(onLostPointerCapture, RCTBubblingEventBlock)
552554

553555
@end

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,20 @@ void TouchEventEmitter::onPointerOut(const PointerEvent &event) const {
223223
RawEvent::Category::ContinuousStart);
224224
}
225225

226+
void TouchEventEmitter::onGotPointerCapture(const PointerEvent &event) const {
227+
dispatchPointerEvent(
228+
"gotPointerCapture",
229+
event,
230+
EventPriority::AsynchronousBatched,
231+
RawEvent::Category::ContinuousStart);
232+
}
233+
234+
void TouchEventEmitter::onLostPointerCapture(const PointerEvent &event) const {
235+
dispatchPointerEvent(
236+
"lostPointerCapture",
237+
event,
238+
EventPriority::AsynchronousBatched,
239+
RawEvent::Category::ContinuousEnd);
240+
}
241+
226242
} // namespace facebook::react

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class TouchEventEmitter : public EventEmitter {
3838
void onPointerLeave(PointerEvent const &event) const;
3939
void onPointerOver(PointerEvent const &event) const;
4040
void onPointerOut(PointerEvent const &event) const;
41+
void onGotPointerCapture(PointerEvent const &event) const;
42+
void onLostPointerCapture(PointerEvent const &event) const;
4143

4244
private:
4345
void dispatchTouchEvent(

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace facebook::react {
2121
enum class PointerEventsMode : uint8_t { Auto, None, BoxNone, BoxOnly };
2222

2323
struct ViewEvents {
24-
std::bitset<32> bits{};
24+
std::bitset<64> bits{};
2525

2626
enum class Offset : std::size_t {
2727
// Pointer events
@@ -60,13 +60,15 @@ struct ViewEvents {
6060
PointerOutCapture = 29,
6161
Click = 30,
6262
ClickCapture = 31,
63+
GotPointerCapture = 32,
64+
LostPointerCapture = 33,
6365
};
6466

6567
constexpr bool operator[](const Offset offset) const {
6668
return bits[static_cast<std::size_t>(offset)];
6769
}
6870

69-
std::bitset<32>::reference operator[](const Offset offset) {
71+
std::bitset<64>::reference operator[](const Offset offset) {
7072
return bits[static_cast<std::size_t>(offset)];
7173
}
7274
};

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,18 @@ static inline ViewEvents convertRawProp(
616616
"onClickCapture",
617617
sourceValue[Offset::ClickCapture],
618618
defaultValue[Offset::ClickCapture]);
619+
result[Offset::GotPointerCapture] = convertRawProp(
620+
context,
621+
rawProps,
622+
"onGotPointerCapture",
623+
sourceValue[Offset::GotPointerCapture],
624+
defaultValue[Offset::GotPointerCapture]);
625+
result[Offset::LostPointerCapture] = convertRawProp(
626+
context,
627+
rawProps,
628+
"onLostPointerCapture",
629+
sourceValue[Offset::LostPointerCapture],
630+
defaultValue[Offset::LostPointerCapture]);
619631

620632
// PanResponder callbacks
621633
result[Offset::MoveShouldSetResponder] = convertRawProp(

packages/rn-tester/js/examples/Experimental/W3CPointerEventPlatformTests/PointerEventCaptureMouse.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ function PointerEventCaptureMouseTestCase(
3232
const pointermoveNoCaptureGot1Ref = useRef(false);
3333
const ownEventForTheCapturedTargetGotRef = useRef(false);
3434

35-
// const testGotPointerCapture = harness.useAsyncTest(
36-
// 'gotpointercapture event received"',
37-
// );
38-
// const testLostPointerCapture = harness.useAsyncTest(
39-
// 'lostpointercapture event received"',
40-
// );
35+
const testGotPointerCapture = harness.useAsyncTest(
36+
'gotpointercapture event received"',
37+
);
38+
const testLostPointerCapture = harness.useAsyncTest(
39+
'lostpointercapture event received"',
40+
);
4141

4242
const handleCaptureButtonDown = useCallback((evt: PointerEvent) => {
4343
const target0 = target0Ref.current;
@@ -50,20 +50,20 @@ function PointerEventCaptureMouseTestCase(
5050
}
5151
}, []);
5252

53-
// const handleTarget0GotPointerCapture = useCallback(
54-
// (evt: PointerEvent) => {
55-
// testGotPointerCapture.done();
56-
// },
57-
// [testGotPointerCapture],
58-
// );
59-
60-
// const handleTarget0LostPointerCapture = useCallback(
61-
// (evt: PointerEvent) => {
62-
// testLostPointerCapture.done();
63-
// isPointerCaptureRef.current = false;
64-
// },
65-
// [testLostPointerCapture],
66-
// );
53+
const handleTarget0GotPointerCapture = useCallback(
54+
(evt: PointerEvent) => {
55+
testGotPointerCapture.done();
56+
},
57+
[testGotPointerCapture],
58+
);
59+
60+
const handleTarget0LostPointerCapture = useCallback(
61+
(evt: PointerEvent) => {
62+
testLostPointerCapture.done();
63+
isPointerCaptureRef.current = false;
64+
},
65+
[testLostPointerCapture],
66+
);
6767

6868
const testPointerMove0 = harness.useAsyncTest(
6969
'pointerover event for black rectangle received',
@@ -150,8 +150,8 @@ function PointerEventCaptureMouseTestCase(
150150
<View style={styles.container}>
151151
<View
152152
ref={target0Ref}
153-
// onGotPointerCapture={handleTarget0GotPointerCapture}
154-
// onLostPointerCapture={handleTarget0LostPointerCapture}
153+
onGotPointerCapture={handleTarget0GotPointerCapture}
154+
onLostPointerCapture={handleTarget0LostPointerCapture}
155155
onPointerMove={handleTarget0PointerMove}
156156
style={styles.target0}
157157
/>

0 commit comments

Comments
 (0)