From 2157d0c073ce2cf4e5827e9a083bd08ed36eb03e Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Thu, 17 Oct 2024 10:58:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E2=80=9C=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E8=BE=93=E5=85=A5=E6=A1=86=E8=BD=AF=E9=94=AE=E7=9B=98?= =?UTF-8?q?=E6=94=B6=E8=B5=B7=E5=86=8D=E5=BC=B9=E8=B5=B7=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=9C=AA=E9=87=8D=E7=BD=AE=E2=80=9D=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=96=B9=E6=B3=95=EF=BC=8C=E9=81=BF=E5=85=8D=E5=9B=A0?= =?UTF-8?q?=E4=B8=BA=E7=B3=BB=E7=BB=9F=E6=94=B6=E8=B5=B7=E8=BD=AF=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E5=B8=A6=E6=9D=A5=E7=9A=84=E5=BC=82=E5=B8=B8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../ets/plugin/editing/TextInputPlugin.ets | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index 60888e9b95..2abc41a2a1 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -78,9 +78,10 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { mEditable: ListenableEditingState; private mRestartInputPending: boolean = false; private plugin: EditingStateWatcher | Any; - private inputTypeNone: string = 'NONE' + private imcFlag: boolean = false; + private inputTypeNone: string = 'NONE'; private keyboardStatus: inputMethod.KeyboardStatus = inputMethod.KeyboardStatus.HIDE; - private inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 } + private inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; constructor(plugin: TextInputPlugin | Any) { this.textConfig = { @@ -143,11 +144,15 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { return; } await this.attach(true); - this.listenKeyBoardEvent(); + if (!this.imcFlag) { + this.listenKeyBoardEvent(); + } } private async hideTextInput(): Promise { this.inputMethodController.detach(); + this.keyboardStatus = inputMethod.KeyboardStatus.NONE; + this.cancelListenKeyBoardEvent(); } async attach(showKeyboard: boolean): Promise { @@ -252,6 +257,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { return; } Log.d(TextInputMethodHandlerImpl.TAG, "listenKeyBoardEvent success"); + this.imcFlag = true; } private insertTextCallback = (text: string) => { @@ -279,8 +285,9 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.keyboardStatus = state; if (state == inputMethod.KeyboardStatus.HIDE) { this.plugin.textInputChannel.onConnectionClosed(this.inputTarget.id); - this.hideTextInput() - this.cancelListenKeyBoardEvent() + /// 收起软键盘时重置键盘状态,避免出现软键盘类型问题 + /// 系统对软键盘的改变也会被该方法监听到,如果继续使用使用detach和取消监听方法会导致其他问题,使用updateAttribute方法去重置,取消监听放在detach方法内,避免出现问题 + this.inputMethodController.updateAttribute({ textInputType: 0, enterKeyType: 1 }); } } @@ -295,6 +302,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.inputMethodController.off('sendFunctionKey', this.sendFunctionKeyCallback); this.inputMethodController.off('sendKeyboardStatus', this.sendKeyboardStatusCallback); this.inputMethodController.off('selectByRange', this.selectByRangeCallback); + this.imcFlag = false; } public clearTextInputClient(): void { -- Gitee