From 836d174635fe9f72625841b71fdc08065abfadf2 Mon Sep 17 00:00:00 2001 From: gtbluesky Date: Thu, 19 Oct 2023 22:20:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=94=AE=E7=9B=B4=E6=8E=A5=E9=80=80=E5=87=BA?= =?UTF-8?q?APP=E8=80=8C=E4=B8=8D=E6=98=AF=E8=BF=94=E5=9B=9E=E4=B8=8A?= =?UTF-8?q?=E4=B8=80=E4=B8=AAFlutter=E9=A1=B5=E9=9D=A2=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flutter/src/main/ets/embedding/ohos/FlutterAbility.ets | 5 +++++ 1 file changed, 5 insertions(+) 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 dd91f36972..0482733f79 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 @@ -33,6 +33,7 @@ import { DVModelContainer } from '../../view/DynamicView/dynamicView'; import { RootDvModeManager } from '../../plugin/platform/RootDvModelManager'; const TAG = "FlutterAbility"; +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; /** * flutter ohos基础ability,请在让主ability继承自该类。 * 该类主要职责: @@ -72,9 +73,13 @@ export class FlutterAbility extends UIAbility implements Host { console.log('MyAbility onCreate'); globalThis.applicationContext = this.context.getApplicationContext(); + this.context.eventHub.on(EVENT_BACK_PRESS, (_) => { + this.delegate.flutterEngine.getNavigationChannel().popRoute(); + }); } onDestroy() { + this.context.eventHub.off(EVENT_BACK_PRESS); if (this.stillAttachedForEvent("onDestroy")) { this.delegate.onDestroy(); } -- Gitee From 94e0c5ffa441424508be2a5c9f75f34333387ee3 Mon Sep 17 00:00:00 2001 From: gtbluesky Date: Thu, 19 Oct 2023 22:20:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=94=AE=E7=9B=B4=E6=8E=A5=E9=80=80=E5=87=BA?= =?UTF-8?q?APP=E8=80=8C=E4=B8=8D=E6=98=AF=E8=BF=94=E5=9B=9E=E4=B8=8A?= =?UTF-8?q?=E4=B8=80=E4=B8=AAFlutter=E9=A1=B5=E9=9D=A2=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gtbluesky --- .../flutter/src/main/ets/embedding/ohos/FlutterAbility.ets | 5 +++++ 1 file changed, 5 insertions(+) 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 dd91f36972..0482733f79 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 @@ -33,6 +33,7 @@ import { DVModelContainer } from '../../view/DynamicView/dynamicView'; import { RootDvModeManager } from '../../plugin/platform/RootDvModelManager'; const TAG = "FlutterAbility"; +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; /** * flutter ohos基础ability,请在让主ability继承自该类。 * 该类主要职责: @@ -72,9 +73,13 @@ export class FlutterAbility extends UIAbility implements Host { console.log('MyAbility onCreate'); globalThis.applicationContext = this.context.getApplicationContext(); + this.context.eventHub.on(EVENT_BACK_PRESS, (_) => { + this.delegate.flutterEngine.getNavigationChannel().popRoute(); + }); } onDestroy() { + this.context.eventHub.off(EVENT_BACK_PRESS); if (this.stillAttachedForEvent("onDestroy")) { this.delegate.onDestroy(); } -- Gitee