Commit 676d14dc authored by yangwu.jia's avatar yangwu.jia

fix textfield bug

parent 35811132
package com.idlefish.flutterboost;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Rect;
......@@ -34,6 +35,7 @@ import io.flutter.embedding.engine.FlutterEngine;
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.PlatformPlugin;
import io.flutter.view.AccessibilityBridge;
public class XFlutterView extends FrameLayout {
......@@ -430,6 +432,7 @@ public class XFlutterView extends FrameLayout {
* {@link FlutterEngine}.
*/
public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) {
Log.d(TAG, "attachToFlutterEngine()");
if (isAttachedToFlutterEngine()) {
if (flutterEngine == this.flutterEngine) {
......@@ -447,14 +450,18 @@ public class XFlutterView extends FrameLayout {
// Instruct our FlutterRenderer that we are now its designated RenderSurface.
this.flutterEngine.getRenderer().attachToRenderSurface(renderSurface);
// Initialize various components that know how to process Android View I/O
// in a way that Flutter understands.
if(textInputPlugin==null){
textInputPlugin = new XTextInputPlugin(
this,
flutterEngine.getTextInputChannel()
);
}
textInputPlugin.setTextInputMethodHandler();
textInputPlugin.getInputMethodManager().restartInput(this);
textInputPlugin = new XTextInputPlugin(
this,
this.flutterEngine.getDartExecutor()
);
androidKeyProcessor = new XAndroidKeyProcessor(
this.flutterEngine.getKeyEventChannel(),
textInputPlugin
......@@ -479,7 +486,6 @@ public class XFlutterView extends FrameLayout {
accessibilityBridge.isAccessibilityEnabled(),
accessibilityBridge.isTouchExplorationEnabled()
);
textInputPlugin.getInputMethodManager().restartInput(this);
}
......@@ -527,8 +533,9 @@ public class XFlutterView extends FrameLayout {
// now that the engine is detached. The new InputConnection will be null, which
// signifies that this View does not process input (until a new engine is attached).
// TODO(mattcarroll): once this is proven to work, move this line ot TextInputPlugin
textInputPlugin.getInputMethodManager().restartInput(this);
// textInputPlugin.getInputMethodManager().restartInput(this);
// Instruct our FlutterRenderer that we are no longer interested in being its RenderSurface.
// this.textInputPlugin.getInputMethodManager().restartInput(this);
flutterEngine.getRenderer().detachFromRenderSurface();
flutterEngine = null;
......
......@@ -24,7 +24,6 @@ public class XTextInputPlugin {
@NonNull
private final InputMethodManager mImm;
@NonNull
private final TextInputChannel textInputChannel;
private int mClient = 0;
@Nullable
private TextInputChannel.Configuration configuration;
......@@ -33,13 +32,17 @@ public class XTextInputPlugin {
private boolean mRestartInputPending;
@Nullable
private InputConnection lastInputConnection;
public XTextInputPlugin(View view, @NonNull DartExecutor dartExecutor) {
private TextInputChannel textInputChannel;
public XTextInputPlugin(View view, TextInputChannel mTextInputChannel) {
mView = view;
mImm = (InputMethodManager) view.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
textInputChannel=mTextInputChannel;
}
textInputChannel = new TextInputChannel(dartExecutor);
public void setTextInputMethodHandler( ){
textInputChannel.setTextInputMethodHandler(new TextInputChannel.TextInputMethodHandler() {
@Override
public void show() {
......@@ -173,6 +176,7 @@ public class XTextInputPlugin {
}
private void showTextInput(View view) {
if(view==null) return;
view.requestFocus();
mImm.showSoftInput(view, 0);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment