From cece2621ceb2d5a03dac62b35b768867acae477d Mon Sep 17 00:00:00 2001 From: zhangyuming27 Date: Wed, 12 Nov 2025 16:21:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commons/base/Index.ets | 2 +- .../base/src/main/ets/utils/WindowUtil.ets | 1 + features/home/src/main/ets/pages/Home.ets | 2 +- .../home/src/main/ets/pages/OptionPage.ets | 2 +- .../src/main/ets/pages/StockDetailsPage.ets | 12 +---- .../main/ets/entryability/EntryAbility.ets | 51 ++----------------- .../splitScreenAbility/SplitScreenAbility.ets | 28 ++-------- products/phone/src/main/module.json5 | 2 +- 8 files changed, 12 insertions(+), 88 deletions(-) diff --git a/commons/base/Index.ets b/commons/base/Index.ets index 396165d..3a628f1 100644 --- a/commons/base/Index.ets +++ b/commons/base/Index.ets @@ -1 +1 @@ -export { WindowInfo, WindowUtil } from './src/main/ets/utils/WindowUtil'; +export { ImmersiveType, WindowInfo, WindowUtil } from './src/main/ets/utils/WindowUtil'; diff --git a/commons/base/src/main/ets/utils/WindowUtil.ets b/commons/base/src/main/ets/utils/WindowUtil.ets index 3b0367e..727370b 100644 --- a/commons/base/src/main/ets/utils/WindowUtil.ets +++ b/commons/base/src/main/ets/utils/WindowUtil.ets @@ -229,6 +229,7 @@ export class WindowUtil { // [EndExclude updateBreakpoint] // [EndExclude WindowSizeChange] // [EndExclude getWindowAvoidArea] + AppStorage.setOrCreate('mainWindowInfo', this.mainWindowInfo); } catch (error) { let err = error as BusinessError; hilog.error(0x0000, `TestLog`, `Failed to update window info. Code: ${err.code}, message: ${err.message}`); diff --git a/features/home/src/main/ets/pages/Home.ets b/features/home/src/main/ets/pages/Home.ets index 1091710..795dcc8 100644 --- a/features/home/src/main/ets/pages/Home.ets +++ b/features/home/src/main/ets/pages/Home.ets @@ -157,7 +157,7 @@ export struct Home { }) .padding({ bottom: this.mainWindowInfo.widthBp === WidthBreakpoint.WIDTH_LG ? 0 : - AppStorage.get('naviIndicatorHeight') as number - 10 + this.getUIContext().px2vp(this.mainWindowInfo.AvoidNavigationIndicator?.bottomRect.height) }) } .width('100%') diff --git a/features/home/src/main/ets/pages/OptionPage.ets b/features/home/src/main/ets/pages/OptionPage.ets index 756f369..3eb08ed 100644 --- a/features/home/src/main/ets/pages/OptionPage.ets +++ b/features/home/src/main/ets/pages/OptionPage.ets @@ -236,7 +236,7 @@ export struct OptionPage { .height('100%') .padding({ top: this.mainWindowInfo.widthBp === WidthBreakpoint.WIDTH_SM && - this.mainWindowInfo.heightBp === HeightBreakpoint.HEIGHT_MD ? 16 : AppStorage.get('statusBarHeight') + this.mainWindowInfo.heightBp === HeightBreakpoint.HEIGHT_MD ? 16 : this.getUIContext().px2vp(this.mainWindowInfo.AvoidSystem?.topRect.height) }) } } \ No newline at end of file diff --git a/features/stockdetail/src/main/ets/pages/StockDetailsPage.ets b/features/stockdetail/src/main/ets/pages/StockDetailsPage.ets index 84d5d10..84f0ee4 100644 --- a/features/stockdetail/src/main/ets/pages/StockDetailsPage.ets +++ b/features/stockdetail/src/main/ets/pages/StockDetailsPage.ets @@ -38,7 +38,6 @@ export struct StockDetailsPage { @State closeInfoCarousel: boolean = false; private scroller: Scroller = new Scroller(); private cardList: number[] = [1, 2, 3]; - private windowClass: window.Window = AppStorage.get('windowClass')!; private isHiding: boolean = false; @Provide('isFirstBulletBox') isFirstBulletBox: boolean = true; @Provide('popUpBoxIsShow') @Watch('bindSheetMonitor') popUpBoxIsShow: boolean = false; @@ -61,14 +60,6 @@ export struct StockDetailsPage { } } - isOverlayMethod(statusBarColor: string): void { - let SystemBarProperties: window.SystemBarProperties; - SystemBarProperties = { statusBarColor: statusBarColor }; - this.windowClass.setWindowSystemBarProperties(SystemBarProperties).catch((err: BusinessError) => { - hilog.error(0x0000, 'StockDetailsView', - `setWindowSystemBarProperties failed, error code=${err.code}, message=${err.message}`); - }); - } @Builder myBuilder() { @@ -101,7 +92,6 @@ export struct StockDetailsPage { Column() { // Stock details information StockDetailsInfo({ stockInForm: this.stockInForm }) - // Stock Notification Row() { Row() { @@ -344,7 +334,7 @@ export struct StockDetailsPage { .backgroundColor(Color.White) .padding({ top: this.mainWindowInfo.widthBp === WidthBreakpoint.WIDTH_SM && - this.mainWindowInfo.heightBp === HeightBreakpoint.HEIGHT_MD ? 0 : AppStorage.get('statusBarHeight') + this.mainWindowInfo.heightBp === HeightBreakpoint.HEIGHT_MD ? 0 : this.getUIContext().px2vp(this.mainWindowInfo.AvoidSystem?.topRect.height) }) .onBackPressed(() => { if (this.tabletMode === NavigationMode.Stack) { diff --git a/products/phone/src/main/ets/entryability/EntryAbility.ets b/products/phone/src/main/ets/entryability/EntryAbility.ets index e4aa578..566160e 100644 --- a/products/phone/src/main/ets/entryability/EntryAbility.ets +++ b/products/phone/src/main/ets/entryability/EntryAbility.ets @@ -18,22 +18,11 @@ import { resourceManager } from '@kit.LocalizationKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; import Logger from '@ohos/commons/src/main/ets/utils/Logger'; -import { WindowInfo, WindowUtil } from '@ohos/commons'; +import { ImmersiveType, WindowUtil } from '@ohos/commons'; export default class EntryAbility extends UIAbility { windowUtil?: WindowUtil private windowObj?: window.Window; - private windowStage?: window.WindowStage; - private onWindowSizeChange: (windowSize: window.Size) => void = () => { - this.windowUtil!.updateWindowInfo(); - let mainWindowInfo: WindowInfo | undefined = this.windowUtil?.mainWindowInfo; - AppStorage.setOrCreate('mainWindowInfo', mainWindowInfo); - // Application adaptation for horizontal and vertical screen switching. - this.windowObj?.setPreferredOrientation(window.Orientation.FOLLOW_DESKTOP).catch((err: BusinessError) => { - Logger.error('EntryAbility', '%{public}s', `setPreferredOrientation failed, code : ${err.code}, message : ${err.message}`); - }); - this.immersionFuc(this.windowStage!); - }; private windowStatusChange: (WindowStatusType: window.WindowStatusType) => void = (WindowStatusType: window.WindowStatusType) => { if (WindowStatusType === window.WindowStatusType.FLOATING || @@ -74,7 +63,6 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('windowUtil', this.windowUtil); let context = this.context; - this.windowStage = windowStage; let resourceManager: resourceManager.ResourceManager = context.resourceManager; AppStorage.setOrCreate('resourceManager', resourceManager); windowStage.loadContent('pages/Index', (err, data) => { @@ -84,9 +72,6 @@ export default class EntryAbility extends UIAbility { } Logger.info('EntryAbility', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - // Immersive Adaptation - this.immersionFuc(windowStage); - const isWindowAvailable = canIUse('SystemCapability.Window.SessionManager'); if (isWindowAvailable) { // Determine the current application window mode. @@ -100,22 +85,14 @@ export default class EntryAbility extends UIAbility { } else { Logger.info('Window not by this device.'); } - windowStage.getMainWindow().then((data: window.Window) => { - try { - this.windowObj = data; - data.on('windowSizeChange', this.onWindowSizeChange); - } catch (error) { - Logger.error(`GetUIContext failed. Cause code: ${err.code}, message: ${err.message}`); - } - }).catch((err: BusinessError) => { - Logger.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); - }); // Application adaptation for horizontal and vertical screen switching. this.windowObj?.setPreferredOrientation(window.Orientation.FOLLOW_DESKTOP).catch((err: BusinessError) => { Logger.error('EntryAbility', '%{public}s', `setPreferredOrientation failed, code : ${err.code}, message : ${err.message}`); }); this.windowUtil!.setUIContext(); + this.windowUtil!.setImmersiveType(ImmersiveType.IMMERSIVE); + this.windowUtil!.setWindowOrientation(window.Orientation.FOLLOW_DESKTOP); this.windowUtil!.updateWindowInfo(); }); @@ -135,26 +112,4 @@ export default class EntryAbility extends UIAbility { // Ability has back to background Logger.info('EntryAbility', '%{public}s', 'Ability onBackground'); } - - /** - * Page immersion. - */ - immersionFuc(windowStage: window.WindowStage): void { - try { - let windowClass: window.Window = windowStage.getMainWindowSync(); - windowClass.setWindowLayoutFullScreen(true).catch((err: BusinessError) => { - Logger.error(`SetWindowLayoutFullScreen failed. Cause code: ${err.code}, message: ${err.message}`); - }); - let navigationBarArea: window.AvoidArea = - windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); - let area: window.AvoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); - AppStorage.setOrCreate('naviIndicatorHeight', - windowClass.getUIContext().px2vp(navigationBarArea.bottomRect.height)); - AppStorage.setOrCreate('statusBarHeight', windowClass.getUIContext().px2vp(area.topRect.height)); - AppStorage.setOrCreate('windowClass', windowClass); - } catch (error) { - let err = error as BusinessError; - Logger.error('EntryAbility', `immersionFuc failed, error code: ${err.code}, message: ${err.message}`); - } - } } \ No newline at end of file diff --git a/products/phone/src/main/ets/splitScreenAbility/SplitScreenAbility.ets b/products/phone/src/main/ets/splitScreenAbility/SplitScreenAbility.ets index 62c806a..e29c100 100644 --- a/products/phone/src/main/ets/splitScreenAbility/SplitScreenAbility.ets +++ b/products/phone/src/main/ets/splitScreenAbility/SplitScreenAbility.ets @@ -18,7 +18,7 @@ import { resourceManager } from '@kit.LocalizationKit'; import { BusinessError, emitter } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; import Logger from '@ohos/commons/src/main/ets/utils/Logger'; -import { WindowUtil } from '@ohos/commons'; +import { ImmersiveType, WindowUtil } from '@ohos/commons'; // [Start SplitAbility] let eventData: emitter.EventData = { @@ -106,8 +106,6 @@ export default class SplitScreenAbility extends UIAbility { } Logger.info('SplitScreenAbility', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - // Immersive Adaptation - this.immersionFuc(windowStage); const isWindowAvailable = canIUse('SystemCapability.Window.SessionManager'); if (isWindowAvailable) { @@ -124,6 +122,8 @@ export default class SplitScreenAbility extends UIAbility { } }); this.windowUtil!.setUIContext(); + this.windowUtil!.setImmersiveType(ImmersiveType.IMMERSIVE); + this.windowUtil!.setWindowOrientation(window.Orientation.FOLLOW_DESKTOP); this.windowUtil!.updateWindowInfo(); } @@ -141,28 +141,6 @@ export default class SplitScreenAbility extends UIAbility { // Ability has back to background Logger.info('SplitScreenAbility', '%{public}s', 'Ability onBackground'); } - - /** - * Page immersion. - */ - immersionFuc(windowStage: window.WindowStage): void { - try { - let windowClass: window.Window = windowStage.getMainWindowSync(); - windowClass.setWindowLayoutFullScreen(true).catch((err: BusinessError) => { - Logger.error(`SetWindowLayoutFullScreen failed. Cause code: ${err.code}, message: ${err.message}`); - }); - let navigationBarArea: window.AvoidArea = - windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); - let area: window.AvoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); - AppStorage.setOrCreate('naviIndicatorHeight', - windowClass.getUIContext().px2vp(navigationBarArea.bottomRect.height)); - AppStorage.setOrCreate('statusBarHeight', windowClass.getUIContext().px2vp(area.topRect.height)); - AppStorage.setOrCreate('windowClass', windowClass); - } catch (error) { - let err = error as BusinessError; - Logger.error('SplitScreenAbility', `immersionFuc failed, error code=${err.code}, message=${err.message}`); - } - } // [EndExclude SplitAbility] } // [End SplitAbility] \ No newline at end of file diff --git a/products/phone/src/main/module.json5 b/products/phone/src/main/module.json5 index 11428e5..aa018c8 100644 --- a/products/phone/src/main/module.json5 +++ b/products/phone/src/main/module.json5 @@ -38,7 +38,7 @@ } ], "minWindowHeight": 600, - "minWindowWidth": 840 + "minWindowWidth": 1080 }, { "name": "SplitScreenAbility", -- Gitee