diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 6f5e6cdb4b993a9fbb1c2135907b770feed4f778..86506488a67549a725174bd94d0de3610e0144b2 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,6 +1,22 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { @@ -20,6 +36,29 @@ export default class EntryAbility extends UIAbility { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } + let windowClass: window.Window | undefined = undefined; + windowStage.getMainWindow((err: BusinessError, data) => { + let errCode: number = err.code; + if (errCode) { + hilog.error(0x0000, 'testTag', 'Failed to obtain the main window. Cause: ', JSON.stringify(err)); + return; + } + try { + windowClass = data; + let isLayoutFullScreen = true; + windowClass.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { + hilog.info(0x0000, 'testTag', 'Succeeded in setting the window layout to full-screen mode.'); + }); + let avoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); + // Set the height of the status bar. + AppStorage.setOrCreate('statusBarHeight', data.getUIContext().px2vp(avoidArea.topRect.height)); + AppStorage.setOrCreate('bottomHeight', data.getUIContext() + .px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height)); + } catch (exception) { + hilog.error(0x0000, '[EntryAbility]', + `Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`); + } + }) hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); }); } diff --git a/entry/src/main/ets/pages/MainPage.ets b/entry/src/main/ets/pages/MainPage.ets index 4d8802739fd5003ef5c9d65bb0e9134f1d8300c3..aa321c442dc8ae44c4d181959d52dfad6b9b8a0d 100644 --- a/entry/src/main/ets/pages/MainPage.ets +++ b/entry/src/main/ets/pages/MainPage.ets @@ -19,10 +19,16 @@ import CommonEventListComponent from '../view/CommonEventListComponent'; @Entry @Component struct MainPage { + @StorageLink('statusBarHeight') statusBarHeight: number = 0; + @StorageLink('bottomHeight') bottomHeight: number = 0; build() { Row() { CommonEventListComponent() } + .padding({ + top: this.statusBarHeight, + bottom: this.bottomHeight + }) .height(CommonConstants.FULL_SCREEN_HEIGHT) .backgroundColor($r('app.color.global_bg_color')) } diff --git a/entry/src/main/ets/view/CommonEventListComponent.ets b/entry/src/main/ets/view/CommonEventListComponent.ets index 990f0e62437fe3f74a69e854bd0e488794c952a2..322be2c2caca7a86540d7978b824bf3193f468e7 100644 --- a/entry/src/main/ets/view/CommonEventListComponent.ets +++ b/entry/src/main/ets/view/CommonEventListComponent.ets @@ -13,7 +13,6 @@ * limitations under the License. */ -import { promptAction } from '@kit.ArkUI'; import { CommonEventItem } from '../viewmodel/CommonEventItem'; import { CommonConstants } from '../common/constants/CommonConst'; import CommonEventUtil from '../common/utils/CommonEventUtil'; diff --git a/entry/src/main/ets/viewmodel/CommonEventItem.ets b/entry/src/main/ets/viewmodel/CommonEventItem.ets index 765eaec3d4f507f1938a142a00d933e240da3ad3..bee900ad11a80ebf29ab0591c34c3043fe55845b 100644 --- a/entry/src/main/ets/viewmodel/CommonEventItem.ets +++ b/entry/src/main/ets/viewmodel/CommonEventItem.ets @@ -15,6 +15,7 @@ import { commonEventManager } from '@kit.BasicServicesKit'; import { CommonConstants } from '../common/constants/CommonConst'; + /** * ButtonList item information */