From d1952086557e503a3cf5ad2275ad37892ae0d4d7 Mon Sep 17 00:00:00 2001 From: dengxiaoyu Date: Thu, 2 Jan 2025 20:27:21 +0800 Subject: [PATCH] fix pc: dubble click back button Signed-off-by: dengxiaoyu --- application/AppScope/app.json | 4 ++-- application/AppScope/app.json5 | 4 ++-- .../src/main/ets/pages/ContinueSwitch.ets | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/application/AppScope/app.json b/application/AppScope/app.json index 18db4803..d4da5707 100644 --- a/application/AppScope/app.json +++ b/application/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 10000030, - "versionName": "1.0.30", + "versionCode": 10000031, + "versionName": "1.0.31", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 12, diff --git a/application/AppScope/app.json5 b/application/AppScope/app.json5 index dc6b2024..0d683326 100644 --- a/application/AppScope/app.json5 +++ b/application/AppScope/app.json5 @@ -16,8 +16,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 10000030, - "versionName": "1.0.30", + "versionCode": 10000031, + "versionName": "1.0.31", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 12, diff --git a/application/entry/src/main/ets/pages/ContinueSwitch.ets b/application/entry/src/main/ets/pages/ContinueSwitch.ets index 927ccbbb..c5663710 100644 --- a/application/entry/src/main/ets/pages/ContinueSwitch.ets +++ b/application/entry/src/main/ets/pages/ContinueSwitch.ets @@ -79,6 +79,7 @@ struct ContinueSwitch { } @State paddingStartNormal: LengthMetrics = LengthMetrics.resource($r('sys.float.margin_left')); @State paddingStartPc: LengthMetrics = LengthMetrics.vp(16); + @State isBacked: boolean = false; private listener: mediaQuery.MediaQueryListener = mediaQuery.matchMediaSync('(dark-mode:true)'); private extContext?: common.UIExtensionContext; private scroller: Scroller = new Scroller(); @@ -286,10 +287,20 @@ struct ContinueSwitch { isSaveIconRequired: false, contentMargin: this.is2in1 ? this.titleBarMarginPc : this.titleBarMargin, onCancel: () => { - if (this.continueSession) { - this.continueSession.sendData({ 'action': 'pop' }) - } else { - logger.error(`${TAG} continueSession is undefined`); + logger.info(`${TAG} onCancel in.`); + if (this.isBacked) { + logger.info(`${TAG} onCancel: The back button has been clicked.`); + return; + } + try { + if (this.continueSession) { + this.continueSession.sendData({ 'action': 'pop' }); + this.isBacked = true; + } else { + logger.error(`${TAG} continueSession is undefined`); + } + } catch (error) { + logger.error(`${TAG} continueSession sendData failed. error.message: ${error.message}`); } } }) -- Gitee