From 9515931232f1a54dea40b3ca6962efaba24df168 Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Thu, 7 Nov 2024 08:25:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=85=88?= =?UTF-8?q?=E6=94=B6=E8=B5=B7=E8=BD=AF=E9=94=AE=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../src/main/ets/embedding/ohos/FlutterAbility.ets | 10 ++++++++-- .../flutter/src/main/ets/view/FlutterView.ets | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index af3a61cd6d..6863ccbb79 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -37,6 +37,7 @@ import FlutterManager from './FlutterManager'; import { FlutterView } from '../../view/FlutterView'; import ApplicationInfoLoader from '../engine/loader/ApplicationInfoLoader'; import { AccessibilityManager } from '../../view/AccessibilityBridge'; +import inputMethod from '@ohos.inputMethod'; const TAG = "FlutterAbility"; const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; @@ -53,6 +54,7 @@ export class FlutterAbility extends UIAbility implements Host { private mainWindow?: window.Window | null; private errorManagerId:number = 0; private accessibilityManager?: AccessibilityManager | null; + private inputMethodController: inputMethod.InputMethodController = inputMethod.getController(); getFlutterView(): FlutterView | null { return this.flutterView; @@ -93,8 +95,12 @@ export class FlutterAbility extends UIAbility implements Host { Log.i(TAG, 'MyAbility onCreate'); this.context.eventHub.on(EVENT_BACK_PRESS, () => { - this.delegate?.flutterEngine?.getNavigationChannel()?.popRoute(); - this.delegate?.flutterEngine?.getPlatformViewsController()?.setBackNodeControllers(); + if (this.flutterView?.getKeyboardHeight() == 0) { + this.delegate?.flutterEngine?.getNavigationChannel()?.popRoute(); + this.delegate?.flutterEngine?.getPlatformViewsController()?.setBackNodeControllers(); + } else { + this.inputMethodController.detach(); + } }); let observer:errorManager.ErrorObserver = { onUnhandledException(errorMsg) { 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 5af7b9cf9d..f0ff44d2b1 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 @@ -247,6 +247,10 @@ export class FlutterView { return this.dVModel } + getKeyboardHeight() { + return this.keyboardAvoidArea.bottomRect.height + } + onDestroy() { try { this.mainWindow?.off('windowSizeChange', this.windowSizeChangeCallback); -- Gitee From 8380aace8e08989a653392307bde14793f9b49d2 Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Thu, 7 Nov 2024 20:16:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0delegate=EF=BC=8C=E4=BB=A5=E9=80=82?= =?UTF-8?q?=E9=85=8DFlutterAbility=E5=92=8CFlutterEntry=E4=B8=A4=E7=A7=8D?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../src/main/ets/embedding/ohos/FlutterAbility.ets | 13 +------------ .../ohos/FlutterAbilityAndEntryDelegate.ets | 14 +++++++++++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index 6863ccbb79..8c541c79ba 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -37,10 +37,8 @@ import FlutterManager from './FlutterManager'; import { FlutterView } from '../../view/FlutterView'; import ApplicationInfoLoader from '../engine/loader/ApplicationInfoLoader'; import { AccessibilityManager } from '../../view/AccessibilityBridge'; -import inputMethod from '@ohos.inputMethod'; const TAG = "FlutterAbility"; -const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; /** * flutter ohos基础ability,请在让主ability继承自该类。 @@ -54,7 +52,6 @@ export class FlutterAbility extends UIAbility implements Host { private mainWindow?: window.Window | null; private errorManagerId:number = 0; private accessibilityManager?: AccessibilityManager | null; - private inputMethodController: inputMethod.InputMethodController = inputMethod.getController(); getFlutterView(): FlutterView | null { return this.flutterView; @@ -94,14 +91,6 @@ export class FlutterAbility extends UIAbility implements Host { Log.i(TAG, 'MyAbility onCreate'); - this.context.eventHub.on(EVENT_BACK_PRESS, () => { - if (this.flutterView?.getKeyboardHeight() == 0) { - this.delegate?.flutterEngine?.getNavigationChannel()?.popRoute(); - this.delegate?.flutterEngine?.getPlatformViewsController()?.setBackNodeControllers(); - } else { - this.inputMethodController.detach(); - } - }); let observer:errorManager.ErrorObserver = { onUnhandledException(errorMsg) { Log.e(TAG, "onUnhandledException, errorMsg:", errorMsg); @@ -120,7 +109,7 @@ export class FlutterAbility extends UIAbility implements Host { onDestroy() { FlutterManager.getInstance().popUIAbility(this); - this.context.eventHub.off(EVENT_BACK_PRESS); + errorManager.off('error', this.errorManagerId); if (this.flutterView != null) { 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 480371d807..f9f09d12c4 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 @@ -36,10 +36,12 @@ import FlutterNapi from '../engine/FlutterNapi'; import { FlutterView } from '../../view/FlutterView'; import FlutterManager from './FlutterManager'; import Any from '../../plugin/common/Any'; +import inputMethod from '@ohos.inputMethod'; const TAG = "FlutterAbilityDelegate"; const PLUGINS_RESTORATION_BUNDLE_KEY = "plugins"; const FRAMEWORK_RESTORATION_BUNDLE_KEY = "framework"; +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; /** * 主要职责: @@ -55,7 +57,8 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent protected isFlutterEngineFromHostOrCache: boolean = false; private engineGroup?: FlutterEngineGroup; private isHost:boolean = false; - private flutterView?: FlutterView + private flutterView?: FlutterView; + private inputMethodController: inputMethod.InputMethodController = inputMethod.getController(); constructor(host?: Host) { this.host = host; @@ -94,6 +97,14 @@ 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.inputMethodController.detach(); + } + }); } /** @@ -302,6 +313,7 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent } this.isAttached = false; + this.context?.eventHub.off(EVENT_BACK_PRESS); } onLowMemory(): void { -- Gitee