From a02621dee6b4fa08199905b1f0705b47e1db27a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E4=B8=9C=E6=B5=B7?= Date: Wed, 7 May 2025 16:25:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=E7=9A=84API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/entryability/EntryAbility.ets | 5 ++--- entry/src/main/ets/pages/CommentPage.ets | 4 ++-- entry/src/main/ets/pages/InputPage.ets | 2 +- entry/src/main/ets/pages/LivePage.ets | 6 +++--- entry/src/main/ets/utils/WindowUtil.ets | 10 +++++----- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 9068416..124592d 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -138,10 +138,9 @@ export default class EntryAbility extends UIAbility { // Main window is created, set main page for this ability Logger.info('Ability onWindowStageCreate'); - WindowUtil.requestFullScreen(windowStage, this.context); - WindowUtil.updateStatusBarColor(this.context, true); - windowStage.loadContent('pages/LivePage', (err) => { + WindowUtil.requestFullScreen(windowStage, this.context); + WindowUtil.updateStatusBarColor(this.context, true); if (err.code) { Logger.error(JSON.stringify(err) ?? ''); return; diff --git a/entry/src/main/ets/pages/CommentPage.ets b/entry/src/main/ets/pages/CommentPage.ets index 0fbae5e..c3747aa 100644 --- a/entry/src/main/ets/pages/CommentPage.ets +++ b/entry/src/main/ets/pages/CommentPage.ets @@ -50,8 +50,8 @@ export struct CommentPage { @State @Watch("onLiveListUpdated") liveList: Array = []; @Link @Watch("onActiveUpdated") activeItem: number; scroller: Scroller = new Scroller(); - listenerIsPhone = mediaquery.matchMediaSync('(orientation:landscape)'); - private context = getContext(this) as common.UIAbilityContext; + listenerIsPhone = this.getUIContext().getMediaQuery().matchMediaSync('(orientation:landscape)'); + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) { this.isPhone = !mediaQueryResult.matches; diff --git a/entry/src/main/ets/pages/InputPage.ets b/entry/src/main/ets/pages/InputPage.ets index b3ab066..f4c2050 100644 --- a/entry/src/main/ets/pages/InputPage.ets +++ b/entry/src/main/ets/pages/InputPage.ets @@ -22,7 +22,7 @@ import Logger from '../utils/Logger'; @Component struct InputPage { @StorageLink('inputText') inputText: string = ''; - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; onPageShow(): void { Logger.info(this.inputText); diff --git a/entry/src/main/ets/pages/LivePage.ets b/entry/src/main/ets/pages/LivePage.ets index 2f717d3..31ffda1 100644 --- a/entry/src/main/ets/pages/LivePage.ets +++ b/entry/src/main/ets/pages/LivePage.ets @@ -55,7 +55,7 @@ struct LivePage { }; @State isPhone: boolean = false; videoController: VideoController = new VideoController(); - listenerIsPhone = mediaquery.matchMediaSync('(orientation:landscape)'); + listenerIsPhone = this.getUIContext().getMediaQuery().matchMediaSync('(orientation:landscape)'); onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) { this.isPhone = !mediaQueryResult.matches; @@ -92,7 +92,7 @@ struct LivePage { .width($r('app.integer.comm_btn_width2')) .height($r('app.integer.comm_btn_width2')) .onClick(() => { - router.back(); + this.getUIContext().getRouter().back(); }) } .margin({ @@ -173,7 +173,7 @@ struct LivePage { .width($r('app.integer.comm_btn_width2')) .height($r('app.integer.comm_btn_width2')) .onClick(() => { - router.back(); + this.getUIContext().getRouter().back(); }) } .margin({ right: $r('app.integer.normal_component_list_margin_3') }) diff --git a/entry/src/main/ets/utils/WindowUtil.ets b/entry/src/main/ets/utils/WindowUtil.ets index d0468e2..1b570d8 100644 --- a/entry/src/main/ets/utils/WindowUtil.ets +++ b/entry/src/main/ets/utils/WindowUtil.ets @@ -47,7 +47,7 @@ export class WindowUtil { let area: window.AvoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); let naviBarArea: window.AvoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); Logger.info(TAG, - 'Succeeded get the window navigation indicator HEIGHT: ' + px2vp(naviBarArea.bottomRect.height) + ' area: ' + + 'Succeeded get the window navigation indicator HEIGHT: ' + data.getUIContext().px2vp(naviBarArea.bottomRect.height) + ' area: ' + JSON.stringify(naviBarArea)); WindowUtil.getDeviceSize(context, area, naviBarArea); if (area.topRect.height > 0) { @@ -68,10 +68,10 @@ export class WindowUtil { // Get device height window.getLastWindow(context).then((data: window.Window) => { let properties = data.getWindowProperties(); - AppStorage.setOrCreate('statusBarHeight', px2vp(area.topRect.height)); - AppStorage.setOrCreate('naviIndicatorHeight', px2vp(naviBarArea.bottomRect.height)); - AppStorage.setOrCreate('deviceHeight', px2vp(properties.windowRect.height)); - AppStorage.setOrCreate('deviceWidth', px2vp(properties.windowRect.width)); + AppStorage.setOrCreate('statusBarHeight', data.getUIContext().px2vp(area.topRect.height)); + AppStorage.setOrCreate('naviIndicatorHeight', data.getUIContext().px2vp(naviBarArea.bottomRect.height)); + AppStorage.setOrCreate('deviceHeight', data.getUIContext().px2vp(properties.windowRect.height)); + AppStorage.setOrCreate('deviceWidth', data.getUIContext().px2vp(properties.windowRect.width)); }); } -- Gitee