From c11ffcb005c65c89e4eb6d0246dd7a3defb97cfd Mon Sep 17 00:00:00 2001 From: asklie <760956257@qq.com> Date: Fri, 8 Nov 2024 10:59:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96content?= =?UTF-8?q?=E4=B8=BAundefined=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: asklie <760956257@qq.com> --- .../systemchannels/TextInputChannel.ets | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets index 99a9d4f39c..23fe07c7d3 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets @@ -448,20 +448,23 @@ class TextInputCallback implements MethodCallHandler { width: 0, height: 0, } + isListenWindow: boolean = false; constructor(handler: TextInputMethodHandler) { this.textInputMethodHandler = handler; - const context = getContext(this) as Context - window.getLastWindow(context, (err: BusinessError, data: window.Window) => { - this.windowPosition = data.getWindowProperties().windowRect as window.Rect; - data.on('windowRectChange', (rect: window.RectChangeOptions) => { - this.windowPosition = rect.rect as window.Rect; - this.setCursorPosition(); - }) - }) - } setCursorPosition() { + if (!this.isListenWindow) { + this.isListenWindow = true; + const context = getContext(this) as Context + window.getLastWindow(context, (err: BusinessError, data: window.Window) => { + this.windowPosition = data.getWindowProperties().windowRect as window.Rect; + data.on('windowRectChange', (rect: window.RectChangeOptions) => { + this.windowPosition = rect.rect as window.Rect; + this.setCursorPosition(); + }) + }) + } const left = (this.windowPosition.left as number) + (this.cursorPosition.left + this.inputPosotion.left) * this.devicePixelRatio; const top = (this.windowPosition.top as number) + (this.cursorPosition.top + this.inputPosotion.top) * this.devicePixelRatio; this.textInputMethodHandler.setCursorSizeAndPosition({ -- Gitee