Skip to content

Commit

Permalink
Fix incorrect pointer coordinates caching
Browse files Browse the repository at this point in the history
Summary:
Changelog: [Internal] - Fix incorrect pointer coordinates caching

In D48472486 I moved the updating of "previous" fields into the `handleHitStateDivergence` method which made sense considering that it's run on every event regardless but what I didn't take into account was the updating of the `mLastEventCoordinatesByPointerId` field. On `ACTION_HOVER_MOVE` events there's a filter that ensures that only move events that have a large enough distance are emitted (something that isn't done on iOS, hence why I didn't think of it), but after my changes in D48472486 it was updating `mLastEventCoordinatesByPointerId` **before** that hover move check, making the distance always 0 and never firing move events.

This diff fixes this by moving the updating of `mLastEventCoordinatesByPointerId` and `mLastButtonState` back to the end of `handleMotionEvent`.

Differential Revision: D48756372

fbshipit-source-id: a6f22a9bc33ff96880727ebd400b45b1d0c5c77f
  • Loading branch information
vincentriemer committed Aug 28, 2023
1 parent 0c25f19 commit 1cb6495
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@ public void handleMotionEvent(
"Motion Event was ignored. Action=" + action + " Target=" + activeTargetTag);
return;
}

// Update "previous" pointer coordinates and button state
Map<Integer, float[]> nextEventCoordinatesByPointerId =
new HashMap<>(eventState.getEventCoordinatesByPointerId());
mLastEventCoordinatesByPointerId = nextEventCoordinatesByPointerId;
mLastButtonState = motionEvent.getButtonState();

// Clean up any stale pointerIds
Set<Integer> allPointerIds = mLastEventCoordinatesByPointerId.keySet();
mHoveringPointerIds.retainAll(allPointerIds);
}

private static boolean isAnyoneListeningForBubblingEvent(
Expand Down Expand Up @@ -562,21 +572,11 @@ private void handleHitStateDivergence(

Map<Integer, List<TouchTargetHelper.ViewTarget>> nextHitPathByPointerId =
new HashMap<>(eventState.getHitPathByPointerId());
Map<Integer, float[]> nextEventCoordinatesByPointerId =
new HashMap<>(eventState.getEventCoordinatesByPointerId());

if (targetTag == UNSELECTED_VIEW_TAG) {
nextHitPathByPointerId.remove(activePointerId);
nextEventCoordinatesByPointerId.remove(activePointerId);
}

mLastHitPathByPointerId = nextHitPathByPointerId;
mLastEventCoordinatesByPointerId = nextEventCoordinatesByPointerId;
mLastButtonState = motionEvent.getButtonState();

// Clean up any stale pointerIds
Set<Integer> allPointerIds = mLastEventCoordinatesByPointerId.keySet();
mHoveringPointerIds.retainAll(allPointerIds);
}

private void onMove(
Expand Down

0 comments on commit 1cb6495

Please sign in to comment.