-
Notifications
You must be signed in to change notification settings - Fork 6k
Android Embedding Refactor PR31: Integrate platform views with the new embedding and the plugin shim. #9206
Changes from all commits
06485f3
94e260d
64219fa
e878c19
7b30095
6a1f257
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| import android.util.AttributeSet; | ||
| import android.view.KeyEvent; | ||
| import android.view.MotionEvent; | ||
| import android.view.View; | ||
| import android.view.WindowInsets; | ||
| import android.view.accessibility.AccessibilityManager; | ||
| import android.view.accessibility.AccessibilityNodeProvider; | ||
|
|
@@ -36,6 +37,7 @@ | |
| import io.flutter.embedding.engine.renderer.FlutterRenderer; | ||
| import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener; | ||
| import io.flutter.plugin.editing.TextInputPlugin; | ||
| import io.flutter.plugin.platform.PlatformViewsController; | ||
| import io.flutter.view.AccessibilityBridge; | ||
|
|
||
| /** | ||
|
|
@@ -117,6 +119,8 @@ public void onFirstFrameRendered() { | |
| * <li>{@link #renderMode} defaults to {@link RenderMode#surface}.</li> | ||
| * <li>{@link #transparencyMode} defaults to {@link TransparencyMode#opaque}.</li> | ||
| * </ul> | ||
| * {@code FlutterView} requires an {@code Activity} instead of a generic {@code Context} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the signature be changed to actually take an Activity throughout?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought the approach we were talking about last week was that we're keeping the PlatformViewController to have an ApplicationContext constructor but just that we're adding new APIs to it, something like onAttachToActivity. And you can only do presentation.show after you onAttachToActivity. But then FlutterView isn't involved in any of this. It's just between the fragment, which does flutterPluginRegistry.getPlatformViewsController.onAttachActivity(activity), and the PlatformViewsController.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mklim I tried that but compilation failed because apparently Android @xster the reason this was a problem at all is because we can't use an application context. If you ever attempt to |
||
| * to be compatible with {@link PlatformViewsController}. | ||
| */ | ||
| public FlutterView(@NonNull Context context) { | ||
| this(context, null, null, null); | ||
|
|
@@ -127,6 +131,9 @@ public FlutterView(@NonNull Context context) { | |
| * and allows selection of a {@link #renderMode}. | ||
| * <p> | ||
| * {@link #transparencyMode} defaults to {@link TransparencyMode#opaque}. | ||
| * <p> | ||
| * {@code FlutterView} requires an {@code Activity} instead of a generic {@code Context} | ||
| * to be compatible with {@link PlatformViewsController}. | ||
| */ | ||
| public FlutterView(@NonNull Context context, @NonNull RenderMode renderMode) { | ||
| this(context, null, renderMode, null); | ||
|
|
@@ -135,6 +142,9 @@ public FlutterView(@NonNull Context context, @NonNull RenderMode renderMode) { | |
| /** | ||
| * Constructs a {@code FlutterView} programmatically, without any XML attributes, | ||
| * assumes the use of {@link RenderMode#surface}, and allows selection of a {@link #transparencyMode}. | ||
| * <p> | ||
| * {@code FlutterView} requires an {@code Activity} instead of a generic {@code Context} | ||
| * to be compatible with {@link PlatformViewsController}. | ||
| */ | ||
| public FlutterView(@NonNull Context context, @NonNull TransparencyMode transparencyMode) { | ||
| this(context, null, RenderMode.surface, transparencyMode); | ||
|
|
@@ -143,16 +153,21 @@ public FlutterView(@NonNull Context context, @NonNull TransparencyMode transpare | |
| /** | ||
| * Constructs a {@code FlutterView} programmatically, without any XML attributes, and allows | ||
| * a selection of {@link #renderMode} and {@link #transparencyMode}. | ||
| * <p> | ||
| * {@code FlutterView} requires an {@code Activity} instead of a generic {@code Context} | ||
| * to be compatible with {@link PlatformViewsController}. | ||
| */ | ||
| public FlutterView(@NonNull Context context, @NonNull RenderMode renderMode, @NonNull TransparencyMode transparencyMode) { | ||
| this(context, null, renderMode, transparencyMode); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a {@code FlutterSurfaceView} in an XML-inflation-compliant manner. | ||
| * | ||
| * // TODO(mattcarroll): expose renderMode in XML when build system supports R.attr | ||
| * <p> | ||
| * {@code FlutterView} requires an {@code Activity} instead of a generic {@code Context} | ||
| * to be compatible with {@link PlatformViewsController}. | ||
| */ | ||
| // TODO(mattcarroll): expose renderMode in XML when build system supports R.attr | ||
| public FlutterView(@NonNull Context context, @Nullable AttributeSet attrs) { | ||
| this(context, attrs, null, null); | ||
| } | ||
|
|
@@ -367,6 +382,21 @@ public InputConnection onCreateInputConnection(@NonNull EditorInfo outAttrs) { | |
| return textInputPlugin.createInputConnection(this, outAttrs); | ||
| } | ||
|
|
||
| /** | ||
| * Allows a {@code View} that is not currently the input connection target to invoke commands on | ||
| * the {@link android.view.inputmethod.InputMethodManager}, which is otherwise disallowed. | ||
| * <p> | ||
| * Returns true to allow non-input-connection-targets to invoke methods on | ||
| * {@code InputMethodManager}, or false to exclusively allow the input connection target to invoke | ||
| * such methods. | ||
| */ | ||
| @Override | ||
| public boolean checkInputConnectionProxy(View view) { | ||
| return flutterEngine != null | ||
| ? flutterEngine.getPlatformViewsController().checkInputConnectionProxy(view) | ||
| : super.checkInputConnectionProxy(view); | ||
| } | ||
|
|
||
| /** | ||
| * Invoked when key is released. | ||
| * | ||
|
|
@@ -511,7 +541,9 @@ private void resetWillNotDraw(boolean isAccessibilityEnabled, boolean isTouchExp | |
| * See {@link #detachFromFlutterEngine()} for information on how to detach from a | ||
| * {@link FlutterEngine}. | ||
| */ | ||
| public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) { | ||
| public void attachToFlutterEngine( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole thing looks a lot cleaner now. Thanks! |
||
| @NonNull FlutterEngine flutterEngine | ||
| ) { | ||
| Log.d(TAG, "Attaching to a FlutterEngine: " + flutterEngine); | ||
| if (isAttachedToFlutterEngine()) { | ||
| if (flutterEngine == this.flutterEngine) { | ||
|
|
@@ -537,7 +569,7 @@ public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) { | |
| textInputPlugin = new TextInputPlugin( | ||
| this, | ||
| this.flutterEngine.getDartExecutor(), | ||
| null | ||
| this.flutterEngine.getPlatformViewsController() | ||
| ); | ||
| androidKeyProcessor = new AndroidKeyProcessor( | ||
| this.flutterEngine.getKeyEventChannel(), | ||
|
|
@@ -549,16 +581,18 @@ public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) { | |
| flutterEngine.getAccessibilityChannel(), | ||
| (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE), | ||
| getContext().getContentResolver(), | ||
| // TODO(mattcaroll): plumb the platform views controller to the accessibility bridge. | ||
| // https://github.com/flutter/flutter/issues/29618 | ||
| null | ||
| this.flutterEngine.getPlatformViewsController() | ||
| ); | ||
| accessibilityBridge.setOnAccessibilityChangeListener(onAccessibilityChangeListener); | ||
| resetWillNotDraw( | ||
| accessibilityBridge.isAccessibilityEnabled(), | ||
| accessibilityBridge.isTouchExplorationEnabled() | ||
| ); | ||
|
|
||
| // Connect AccessibilityBridge to the PlatformViewsController within the FlutterEngine. | ||
| // This allows platform Views to hook into Flutter's overall accessibility system. | ||
| this.flutterEngine.getPlatformViewsController().attachAccessibilityBridge(accessibilityBridge); | ||
|
|
||
| // Inform the Android framework that it should retrieve a new InputConnection | ||
| // now that an engine is attached. | ||
| // TODO(mattcarroll): once this is proven to work, move this line ot TextInputPlugin | ||
|
|
@@ -597,6 +631,9 @@ public void detachFromFlutterEngine() { | |
| listener.onFlutterEngineDetachedFromFlutterView(); | ||
| } | ||
|
|
||
| // Disconnect the FlutterEngine's PlatformViewsController from the AccessibilityBridge. | ||
| flutterEngine.getPlatformViewsController().detachAccessibiltyBridge(); | ||
|
|
||
| // Disconnect and clean up the AccessibilityBridge. | ||
| accessibilityBridge.release(); | ||
| accessibilityBridge = null; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.