This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[android] Childview will process its motion events #19662
Merged
blasten
merged 4 commits into
flutter:master
from
iskakaushik:consume_input_events_at_child_view
Jul 15, 2020
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
replace getRawX and getRawY with shims
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package io.flutter.embedding.engine.mutatorsstack; | ||
|
|
||
| import android.annotation.SuppressLint; | ||
| import android.content.Context; | ||
| import android.graphics.Canvas; | ||
| import android.graphics.Matrix; | ||
|
|
@@ -26,17 +27,19 @@ public class FlutterMutatorView extends FrameLayout { | |
| * correct the final transform matrix. | ||
| */ | ||
| public FlutterMutatorView( | ||
| @NonNull Context context, float screenDensity, AndroidTouchProcessor androidTouchProcessor) { | ||
| @NonNull Context context, | ||
| float screenDensity, | ||
| @NonNull AndroidTouchProcessor androidTouchProcessor) { | ||
| super(context, null); | ||
| this.screenDensity = screenDensity; | ||
| this.androidTouchProcessor = androidTouchProcessor; | ||
| } | ||
|
|
||
| /** Initialize the FlutterMutatorView. */ | ||
| public FlutterMutatorView(@NonNull Context context, AndroidTouchProcessor androidTouchProcessor) { | ||
| public FlutterMutatorView(@NonNull Context context) { | ||
| super(context, null); | ||
| this.screenDensity = 1; | ||
| this.androidTouchProcessor = androidTouchProcessor; | ||
| this.androidTouchProcessor = null; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -78,7 +81,14 @@ public void dispatchDraw(Canvas canvas) { | |
| // Apply all the transforms on the child canvas. | ||
| canvas.save(); | ||
|
|
||
| canvas.concat(getPlatformViewMatrix()); | ||
| super.dispatchDraw(canvas); | ||
| canvas.restore(); | ||
| } | ||
|
|
||
| private Matrix getPlatformViewMatrix() { | ||
| Matrix finalMatrix = new Matrix(mutatorsStack.getFinalMatrix()); | ||
|
|
||
| // Reverse scale based on screen scale. | ||
| // | ||
| // The Android frame is set based on the logical resolution instead of physical. | ||
|
|
@@ -87,6 +97,7 @@ public void dispatchDraw(Canvas canvas) { | |
| // 500 points in Android. And until this point, we did all the calculation based on the flow | ||
| // resolution. So we need to scale down to match Android's logical resolution. | ||
| finalMatrix.preScale(1 / screenDensity, 1 / screenDensity); | ||
|
|
||
| // Reverse the current offset. | ||
| // | ||
| // The frame of this view includes the final offset of the bounding rect. | ||
|
|
@@ -95,19 +106,27 @@ public void dispatchDraw(Canvas canvas) { | |
| // all the clipping paths | ||
| finalMatrix.postTranslate(-left, -top); | ||
|
|
||
| canvas.concat(finalMatrix); | ||
| super.dispatchDraw(canvas); | ||
| canvas.restore(); | ||
| return finalMatrix; | ||
| } | ||
|
|
||
| /** Intercept the events here and do not propagate them to the child platform views. */ | ||
| @Override | ||
| // Intercept the events here and do not propagate them to the child platform views. | ||
| public boolean onInterceptTouchEvent(MotionEvent event) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressLint("ClickableViewAccessibility") | ||
| public boolean onTouchEvent(MotionEvent event) { | ||
| return androidTouchProcessor.onTouchEvent(event); | ||
| if (androidTouchProcessor == null) { | ||
| return super.onTouchEvent(event); | ||
| } | ||
|
|
||
| // Mutator view itself doesn't rotate, scale, skew, etc. | ||
| // we only need to account for translation. | ||
| Matrix screenMatrix = new Matrix(); | ||
| screenMatrix.postTranslate(getLeft(), getTop()); | ||
|
||
|
|
||
| return androidTouchProcessor.onTouchEvent(event, screenMatrix); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.