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 60888e9b95c7058aa9f3b6b1cbe2bea2aedd4510..2abc41a2a1838a3b2338f0d109dc39c761aa8e31 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 {