From 3239b704c397ad9c7021073343a1d1c4790ca43b Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 8 Jul 2020 13:19:17 -0700 Subject: [PATCH] Propoagate Tap events on Android hybrid views (flutter/engine#19608) Translate the coordinate from global flutterview to the specific embedded sub-view. --- .../platform/PlatformViewsController.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 3929698a8e..92b77de1b0 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -309,12 +309,11 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega MotionEventTracker.MotionEventId motionEventId = MotionEventTracker.MotionEventId.from(touch.motionEventId); MotionEvent trackedEvent = motionEventTracker.pop(motionEventId); - if (trackedEvent != null) { - return trackedEvent; - } - // TODO (kaushikiska) : warn that we are potentially using an untracked - // event in the platform views. + // Pointer coordinates in the tracked events are global to FlutterView + // framework converts them to be local to a widget, given that + // motion events operate on local coords, we need to replace these in the tracked + // event with their local counterparts. PointerProperties[] pointerProperties = parsePointerPropertiesList(touch.rawPointerPropertiesList) .toArray(new PointerProperties[touch.pointerCount]); @@ -322,6 +321,26 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega parsePointerCoordsList(touch.rawPointerCoords, density) .toArray(new PointerCoords[touch.pointerCount]); + if (trackedEvent != null) { + return MotionEvent.obtain( + trackedEvent.getDownTime(), + trackedEvent.getEventTime(), + trackedEvent.getAction(), + touch.pointerCount, + pointerProperties, + pointerCoords, + trackedEvent.getMetaState(), + trackedEvent.getButtonState(), + trackedEvent.getXPrecision(), + trackedEvent.getYPrecision(), + trackedEvent.getDeviceId(), + trackedEvent.getEdgeFlags(), + trackedEvent.getSource(), + trackedEvent.getFlags()); + } + + // TODO (kaushikiska) : warn that we are potentially using an untracked + // event in the platform views. return MotionEvent.obtain( touch.downTime.longValue(), touch.eventTime.longValue(),