From c861bdd3c8e486dd65c32eed6a7733bbd69f33c5 Mon Sep 17 00:00:00 2001 From: kuangning <2540487435@qq.com> Date: Thu, 8 May 2025 14:06:08 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Aapi=E5=8D=87=E7=BA=A7=E8=87=B316?= =?UTF-8?q?=EF=BC=8C=E5=BA=9F=E5=BC=83api=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 2 +- entry/src/main/ets/pages/Index.ets | 2 +- features/longList/src/main/ets/pages/Index.ets | 8 ++++---- .../longList/src/main/ets/utils/BreakpointSystem.ets | 12 +++++++++--- features/longList/src/main/ets/view/HomeContent.ets | 4 ++-- .../src/main/ets/view/WaterFlowLivingView.ets | 4 ++-- .../longList/src/main/ets/view/WaterFlowView.ets | 8 ++++---- features/video/src/main/ets/components/ExitVideo.ets | 4 ++-- features/video/src/main/ets/pages/Index.ets | 2 +- features/web/src/main/ets/pages/IndexPage.ets | 12 ++++++------ features/web/src/main/ets/pages/OrderConfirmPage.ets | 10 +++++----- 11 files changed, 37 insertions(+), 31 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index 4d15135..c22fe51 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -6,7 +6,7 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", + "compatibleSdkVersion": "5.0.4(16)", "runtimeOS": "HarmonyOS", "buildOption": { "strictMode": { diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index dd18aed..f2b9a71 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -17,7 +17,7 @@ import { common, Want } from '@kit.AbilityKit'; @Entry @Component struct Index { - private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + private context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; build() { Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween }) { diff --git a/features/longList/src/main/ets/pages/Index.ets b/features/longList/src/main/ets/pages/Index.ets index d183dd1..723336f 100644 --- a/features/longList/src/main/ets/pages/Index.ets +++ b/features/longList/src/main/ets/pages/Index.ets @@ -29,7 +29,7 @@ struct Index { @StorageLink(CommonConstants.LANGUAGE) language: string = CommonConstants.CHINESE_LANGUAGE; @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack(); @State windowsHeight: number = CommonConstants.NUMBER_DEFAULT_VALUE; - private breakpointSystem: BreakpointSystem = new BreakpointSystem(); + private breakpointSystem: BreakpointSystem = new BreakpointSystem(this.getUIContext()); private indexPage: string = CommonConstants.CHINESE_LANGUAGE; onBackPress() { @@ -60,13 +60,13 @@ struct Index { this.indexPage = HomeConstants.INDEX_PAGE_EN; } this.pageInfos.pushPath({ name: this.indexPage }, false); - this.windowsHeight = px2vp(display.getDefaultDisplaySync().height); + this.windowsHeight = this.getUIContext().px2vp(display.getDefaultDisplaySync().height); this.breakpointSystem.register(); - window.getLastWindow(getContext()).then(win => { + window.getLastWindow(this.getUIContext().getHostContext()).then(win => { win.setWindowLayoutFullScreen(true); let area = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); let height = area.topRect.height; - let vpHeight = px2vp(height); + let vpHeight = this.getUIContext().px2vp(height); AppStorage.setOrCreate('topHeight', vpHeight); }); } diff --git a/features/longList/src/main/ets/utils/BreakpointSystem.ets b/features/longList/src/main/ets/utils/BreakpointSystem.ets index f0ede60..310e444 100644 --- a/features/longList/src/main/ets/utils/BreakpointSystem.ets +++ b/features/longList/src/main/ets/utils/BreakpointSystem.ets @@ -52,9 +52,15 @@ export class BreakpointType { export class BreakpointSystem { private readonly listenerKey = 'change'; private currentBreakpoint: string = BreakpointConstants.BREAKPOINT_SM; - private smListener: mediaQuery.MediaQueryListener = mediaQuery.matchMediaSync(BreakpointConstants.RANGE_SM); - private mdListener: mediaQuery.MediaQueryListener = mediaQuery.matchMediaSync(BreakpointConstants.RANGE_MD); - private lgListener: mediaQuery.MediaQueryListener = mediaQuery.matchMediaSync(BreakpointConstants.RANGE_LG); + private smListener: mediaQuery.MediaQueryListener; + private mdListener: mediaQuery.MediaQueryListener; + private lgListener: mediaQuery.MediaQueryListener; + + constructor(context: UIContext) { + this.smListener = context.getMediaQuery().matchMediaSync(BreakpointConstants.RANGE_SM); + this.mdListener = context.getMediaQuery().matchMediaSync(BreakpointConstants.RANGE_MD); + this.lgListener = context.getMediaQuery().matchMediaSync(BreakpointConstants.RANGE_LG); + } private updateCurrentBreakpoint(breakpoint: string): void { if (this.currentBreakpoint !== breakpoint) { diff --git a/features/longList/src/main/ets/view/HomeContent.ets b/features/longList/src/main/ets/view/HomeContent.ets index ebd56f3..32ce639 100644 --- a/features/longList/src/main/ets/view/HomeContent.ets +++ b/features/longList/src/main/ets/view/HomeContent.ets @@ -41,7 +41,7 @@ export struct HomeContent { @State netConnectState: NetConnectionState = NetConnectionState.UNKNOWN_STATE; public scroller: Scroller = new Scroller(); public waterFlowScroller: Scroller = new Scroller(); - private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + private context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; watchCurrentOffset(){ if(this.setCurrentOffset){ @@ -66,7 +66,7 @@ export struct HomeContent { }, 3000); } else { try { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.net_connection_description'), bottom: 120, duration: 3000 diff --git a/features/longList/src/main/ets/view/WaterFlowLivingView.ets b/features/longList/src/main/ets/view/WaterFlowLivingView.ets index bffc344..8fef487 100644 --- a/features/longList/src/main/ets/view/WaterFlowLivingView.ets +++ b/features/longList/src/main/ets/view/WaterFlowLivingView.ets @@ -90,8 +90,8 @@ export struct WaterFlowLivingView { } }) .onAppear(() => { - let videoPos = componentUtils.getRectangleById(CommonConstants.WATER_FLOW_LIVING_STRUCT_ID + this.itemIndex); - if (px2vp(videoPos.windowOffset.y) + px2vp(videoPos.size.height) < this.windowsHeight) { + let videoPos = this.getUIContext().getComponentUtils().getRectangleById(CommonConstants.WATER_FLOW_LIVING_STRUCT_ID + this.itemIndex); + if (this.getUIContext().px2vp(videoPos.windowOffset.y) + this.getUIContext().px2vp(videoPos.size.height) < this.windowsHeight) { setTimeout(() => { this.videoController.start(); }, 1000); diff --git a/features/longList/src/main/ets/view/WaterFlowView.ets b/features/longList/src/main/ets/view/WaterFlowView.ets index b708005..bc88a7e 100644 --- a/features/longList/src/main/ets/view/WaterFlowView.ets +++ b/features/longList/src/main/ets/view/WaterFlowView.ets @@ -66,7 +66,7 @@ export struct WaterFlowView { this.isShowFoot = false; } try { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.net_connection_description'), bottom: CommonConstants.TOAST_SHOW_MARGIN_BOTTOM, duration: CommonConstants.TOAST_SHOW_TIME @@ -90,19 +90,19 @@ export struct WaterFlowView { } updateWaterFlowItemWidth() { - let windowWidth: number = px2vp(display.getDefaultDisplaySync().width); + let windowWidth: number = this.getUIContext().px2vp(display.getDefaultDisplaySync().width); let columns = windowWidth > CommonConstants.CRITICAL_VALUE ? CommonConstants.WATER_FLOW_THREE_COLUMNS : CommonConstants.WATER_FLOW_TWO_COLUMNS; let marginLeft = windowWidth > CommonConstants.CRITICAL_VALUE ? BreakpointConstants.SEARCHBAR_AND_WATER_FLOW_MARGIN_LEFT_MD : BreakpointConstants.SEARCHBAR_AND_WATER_FLOW_MARGIN_LEFT_SM; this.waterFlowItemWidth = - (px2vp(display.getDefaultDisplaySync().width) - marginLeft * 2 - + (this.getUIContext().px2vp(display.getDefaultDisplaySync().width) - marginLeft * 2 - (columns - 1) * CommonConstants.WATER_FLOW_COLUMN_GAP) / columns; } getTitleHeight(title: string) { - let textWidth: number = MeasureText.measureText({ + let textWidth: number = this.getUIContext().getMeasureUtils().measureText({ textContent: title, fontSize: $r('app.float.font_size_14') }); diff --git a/features/video/src/main/ets/components/ExitVideo.ets b/features/video/src/main/ets/components/ExitVideo.ets index 8ea99b3..c77d19f 100644 --- a/features/video/src/main/ets/components/ExitVideo.ets +++ b/features/video/src/main/ets/components/ExitVideo.ets @@ -25,7 +25,7 @@ export struct ExitVideo { @StorageLink('show') show: boolean = false; @StorageLink('videoSelect') videoSelect: number = 0; @Link avPlayManage: avPlayManage; - private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + private context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; private videoList: Resource[] = [$r('app.string.video_res_1'), $r('app.string.video_res_2')]; async isInternet(): Promise { @@ -37,7 +37,7 @@ export struct ExitVideo { } async toast() { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.video_warn'), duration: 2000, }); diff --git a/features/video/src/main/ets/pages/Index.ets b/features/video/src/main/ets/pages/Index.ets index 5882d51..dd46838 100644 --- a/features/video/src/main/ets/pages/Index.ets +++ b/features/video/src/main/ets/pages/Index.ets @@ -165,7 +165,7 @@ struct Index { } async toast() { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.video_warn'), duration: 2000, }); diff --git a/features/web/src/main/ets/pages/IndexPage.ets b/features/web/src/main/ets/pages/IndexPage.ets index 5bcfd0d..7366239 100644 --- a/features/web/src/main/ets/pages/IndexPage.ets +++ b/features/web/src/main/ets/pages/IndexPage.ets @@ -39,7 +39,7 @@ struct IndexPage { @State controller: webview.WebviewController = new webview.WebviewController(); @State statusBarHeight: number = 0; @State sliderBarHeight: number = 56; - private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + private context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; arkTSObj: ArkTSFunModel = { jumpOrderConfirm: (detailStr: string) => this.jumpOrderConfirm(detailStr) }; @@ -53,7 +53,7 @@ struct IndexPage { aboutToAppear() { webview.WebviewController.setWebDebuggingAccess(true); - window.getLastWindow(getContext(this), (err: BusinessError, windowClass: window.Window) => { + window.getLastWindow(this.getUIContext().getHostContext(), (err: BusinessError, windowClass: window.Window) => { if (err.code) { Logger.error(TAG, 'Failed to obtain the main window. Cause: ' + JSON.stringify(err)); return; @@ -65,8 +65,8 @@ struct IndexPage { let type = window.AvoidAreaType.TYPE_SYSTEM; // Get status bar height. let area: window.AvoidArea = windowClass.getWindowAvoidArea(type); - let statusBarHeight = px2vp(area.topRect.height); - let sliderBarHeight = px2vp(area.bottomRect.height); + let statusBarHeight = this.getUIContext().px2vp(area.topRect.height); + let sliderBarHeight = this.getUIContext().px2vp(area.bottomRect.height); this.statusBarHeight = statusBarHeight; this.sliderBarHeight = sliderBarHeight; if (statusBarHeight > 0) { @@ -83,7 +83,7 @@ struct IndexPage { } jumpOrderConfirm(detailStr: string): void { - router.pushUrl({ + this.getUIContext().getRouter().pushUrl({ url: 'pages/OrderConfirmPage', params: { statusBarHeight: this.statusBarHeight, sliderBarHeight: this.sliderBarHeight, detailStr } }); @@ -102,7 +102,7 @@ struct IndexPage { controller: this.controller }) .onConfirm(() => { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast_msg'), duration: CommonConstants.TOAST_DURATION }); diff --git a/features/web/src/main/ets/pages/OrderConfirmPage.ets b/features/web/src/main/ets/pages/OrderConfirmPage.ets index fa532c7..e61169b 100644 --- a/features/web/src/main/ets/pages/OrderConfirmPage.ets +++ b/features/web/src/main/ets/pages/OrderConfirmPage.ets @@ -28,9 +28,9 @@ function titleStyle() { @Entry @Component struct OrderConfirmPage { - statusBarHeight: number = (router.getParams() as Record)['statusBarHeight']; - sliderBarHeight: number = (router.getParams() as Record)['sliderBarHeight']; - productDetail: ProductModel = JSON.parse((router.getParams() as Record)['detailStr']) as ProductModel; + statusBarHeight: number = (this.getUIContext().getRouter().getParams() as Record)['statusBarHeight']; + sliderBarHeight: number = (this.getUIContext().getRouter().getParams() as Record)['sliderBarHeight']; + productDetail: ProductModel = JSON.parse((this.getUIContext().getRouter().getParams() as Record)['detailStr']) as ProductModel; build() { Column() { @@ -39,7 +39,7 @@ struct OrderConfirmPage { .width($r('app.float.img_size')) .margin({ left: $r('app.float.md_padding_margin'), right: $r('app.float.lg_padding_margin') }) .onClick(() => { - router.back(); + this.getUIContext().getRouter().back(); }) Text($r('app.string.confirm_order')) .fontSize($r('app.float.font_size_lg')) @@ -194,7 +194,7 @@ struct OrderConfirmPage { colors: [[$r('app.color.button_start'), 0.11], [$r('app.color.button_end'), 0.89]] }) .onClick(() => { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.toast_msg'), duration: CommonConstants.TOAST_DURATION }); -- Gitee