From 571fc3f863fb131585cd12c812ee6145027355e2 Mon Sep 17 00:00:00 2001 From: chenzhensheng79 <15118029047@139.com> Date: Tue, 21 Jan 2025 15:55:24 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Flutter=E6=89=8B=E5=8A=BF=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shijie --- .../ohos/FlutterAbilityAndEntryDelegate.ets | 10 ---------- .../flutter/src/main/ets/view/FlutterView.ets | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets index 1f3c735b0e..4a0c5e3e80 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets @@ -39,7 +39,6 @@ import Any from '../../plugin/common/Any'; const TAG = "FlutterAbilityDelegate"; const PLUGINS_RESTORATION_BUNDLE_KEY = "plugins"; const FRAMEWORK_RESTORATION_BUNDLE_KEY = "framework"; -const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; /** * 主要职责: @@ -92,14 +91,6 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent this.flutterView.attachToFlutterEngine(this.flutterEngine!!); } this.host?.configureFlutterEngine(this.flutterEngine!!); - this.context.eventHub.on(EVENT_BACK_PRESS, () => { - if (this.flutterView?.getKeyboardHeight() == 0) { - this.flutterEngine?.getNavigationChannel()?.popRoute(); - this.flutterEngine?.getPlatformViewsController()?.setBackNodeControllers(); - } else { - this.flutterEngine?.getTextInputChannel()?.textInputMethodHandler?.hide(); - } - }); } /** @@ -307,7 +298,6 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent } this.isAttached = false; - this.context?.eventHub.off(EVENT_BACK_PRESS); } onLowMemory(): void { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets index f402b642b7..d835d9cb13 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets @@ -30,6 +30,7 @@ import { accessibility } from '@kit.AccessibilityKit'; import TextInputPlugin from '../plugin/editing/TextInputPlugin'; const TAG = "FlutterViewTag"; +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; export class ViewportMetrics { devicePixelRatio: number = 1.0; @@ -184,6 +185,7 @@ export class FlutterView { private mouseCursorPlugin?: MouseCursorPlugin; private textInputPlugin?: TextInputPlugin; private uiContext?: UIContext | undefined; + private context: Context; private settings?: Settings; private mFirstFrameListeners: ArrayList; private isFlutterUiDisplayed: boolean = false; @@ -199,7 +201,8 @@ export class FlutterView { private keyboardAvoidArea: window.AvoidArea; constructor(viewId: string, context: Context) { - this.id = viewId + this.id = viewId; + this.context = context; this.displayInfo = display.getDefaultDisplaySync(); this.viewportMetrics.devicePixelRatio = this.displayInfo?.densityPixels; @@ -433,6 +436,15 @@ export class FlutterView { } this.onAreaChange(newArea, true); + this.context.eventHub.on(EVENT_BACK_PRESS, () => { + if (this?.getKeyboardHeight() == 0) { + this.flutterEngine?.getNavigationChannel()?.popRoute(); + this.flutterEngine?.getPlatformViewsController()?.setBackNodeControllers(); + } else { + this.flutterEngine?.getTextInputChannel()?.textInputMethodHandler?.hide(); + } + }); + let windowId = this.mainWindow?.getWindowProperties()?.id ?? 0 this.mouseCursorPlugin = new MouseCursorPlugin(windowId, this.flutterEngine?.getMouseCursorChannel()!); this.textInputPlugin = new TextInputPlugin(this.flutterEngine?.getTextInputChannel()!); @@ -459,6 +471,7 @@ export class FlutterView { this.flutterEngine = null; this.keyboardManager = null; this.textInputPlugin?.destroy(); + this.context.eventHub.off(EVENT_BACK_PRESS); } onWindowCreated() { -- Gitee From 2b6c5c930f99e5e74e22343589fb5c5a4c64e6c9 Mon Sep 17 00:00:00 2001 From: shijie Date: Tue, 21 Jan 2025 10:54:25 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shijie --- .../flutter_embedding/flutter/src/main/ets/view/FlutterView.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets index d835d9cb13..5931f9f636 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets @@ -30,7 +30,7 @@ import { accessibility } from '@kit.AccessibilityKit'; import TextInputPlugin from '../plugin/editing/TextInputPlugin'; const TAG = "FlutterViewTag"; -const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; +const EVENT_BACK_PRES = 'EVENT_BACK_PRESS'; export class ViewportMetrics { devicePixelRatio: number = 1.0; -- Gitee From 5ad615da0b43088198793ceeaaf482dad714df11 Mon Sep 17 00:00:00 2001 From: shijie Date: Tue, 21 Jan 2025 11:25:10 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=9B=9E=E6=BB=9A=E5=8F=8A=E8=AF=84=E5=AE=A1=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shijie --- .../flutter/src/main/ets/view/FlutterView.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets index 5931f9f636..320f9923b2 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets @@ -30,7 +30,7 @@ import { accessibility } from '@kit.AccessibilityKit'; import TextInputPlugin from '../plugin/editing/TextInputPlugin'; const TAG = "FlutterViewTag"; -const EVENT_BACK_PRES = 'EVENT_BACK_PRESS'; +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; export class ViewportMetrics { devicePixelRatio: number = 1.0; @@ -471,7 +471,7 @@ export class FlutterView { this.flutterEngine = null; this.keyboardManager = null; this.textInputPlugin?.destroy(); - this.context.eventHub.off(EVENT_BACK_PRESS); + this.context?.eventHub.off(EVENT_BACK_PRESS); } onWindowCreated() { -- Gitee