Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Synthesize touch events for hybrid views #19427

Merged
merged 1 commit into from
Jul 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,37 +244,18 @@ public void run() {

@Override
public void onTouch(@NonNull PlatformViewsChannel.PlatformViewTouch touch) {
PointerProperties[] pointerProperties =
parsePointerPropertiesList(touch.rawPointerPropertiesList)
.toArray(new PointerProperties[touch.pointerCount]);
PointerCoords[] pointerCoords =
parsePointerCoordsList(touch.rawPointerCoords, getDisplayDensity())
.toArray(new PointerCoords[touch.pointerCount]);

if (!vdControllers.containsKey(touch.viewId)) {
throw new IllegalStateException(
"Sending touch to an unknown view with id: " + touch.viewId);
}

MotionEvent event =
MotionEvent.obtain(
touch.downTime.longValue(),
touch.eventTime.longValue(),
touch.action,
touch.pointerCount,
pointerProperties,
pointerCoords,
touch.metaState,
touch.buttonState,
touch.xPrecision,
touch.yPrecision,
touch.deviceId,
touch.edgeFlags,
touch.source,
touch.flags);

final int viewId = touch.viewId;
float density = context.getResources().getDisplayMetrics().density;
ensureValidAndroidVersion(Build.VERSION_CODES.KITKAT_WATCH);
vdControllers.get(touch.viewId).dispatchTouchEvent(event);
final MotionEvent event = toMotionEvent(density, touch);
if (vdControllers.containsKey(viewId)) {
vdControllers.get(touch.viewId).dispatchTouchEvent(event);
} else if (platformViews.get(viewId) != null) {
View view = platformViews.get(touch.viewId);
view.dispatchTouchEvent(event);
} else {
throw new IllegalStateException("Sending touch to an unknown view with id: " + viewId);
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Expand Down Expand Up @@ -317,6 +298,32 @@ private void ensureValidAndroidVersion(int minSdkVersion) {
}
};

private static MotionEvent toMotionEvent(
float density, PlatformViewsChannel.PlatformViewTouch touch) {
PointerProperties[] pointerProperties =
parsePointerPropertiesList(touch.rawPointerPropertiesList)
.toArray(new PointerProperties[touch.pointerCount]);
PointerCoords[] pointerCoords =
parsePointerCoordsList(touch.rawPointerCoords, density)
.toArray(new PointerCoords[touch.pointerCount]);

return MotionEvent.obtain(
touch.downTime.longValue(),
touch.eventTime.longValue(),
touch.action,
touch.pointerCount,
pointerProperties,
pointerCoords,
touch.metaState,
touch.buttonState,
touch.xPrecision,
touch.yPrecision,
touch.deviceId,
touch.edgeFlags,
touch.source,
touch.flags);
Comment on lines +317 to +324
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we don't pass any of these values :/ flutter/flutter#60320 (comment)

}

public PlatformViewsController() {
registry = new PlatformViewRegistryImpl();
vdControllers = new HashMap<>();
Expand Down