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

[android] Childview will process its motion events #19662

Merged

Conversation

iskakaushik
Copy link
Contributor

@iskakaushik iskakaushik commented Jul 10, 2020

Prior to this change the parent view, i.e, FlutterView intercepts
all the MotionEvents and sent them to the framework for processing,
after this it makes it so that the ChildView processes the event.

Fixes flutter/flutter#61200

@iskakaushik iskakaushik requested a review from blasten July 10, 2020 22:10
@fluttergithubbot
Copy link
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

mutatorViews.put(viewId, mutatorView);
mutatorView.addView(platformView.getView());
((FlutterView) flutterView).addView(mutatorView);
}

public void attachToFlutterRenderer(FlutterRenderer flutterRenderer) {
androidTouchProcessor = new AndroidTouchProcessor(flutterRenderer, /*trackMotionEvents=*/ true);
Copy link

Choose a reason for hiding this comment

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

wdyt about making AndroidTouchProcessor a singleton, and pass this trackMotionEvents to onTouchEvent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so for moving trackMotionEvents to AndroidTouchProcessor, the only reason i did not have the additional arg onTouch was because, we also need it for onGenericMotionEvent, so Ideally, we would have a MotionEventTrackingAndroidTouchProcessor as a delegate for AndroidTouchProcessor and have it track all events that go through that, but I added an extra constructor param for now.

Comment on lines 204 to 205
packet.putDouble(event.getRawX(pointerIndex)); // physical_x
packet.putDouble(event.getRawY(pointerIndex)); // physical_y
Copy link

Choose a reason for hiding this comment

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

As discussed, we would need a shim for getRawX and getRawY.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, looking into it now.

@iskakaushik iskakaushik force-pushed the consume_input_events_at_child_view branch from 1c412b5 to 62d495d Compare July 13, 2020 19:45
Comment on lines 130 to 131
public boolean performClick() {
return super.performClick();
Copy link

Choose a reason for hiding this comment

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

is this needed?

@iskakaushik iskakaushik force-pushed the consume_input_events_at_child_view branch from 62d495d to 835b2d0 Compare July 13, 2020 20:02
/**
* Initialize the FlutterMutatorView. Use this to set the screenDensity, which will be used to
* correct the final transform matrix.
*/
public FlutterMutatorView(@NonNull Context context, float screenDensity) {
public FlutterMutatorView(
@NonNull Context context, float screenDensity, AndroidTouchProcessor androidTouchProcessor) {
Copy link

Choose a reason for hiding this comment

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

is androidTouchProcessor NonNull?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, added the annotation

Comment on lines 109 to 110
@Override
// Intercept the events here and do not propagate them to the child platform views.
Copy link

Choose a reason for hiding this comment

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

minor nit: for consistency, what about moving the @Override after the javadoc, and using /** */?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good

Comment on lines 123 to 128
Matrix screenMatrix = new Matrix();
screenMatrix.postTranslate(getLeft(), getTop());
Copy link

Choose a reason for hiding this comment

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

did you intend to use getPlatformViewMatrix() here or somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, it is for when we need to support mutations on top of platform views

Copy link

Choose a reason for hiding this comment

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

the mutator view does rotate, translate and scale. right @cyanglaz ?

@iskakaushik iskakaushik force-pushed the consume_input_events_at_child_view branch 4 times, most recently from b8a6247 to 5636064 Compare July 13, 2020 21:16
Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

LGTM. This change will be tested by the e2e android view test.

@iskakaushik iskakaushik added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jul 14, 2020
@blasten blasten removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jul 14, 2020
@blasten
Copy link

blasten commented Jul 14, 2020

@iskakaushik I removed the waiting for tree to go green label. While updating the e2e test, I saw a strange behavior where events looked duplicated. It turns out Android mutates the MotionEvent instance, so we need to call MotionEvent.obtain here

The e2e test wasn't designed to capture these issues because it dispatches unique instances every time. I'm going to change the test so it fires a tap from shell.

@blasten
Copy link

blasten commented Jul 14, 2020

flutter/flutter#61417 is verifying this issue for virtual displays. I will add the same for hybrid e2e. Once we address the mutation issue, then feel free to merge!

@@ -325,10 +329,12 @@ public MotionEvent toMotionEvent(
.toArray(new PointerCoords[touch.pointerCount]);

if (!usingVirtualDiplays && trackedEvent != null) {
// TODO (kaushikiska): investigate why we can not use the tracked
Copy link

Choose a reason for hiding this comment

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

I think the reason is that the action was mutated while it was waiting for the reply from the framework

@iskakaushik
Copy link
Contributor Author

@blasten after my conversation with the android-ui team, it sounds like this approach isn't sound as it translates things from mutator view coordinate space to screen space as opposed to FlutterView space. I'll make amends to fix that as well.

@iskakaushik iskakaushik force-pushed the consume_input_events_at_child_view branch from f2704b6 to 8e72b19 Compare July 14, 2020 17:05
@iskakaushik iskakaushik requested a review from blasten July 14, 2020 17:27
Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

LGTM

@iskakaushik iskakaushik added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jul 14, 2020
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Mac iOS Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jul 14, 2020
@iskakaushik iskakaushik force-pushed the consume_input_events_at_child_view branch from c3410d1 to 0b7ed4a Compare July 14, 2020 19:11
Kaushik Iska added 4 commits July 14, 2020 17:15
Prior to this change the parent view, i.e, FlutterView intercepts
all the MotionEvents and sent them to the framework for processing,
after this it makes it so that the ChildView processes the event.
There was an issue where we were getting it w.r.t screen
as opposed to parent.
@iskakaushik iskakaushik force-pushed the consume_input_events_at_child_view branch from 0b7ed4a to e1aefc5 Compare July 15, 2020 00:15
@blasten blasten merged commit 1832613 into flutter:master Jul 15, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 15, 2020
pcsosinski pushed a commit to pcsosinski/engine that referenced this pull request Jul 15, 2020
pcsosinski pushed a commit that referenced this pull request Jul 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Propagate original MotionEvent to the Android view
4 participants