Skip to content

Commit

Permalink
W3CPointerEvents: fix unintentional shallow copy of coordinates (#38201)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #38201

Changelog: [Android] [Internal] - W3CPointerEvents: fix unintentional shallow copy of coordinates

When normalizing pointer event state, we previously only made a shallow copy and thus unintentionally modified the coordinate values in the original event state. This change fixes the issue by creating new coordinate arrays for the normalized event state instead of reusing the existing ones.

Reviewed By: javache

Differential Revision: D47230953

fbshipit-source-id: b29118c1ec32cd80fc0f05b2a55f283ef060f244
  • Loading branch information
Alex Danoff authored and facebook-github-bot committed Jul 6, 2023
1 parent 2bd4429 commit 5a57c0b
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -674,16 +674,14 @@ private PointerEventState normalizeToRoot(PointerEventState original, float root
Map<Integer, float[]> newOffsets = new HashMap<>(original.getOffsetByPointerId());
Map<Integer, float[]> newEventCoords = new HashMap<>(original.getEventCoordinatesByPointerId());

float[] rootOffset = {rootX, rootY};
for (Map.Entry<Integer, float[]> offsetEntry : newOffsets.entrySet()) {
float[] offsetValue = offsetEntry.getValue();
offsetValue[0] = rootX;
offsetValue[1] = rootY;
offsetEntry.setValue(rootOffset);
}

float[] zeroOffset = {0, 0};
for (Map.Entry<Integer, float[]> eventCoordsEntry : newEventCoords.entrySet()) {
float[] eventCoordsValue = eventCoordsEntry.getValue();
eventCoordsValue[0] = 0;
eventCoordsValue[1] = 0;
eventCoordsEntry.setValue(zeroOffset);
}

return new PointerEventState(
Expand Down

0 comments on commit 5a57c0b

Please sign in to comment.