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 aba17a326c8c3d8bcb9c19ccedb35dfec4477ad5..2c260f49bd816c7286069455ae187005e7a1067c 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 @@ -174,12 +174,12 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.listenNoShowKeyboard() } - /// 通过监听规避区域内,是否有软键盘区域来进行监听。该方法在回到桌面和锁屏依然可以正常监听 + /// 通过监听键盘高度,决定是否需要弹出键盘 listenShowKeyboard() { let windowStage = FlutterManager.getInstance() .getWindowStage(FlutterManager.getInstance().getUIAbility(getContext(this))); windowStage.getMainWindow((err: BusinessError, currentWindow ) => { - currentWindow.on('avoidAreaChange', this.avoidAreaChangeCallback) + currentWindow.on('keyboardHeightChange', this.keyboardHeightChangeCallback); }); } @@ -188,7 +188,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { let windowStage = FlutterManager.getInstance() .getWindowStage(FlutterManager.getInstance().getUIAbility(getContext(this))); windowStage.getMainWindow((err: BusinessError, currentWindow ) => { - currentWindow.off('avoidAreaChange', this.avoidAreaChangeCallback) + currentWindow.off('keyboardHeightChange', this.keyboardHeightChangeCallback); }); } @@ -209,6 +209,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } }; await this.inputMethodController.attach(false, textConfig); + this.firstShow = true } catch (err) { Log.e(TextInputMethodHandlerImpl.TAG, "Failed to attach:" + JSON.stringify(err)); } @@ -235,7 +236,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.mRestartInputPending = true; this.mEditable.addEditingStateListener(this.plugin); - this.firstShow = true } canShowTextInput(): boolean { @@ -316,12 +316,9 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { }) } - private avoidAreaChangeCallback = (data: window.AvoidAreaOptions) => { + private keyboardHeightChangeCallback = (data: number) => { console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); - if (data.type !== window.AvoidAreaType.TYPE_KEYBOARD) { - return; - } - if (data.area.bottomRect.height == 0) { + if (data == 0) { this.firstShow = true } else { this.firstShow = false