From b216199b19f9ab8e491d30239e76717b5bb3e078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=98=E6=B5=A9=E7=A8=8B?= <798994511@qq.com> Date: Tue, 5 Nov 2024 11:34:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E5=A4=9A=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/src/main/ets/view/HomeContent.ets | 29 +------------------ .../home/src/main/ets/view/HomeHeader.ets | 2 +- .../main/ets/entryability/EntryAbility.ets | 2 ++ 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/features/home/src/main/ets/view/HomeContent.ets b/features/home/src/main/ets/view/HomeContent.ets index aacd955..c640306 100644 --- a/features/home/src/main/ets/view/HomeContent.ets +++ b/features/home/src/main/ets/view/HomeContent.ets @@ -13,7 +13,6 @@ * limitations under the License. */ -import { window } from '@kit.ArkUI'; import { deviceInfo } from '@kit.BasicServicesKit'; import { BreakpointConstants, BreakpointType, CommonConstants } from '@ohos/commons'; import { Logger, WindowUtil } from '@ohos/commons'; @@ -28,14 +27,9 @@ import { PreviousVideo } from './PreviousVideo'; export struct HomeContent { @StorageLink('currentWidthBreakpoint') currentWidthBreakpoint: string = BreakpointConstants.BREAKPOINT_LG; @StorageLink('currentTopIndex') currentTopIndex: number = 0; - @StorageLink('windowWidth') windowWidth: number = 0; @State gridStatus: number = 1; private windowUtil?: WindowUtil; - private mainWindow?: window.Window; private isSearching: boolean = false; - private onWindowSizeChange: (data: window.Size) => void = (data: window.Size) => { - this.windowWidth = data.width; - } aboutToAppear(): void { this.windowUtil = WindowUtil.getInstance(); @@ -46,30 +40,9 @@ export struct HomeContent { if (deviceInfo.deviceType !== CommonConstants.DEVICE_TYPES[0]) { this.windowUtil.setFullScreen(); } - this.mainWindow = this.windowUtil.getMainWindow(); - if (this.mainWindow === undefined) { - Logger.error(`MainWindow is undefined`); - return; - } - this.windowWidth = this.mainWindow.getWindowProperties().windowRect.width; - this.mainWindow.on('windowSizeChange', this.onWindowSizeChange); } - aboutToDisappear(): void { - this.windowUtil = WindowUtil.getInstance(); - if (this.windowUtil === undefined) { - return; - } - this.mainWindow = this.windowUtil.getMainWindow(); - if (this.mainWindow === undefined) { - return; - } - try { - this.mainWindow.off('windowSizeChange'); - } catch (exception) { - Logger.error('Failed to unregister the window callback. Code: ' + JSON.stringify(exception)); - } - } + build() { Column() { diff --git a/features/home/src/main/ets/view/HomeHeader.ets b/features/home/src/main/ets/view/HomeHeader.ets index fe6170e..fe929f4 100644 --- a/features/home/src/main/ets/view/HomeHeader.ets +++ b/features/home/src/main/ets/view/HomeHeader.ets @@ -147,7 +147,7 @@ export struct HomeHeader { this.currentTopIndex = index; this.scrollHeight = 0; }) - }, (item: number, index: number) => index + JSON.stringify(item)) + }, (item: string, index: number) => index + JSON.stringify(item)) } .tabIndex(getTabIndex(HomeConstants.DIRECTION_LIST[1])) .scrollBar(BarState.Off) diff --git a/products/phone/src/main/ets/entryability/EntryAbility.ets b/products/phone/src/main/ets/entryability/EntryAbility.ets index 14a280f..9e59bc8 100644 --- a/products/phone/src/main/ets/entryability/EntryAbility.ets +++ b/products/phone/src/main/ets/entryability/EntryAbility.ets @@ -57,9 +57,11 @@ export default class EntryAbility extends UIAbility { this.windowObj = data; this.updateWidthBp(); this.updateHeightBp(); + AppStorage.setOrCreate('windowWidth', data.getWindowProperties().windowRect.width); this.windowObj.on('windowSizeChange', (windowSize: window.Size) => { this.updateWidthBp(); this.updateHeightBp(); + AppStorage.setOrCreate('windowWidth', windowSize.width); }) }) -- Gitee