Skip to content

Commit bcc69df

Browse files
Artem Goncharovfacebook-github-bot
Artem Goncharov
authored andcommitted
Back out "PointerEvents: Don't dispatch when no listeners for hover events" because hover events stopped working in felios apps in headsets
Summary: Changelog: [Internal][Changed] The diff I'm backing out accidentally made Hover events in Felios apps that use RN under the hood stopped working in headsets (Oculus, Arcata). So we can't test our apps properly without these events. We, with the diff author Luna tried to fix that but it turned out to be not easy so we decided to revert the commit in order to unblock experiences teams. Original commit changeset: d6b5c32ae50b Original Phabricator Diff: D36601638 (40769f2) (Note: this ignores all push blocking failures!) Reviewed By: arhelmus Differential Revision: D37135208 fbshipit-source-id: 4f7d5f168b795690e951ce7063ae3feec3338772
1 parent 5471afe commit bcc69df

File tree

1 file changed

+41
-83
lines changed

1 file changed

+41
-83
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java

Lines changed: 41 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,7 @@ public void handleMotionEvent(MotionEvent motionEvent, EventDispatcher eventDisp
111111

112112
if (!supportsHover) {
113113
dispatchNonBubblingEventForPathWhenListened(
114-
EVENT.ENTER,
115-
EVENT.ENTER_CAPTURE,
116-
hitPath,
117-
eventDispatcher,
118-
surfaceId,
119-
motionEvent,
120-
false);
114+
EVENT.ENTER, EVENT.ENTER_CAPTURE, hitPath, eventDispatcher, surfaceId, motionEvent);
121115
}
122116

123117
boolean listeningForDown =
@@ -202,13 +196,7 @@ public void handleMotionEvent(MotionEvent motionEvent, EventDispatcher eventDisp
202196

203197
if (!supportsHover) {
204198
dispatchNonBubblingEventForPathWhenListened(
205-
EVENT.LEAVE,
206-
EVENT.LEAVE_CAPTURE,
207-
hitPath,
208-
eventDispatcher,
209-
surfaceId,
210-
motionEvent,
211-
false);
199+
EVENT.LEAVE, EVENT.LEAVE_CAPTURE, hitPath, eventDispatcher, surfaceId, motionEvent);
212200
}
213201
return;
214202
}
@@ -239,28 +227,22 @@ private static boolean isAnyoneListeningForBubblingEvent(
239227
return false;
240228
}
241229

242-
/**
243-
* Dispatch event only if ancestor is listening to relevant capture event. This should only be
244-
* relevant for ENTER/LEAVE events that need to be dispatched along every relevant view in the hit
245-
* path.
246-
*
247-
* @param pointerEventType - Should only be ENTER/LEAVE events
248-
* @param hitPath - ViewTargets ordered from target -> root
249-
* @param dispatcher
250-
* @param surfaceId
251-
* @param motionEvent
252-
* @param forceDispatch - Ignore if ancestor is listening and force the event to be dispatched
230+
/*
231+
Dispatch event only if ancestor is listening to relevant event.
232+
This should only be relevant for ENTER/LEAVE events.
233+
@param hitPath - ordered from inner target to root
253234
*/
235+
236+
/** Dispatch non-bubbling event along the hit path only when relevant listeners */
254237
private static void dispatchNonBubblingEventForPathWhenListened(
255238
EVENT event,
256239
EVENT captureEvent,
257240
List<ViewTarget> hitPath,
258241
EventDispatcher dispatcher,
259242
int surfaceId,
260-
MotionEvent motionEvent,
261-
boolean forceDispatch) {
243+
MotionEvent motionEvent) {
262244

263-
boolean ancestorListening = forceDispatch;
245+
boolean ancestorListening = false;
264246
String eventName = PointerEventHelper.getDispatchableEventName(event);
265247
if (eventName == null) {
266248
return;
@@ -330,72 +312,54 @@ private void handleHoverEvent(
330312
// hitState is list ordered from inner child -> parent tag
331313
// Traverse hitState back-to-front to find the first divergence with mLastHitState
332314
// FIXME: this may generate incorrect events when view collapsing changes the hierarchy
333-
boolean nonDivergentListeningToEnter = false;
334-
boolean nonDivergentListeningToLeave = false;
335-
int firstDivergentIndexFromBack = 0;
336-
while (firstDivergentIndexFromBack < Math.min(hitPath.size(), mLastHitPath.size())
315+
int firstDivergentIndex = 0;
316+
while (firstDivergentIndex < Math.min(hitPath.size(), mLastHitPath.size())
337317
&& hitPath
338-
.get(hitPath.size() - 1 - firstDivergentIndexFromBack)
339-
.equals(mLastHitPath.get(mLastHitPath.size() - 1 - firstDivergentIndexFromBack))) {
340-
341-
// Track if any non-diverging views are listening to enter/leave
342-
View nonDivergentViewTargetView =
343-
hitPath.get(hitPath.size() - 1 - firstDivergentIndexFromBack).getView();
344-
if (!nonDivergentListeningToEnter
345-
&& PointerEventHelper.isListening(nonDivergentViewTargetView, EVENT.ENTER_CAPTURE)) {
346-
nonDivergentListeningToEnter = true;
347-
}
348-
if (!nonDivergentListeningToLeave
349-
&& PointerEventHelper.isListening(nonDivergentViewTargetView, EVENT.LEAVE_CAPTURE)) {
350-
nonDivergentListeningToLeave = true;
351-
}
352-
353-
firstDivergentIndexFromBack++;
318+
.get(hitPath.size() - 1 - firstDivergentIndex)
319+
.equals(mLastHitPath.get(mLastHitPath.size() - 1 - firstDivergentIndex))) {
320+
firstDivergentIndex++;
354321
}
355322

356-
boolean hasDiverged =
357-
firstDivergentIndexFromBack < Math.max(hitPath.size(), mLastHitPath.size());
323+
boolean hasDiverged = firstDivergentIndex < Math.max(hitPath.size(), mLastHitPath.size());
358324

325+
// Fire all relevant enter events
359326
if (hasDiverged) {
360327
// If something has changed in either enter/exit, let's start a new coalescing key
361328
mTouchEventCoalescingKeyHelper.incrementCoalescingKey(mHoverInteractionKey);
362329

363-
List<ViewTarget> enterViewTargets =
364-
hitPath.subList(0, hitPath.size() - firstDivergentIndexFromBack);
330+
List<ViewTarget> enterViewTargets = hitPath.subList(0, hitPath.size() - firstDivergentIndex);
365331
if (enterViewTargets.size() > 0) {
366-
dispatchNonBubblingEventForPathWhenListened(
367-
EVENT.ENTER,
368-
EVENT.ENTER_CAPTURE,
369-
enterViewTargets,
370-
eventDispatcher,
371-
surfaceId,
372-
motionEvent,
373-
nonDivergentListeningToEnter);
332+
// root -> child
333+
for (int i = enterViewTargets.size(); i-- > 0; ) {
334+
eventDispatcher.dispatchEvent(
335+
PointerEvent.obtain(
336+
PointerEventHelper.POINTER_ENTER,
337+
surfaceId,
338+
enterViewTargets.get(i).getViewId(),
339+
motionEvent));
340+
}
374341
}
375342

343+
// Fire all relevant exit events
376344
List<ViewTarget> exitViewTargets =
377-
mLastHitPath.subList(0, mLastHitPath.size() - firstDivergentIndexFromBack);
345+
mLastHitPath.subList(0, mLastHitPath.size() - firstDivergentIndex);
378346
if (exitViewTargets.size() > 0) {
379347
// child -> root
380-
dispatchNonBubblingEventForPathWhenListened(
381-
EVENT.LEAVE,
382-
EVENT.LEAVE_CAPTURE,
383-
enterViewTargets,
384-
eventDispatcher,
385-
surfaceId,
386-
motionEvent,
387-
nonDivergentListeningToLeave);
348+
for (ViewTarget exitViewTarget : exitViewTargets) {
349+
eventDispatcher.dispatchEvent(
350+
PointerEvent.obtain(
351+
PointerEventHelper.POINTER_LEAVE,
352+
surfaceId,
353+
exitViewTarget.getViewId(),
354+
motionEvent));
355+
}
388356
}
389357
}
390358

391359
int coalescingKey = mTouchEventCoalescingKeyHelper.getCoalescingKey(mHoverInteractionKey);
392-
boolean listeningToMove =
393-
isAnyoneListeningForBubblingEvent(hitPath, EVENT.MOVE, EVENT.MOVE_CAPTURE);
394-
if (listeningToMove) {
395-
eventDispatcher.dispatchEvent(
396-
PointerEvent.obtain(
397-
PointerEventHelper.POINTER_MOVE, surfaceId, targetTag, motionEvent, coalescingKey));
398-
}
360+
eventDispatcher.dispatchEvent(
361+
PointerEvent.obtain(
362+
PointerEventHelper.POINTER_MOVE, surfaceId, targetTag, motionEvent, coalescingKey));
399363

400364
mLastHitPath = hitPath;
401365
mLastEventCoordinates[0] = x;
@@ -425,13 +389,7 @@ private void dispatchCancelEvent(
425389
}
426390

427391
dispatchNonBubblingEventForPathWhenListened(
428-
EVENT.LEAVE,
429-
EVENT.LEAVE_CAPTURE,
430-
hitPath,
431-
eventDispatcher,
432-
surfaceId,
433-
motionEvent,
434-
false);
392+
EVENT.LEAVE, EVENT.LEAVE_CAPTURE, hitPath, eventDispatcher, surfaceId, motionEvent);
435393

436394
mTouchEventCoalescingKeyHelper.removeCoalescingKey(mDownStartTime);
437395
mDownStartTime = TouchEvent.UNSET;

0 commit comments

Comments
 (0)