-
Notifications
You must be signed in to change notification settings - Fork 6k
[android] Childview will process its motion events #19662
[android] Childview will process its motion events #19662
Conversation
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); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
packet.putDouble(event.getRawX(pointerIndex)); // physical_x | ||
packet.putDouble(event.getRawY(pointerIndex)); // physical_y |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
1c412b5
to
62d495d
Compare
public boolean performClick() { | ||
return super.performClick(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed?
62d495d
to
835b2d0
Compare
/** | ||
* 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is androidTouchProcessor
NonNull
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, added the annotation
@Override | ||
// Intercept the events here and do not propagate them to the child platform views. |
There was a problem hiding this comment.
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 /** */
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
Matrix screenMatrix = new Matrix(); | ||
screenMatrix.postTranslate(getLeft(), getTop()); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java
Show resolved
Hide resolved
b8a6247
to
5636064
Compare
There was a problem hiding this 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 I removed the engine/shell/platform/android/io/flutter/embedding/android/MotionEventTracker.java Line 53 in fef0fcc
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. |
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 |
There was a problem hiding this comment.
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
@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. |
f2704b6
to
8e72b19
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This pull request is not suitable for automatic merging in its current state.
|
c3410d1
to
0b7ed4a
Compare
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.
0b7ed4a
to
e1aefc5
Compare
Co-authored-by: Kaushik Iska <[email protected]>
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