From 8dc0fc8c71dc57b0626faacbec4ac5129612588c Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Sun, 29 Sep 2024 17:06:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E9=81=BF=E5=85=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E4=B8=8E=E5=85=B6=E4=BB=96=E5=BA=94=E7=94=A8=E6=8A=A2=E5=8D=A0?= =?UTF-8?q?=E8=AF=A5=E7=9B=91=E5=90=AC=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E4=BF=AE=E6=94=B9=E9=94=AE=E7=9B=98=E5=BC=B9?= =?UTF-8?q?=E5=87=BA=E9=80=BB=E8=BE=91=EF=BC=8C=E4=B8=8D=E5=9C=A8=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEclient=E6=97=B6=E5=AF=B9=E6=98=AF=E5=90=A6=E5=BC=B9?= =?UTF-8?q?=E5=87=BA=E9=94=AE=E7=9B=98=E5=81=9A=E5=86=B3=E5=AE=9A?= 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 | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 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 aba17a326c..8924615383 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,15 +316,12 @@ 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) { - this.firstShow = true + if (data == 0) { + this.showType = keyboardType.ENTRY } else { - this.firstShow = false + this.showType = keyboardType.NONE } } -- Gitee From 2e8edd5e5ce4c9925f62a262bb5cb0a748c43373 Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Sun, 29 Sep 2024 17:07:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=9C=B0=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../flutter/src/main/ets/plugin/editing/TextInputPlugin.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 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 8924615383..2c260f49bd 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 @@ -319,9 +319,9 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { private keyboardHeightChangeCallback = (data: number) => { console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + JSON.stringify(data)); if (data == 0) { - this.showType = keyboardType.ENTRY + this.firstShow = true } else { - this.showType = keyboardType.NONE + this.firstShow = false } } -- Gitee