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 af3a61cd6db2529265379012a77070c8fd53441a..8c541c79ba1f32a771644f817c88cae8995b30fe 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 @@ -39,7 +39,6 @@ import ApplicationInfoLoader from '../engine/loader/ApplicationInfoLoader'; import { AccessibilityManager } from '../../view/AccessibilityBridge'; const TAG = "FlutterAbility"; -const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; /** * flutter ohos基础ability,请在让主ability继承自该类。 @@ -92,10 +91,6 @@ 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(); - }); let observer:errorManager.ErrorObserver = { onUnhandledException(errorMsg) { Log.e(TAG, "onUnhandledException, errorMsg:", errorMsg); @@ -114,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 480371d80703aafa8be51b208ed052bb921375bc..f9f09d12c458196bbd6117fb155b9b7a53364303 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 { 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 5af7b9cf9dd2343f47f2bbbec760715144062454..f0ff44d2b13583af08b9d8907a34cf743d7a35e4 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);