100aff185Sopenharmony_ci/* 200aff185Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 300aff185Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 400aff185Sopenharmony_ci * you may not use this file except in compliance with the License. 500aff185Sopenharmony_ci * You may obtain a copy of the License at 600aff185Sopenharmony_ci * 700aff185Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 800aff185Sopenharmony_ci * 900aff185Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1000aff185Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1100aff185Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1200aff185Sopenharmony_ci * See the License for the specific language governing permissions and 1300aff185Sopenharmony_ci * limitations under the License. 1400aff185Sopenharmony_ci */ 1500aff185Sopenharmony_ci 1600aff185Sopenharmony_ciimport { ScreenManager } from '../model/common/ScreenManager'; 1700aff185Sopenharmony_ciimport { Constants } from '../model/common/Constants'; 1800aff185Sopenharmony_ciimport { Log } from '../utils/Log'; 1900aff185Sopenharmony_ci 2000aff185Sopenharmony_ciconst TAG: string = 'common_NoPhotoComponent'; 2100aff185Sopenharmony_ci 2200aff185Sopenharmony_ci@Component 2300aff185Sopenharmony_ciexport struct NoPhotoComponent { 2400aff185Sopenharmony_ci title?: Resource; 2500aff185Sopenharmony_ci 2600aff185Sopenharmony_ci // set an initial value temporarily, later change to 0. 2700aff185Sopenharmony_ci @State offSetY: number = Constants.EMPTY_PAGE_DEFAULT_OFFSET; 2800aff185Sopenharmony_ci @StorageLink('isHorizontal') isHorizontal: boolean = ScreenManager.getInstance().isHorizontal(); 2900aff185Sopenharmony_ci @StorageLink('isSidebar') isSidebar: boolean = ScreenManager.getInstance().isSidebar(); 3000aff185Sopenharmony_ci @StorageLink('leftBlank') leftBlank: number[] = 3100aff185Sopenharmony_ci [0, ScreenManager.getInstance().getStatusBarHeight(), 0, ScreenManager.getInstance().getNaviBarHeight()]; 3200aff185Sopenharmony_ci @State bigScreen: boolean = false; 3300aff185Sopenharmony_ci private updateImageLayoutFunc: Function = (): void => this.updateImageLayout(); 3400aff185Sopenharmony_ci 3500aff185Sopenharmony_ci aboutToAppear(): void { 3600aff185Sopenharmony_ci Log.info(TAG, `aboutToAppear`); 3700aff185Sopenharmony_ci ScreenManager.getInstance().on(ScreenManager.ON_WIN_SIZE_CHANGED, this.updateImageLayoutFunc); 3800aff185Sopenharmony_ci this.updateImageLayout(); 3900aff185Sopenharmony_ci } 4000aff185Sopenharmony_ci 4100aff185Sopenharmony_ci aboutToDisappear(): void { 4200aff185Sopenharmony_ci Log.info(TAG, 'aboutToDisappear'); 4300aff185Sopenharmony_ci ScreenManager.getInstance().off(ScreenManager.ON_WIN_SIZE_CHANGED, this.updateImageLayoutFunc); 4400aff185Sopenharmony_ci } 4500aff185Sopenharmony_ci 4600aff185Sopenharmony_ci build() { 4700aff185Sopenharmony_ci Flex({ 4800aff185Sopenharmony_ci direction: FlexDirection.Column, 4900aff185Sopenharmony_ci justifyContent: FlexAlign.Start, 5000aff185Sopenharmony_ci alignItems: ItemAlign.Center 5100aff185Sopenharmony_ci }) { 5200aff185Sopenharmony_ci Column() { 5300aff185Sopenharmony_ci Image($r('app.media.no_image_icon')) 5400aff185Sopenharmony_ci .height(this.bigScreen ? $r('app.float.empty_page_picture_size_large') : $r('app.float.empty_page_picture_size')) 5500aff185Sopenharmony_ci .width(this.bigScreen ? $r('app.float.empty_page_picture_size_large') : $r('app.float.empty_page_picture_size')) 5600aff185Sopenharmony_ci .margin({ 5700aff185Sopenharmony_ci bottom: $r('sys.float.ohos_id_elements_margin_vertical_m'), 5800aff185Sopenharmony_ci }) 5900aff185Sopenharmony_ci Text(this.title) 6000aff185Sopenharmony_ci .fontSize($r('sys.float.ohos_id_text_size_body2')) 6100aff185Sopenharmony_ci .fontFamily($r('app.string.id_text_font_family_regular')) 6200aff185Sopenharmony_ci .fontColor($r('app.color.tertiary_title_text_color')) 6300aff185Sopenharmony_ci } 6400aff185Sopenharmony_ci .width('100%') 6500aff185Sopenharmony_ci .offset({ x: 0, y: this.offSetY }) 6600aff185Sopenharmony_ci .padding({ left: $r('app.float.max_padding_start'), right: $r('app.float.max_padding_start') }) 6700aff185Sopenharmony_ci } 6800aff185Sopenharmony_ci .width('100%') 6900aff185Sopenharmony_ci } 7000aff185Sopenharmony_ci 7100aff185Sopenharmony_ci private updateImageLayout(): void { 7200aff185Sopenharmony_ci this.bigScreen = Math.min(ScreenManager.getInstance().getWinHeight(), ScreenManager.getInstance() 7300aff185Sopenharmony_ci .getWinWidth()) > Constants.BIG_SCREEN_WIDTH 7400aff185Sopenharmony_ci let halfImageHeight = this.bigScreen ? Constants.BIG_EMPTY_ICON_SIZE / 2 : Constants.SMALL_EMPTY_ICON_SIZE / 2 7500aff185Sopenharmony_ci let screenHeight = ScreenManager.getInstance().getWinHeight() - this.leftBlank[1] - this.leftBlank[3] 7600aff185Sopenharmony_ci if (this.isHorizontal) { 7700aff185Sopenharmony_ci if (this.isSidebar) { 7800aff185Sopenharmony_ci // Pad landscape 7900aff185Sopenharmony_ci this.offSetY = screenHeight / Constants.NUMBER_2 - halfImageHeight - Constants.ActionBarHeight; 8000aff185Sopenharmony_ci } else { 8100aff185Sopenharmony_ci // Phone landscape 8200aff185Sopenharmony_ci this.offSetY = (screenHeight - Constants.ActionBarHeight) / Constants.NUMBER_2 - halfImageHeight; 8300aff185Sopenharmony_ci } 8400aff185Sopenharmony_ci } else { 8500aff185Sopenharmony_ci // Phone vertical screen 8600aff185Sopenharmony_ci this.offSetY = screenHeight * Constants.EMPTY_PAGE_OFFSET_RADIO - 8700aff185Sopenharmony_ci Constants.ActionBarHeight - halfImageHeight; 8800aff185Sopenharmony_ci } 8900aff185Sopenharmony_ci Log.info(TAG, `isHorizontal: ${this.isHorizontal}, offSetY: ${this.offSetY}, bigScreen: ${this.bigScreen}`); 9000aff185Sopenharmony_ci } 9100aff185Sopenharmony_ci}