diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 8ea9e4e1bc1024f3ad40fa38d0123d805b90dd70..641e726438977af5ed0cb38c0091ca3d9b6ddcc6 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -22,7 +22,7 @@ import { CommonConstants } from '../constants/CommonConstants'; // [Start get_avoid] export default class EntryAbility extends UIAbility { - uiContext ?: UIContext; + private uiContext ?: UIContext; private windowUtil?: WindowUtil = WindowUtil.getInstance(); private onAvoidAreaChange: (avoidArea: window.AvoidAreaOptions) => void = (avoidArea: window.AvoidAreaOptions) => { if (avoidArea.type === window.AvoidAreaType.TYPE_SYSTEM) { @@ -52,40 +52,40 @@ export default class EntryAbility extends UIAbility { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); this.windowUtil?.setWindowStage(windowStage); - windowStage.getMainWindow((err: BusinessError, data: window.Window) => { - if (err.code) { - hilog.error(0x0000, 'testTag', 'Failed to get the main window. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - this.windowUtil!.setFullScreen(); - // [StartExclude get_avoid] - AppStorage.setOrCreate('currentWidthBreakpoint', this.uiContext!.getWindowWidthBreakpoint()); - AppStorage.setOrCreate('currentHeightBreakpoint', this.uiContext!.getWindowHeightBreakpoint()); - data.on('windowSizeChange', this.onWindowSizeChange); - // [EndExclude get_avoid] - let topAvoidHeight: window.AvoidArea = data.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); - AppStorage.setOrCreate('topAvoidHeight', this.uiContext!.px2vp(topAvoidHeight.topRect.height)); - let bottomAvoidHeight: window.AvoidArea = data.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); - AppStorage.setOrCreate('bottomAvoidHeight', this.uiContext!.px2vp(bottomAvoidHeight.bottomRect.height)); - data.on('avoidAreaChange', this.onAvoidAreaChange); - if (AppStorage.get('currentWidthBreakpoint') === 'sm' && (AppStorage.get('currentHeightBreakpoint') === 'md' || - AppStorage.get('currentHeightBreakpoint') === 'sm')) { - // Set top bar height when the application is in small screen. - AppStorage.setOrCreate('topBarHeight', - CommonConstants.UTIL_HEIGHTS[1] + this.uiContext!.px2vp(topAvoidHeight.topRect.height)); - } else { - // Set top bar height when the application is in full screen. - AppStorage.setOrCreate('topBarHeight', - CommonConstants.UTIL_HEIGHTS[2] + this.uiContext!.px2vp(topAvoidHeight.topRect.height)); - } - }) - // [StartExclude get_avoid] - windowStage.loadContent('pages/Index', (err) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } + windowStage.getMainWindow((err: BusinessError, data: window.Window) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to get the main window. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + this.uiContext = data.getUIContext(); + this.windowUtil!.setFullScreen(); + // [StartExclude get_avoid] + AppStorage.setOrCreate('currentWidthBreakpoint', this.uiContext.getWindowWidthBreakpoint()); + AppStorage.setOrCreate('currentHeightBreakpoint', this.uiContext.getWindowHeightBreakpoint()); + data.on('windowSizeChange', this.onWindowSizeChange); + // [EndExclude get_avoid] + let topAvoidHeight: window.AvoidArea = data.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); + AppStorage.setOrCreate('topAvoidHeight', this.uiContext.px2vp(topAvoidHeight.topRect.height)); + let bottomAvoidHeight: window.AvoidArea = data.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); + AppStorage.setOrCreate('bottomAvoidHeight', this.uiContext.px2vp(bottomAvoidHeight.bottomRect.height)); + data.on('avoidAreaChange', this.onAvoidAreaChange); + if (AppStorage.get('currentWidthBreakpoint') === 'sm' && (AppStorage.get('currentHeightBreakpoint') === 'md' || + AppStorage.get('currentHeightBreakpoint') === 'sm')) { + // Set top bar height when the application is in small screen. + AppStorage.setOrCreate('topBarHeight', + CommonConstants.UTIL_HEIGHTS[1] + this.uiContext!.px2vp(topAvoidHeight.topRect.height)); + } else { + // Set top bar height when the application is in full screen. + AppStorage.setOrCreate('topBarHeight', + CommonConstants.UTIL_HEIGHTS[2] + this.uiContext!.px2vp(topAvoidHeight.topRect.height)); + } + }) + // [StartExclude get_avoid] hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); }); // [EndExclude get_avoid]