diff --git a/features/home/src/main/ets/view/HomeContent.ets b/features/home/src/main/ets/view/HomeContent.ets index aacd955eca5565a17da786adb153f807982cfa4f..c64030689f9d5f5207ec86ff762ad0ce17cc4486 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 fe6170e241c0cf433ce82bf6d84a0e1d36fc3522..fe929f4f876063b3af55742592b7384f4d79ec9d 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 14a280f9acbd7abb66660b922d63da4d45dd5b43..9e59bc806d96d210107be14298c624f7202edc1f 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); }) })