1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import screenManager from '@ohos/base/src/main/ets/manager/ScreenManager'; 17import { Constants } from '../model/common/Constants'; 18import { Log } from '@ohos/base/src/main/ets/utils/Log'; 19 20const TAG = "NoPhotoComponent" 21 22@Component 23export struct NoPhotoComponent { 24 private TAG: string = 'NoPhotoComponent'; 25 title: Resource; 26 // set an initial value temporarily, later change to 0. 27 @State offSetY: number = Constants.EMPTY_PAGE_DEFAULT_OFFSET; 28 @StorageLink('isHorizontal') isHorizontal: boolean = screenManager.isHorizontal(); 29 @StorageLink('isSidebar') isSidebar: boolean = screenManager.isSidebar(); 30 @StorageLink('leftBlank') leftBlank: [number, number, number, number] = [0, 0, 0, 0]; 31 @State bigScreen: boolean = false; 32 33 aboutToAppear(): void { 34 Log.info(TAG, `aboutToAppear`); 35 this.bigScreen = Math.min(screenManager.getWinHeight(), screenManager 36 .getWinWidth()) > Constants.BIG_SCREEN_WIDTH; 37 let halfImageHeight = this.bigScreen ? Constants.BIG_EMPTY_ICON_SIZE / 2 : Constants.SMALL_EMPTY_ICON_SIZE / 2; 38 let screenHeight = screenManager.getWinHeight() - px2vp(this.leftBlank[1] + this.leftBlank[3]); 39 if (this.isHorizontal) { 40 if (this.isSidebar) { 41 // Pad landscape 42 this.offSetY = screenHeight / Constants.NUMBER_2 - halfImageHeight - Constants.ActionBarHeight; 43 } else { 44 // Phone landscape 45 this.offSetY = (screenHeight - Constants.ActionBarHeight) / Constants.NUMBER_2 - halfImageHeight; 46 } 47 } else { 48 // Phone vertical screen 49 this.offSetY = screenHeight * Constants.EMPTY_PAGE_OFFSET_RADIO - 50 Constants.ActionBarHeight - halfImageHeight; 51 } 52 53 Log.info(TAG, `isHorizontal: ${this.isHorizontal}, offSetY: ${this.offSetY}, bigScreen: ${this.bigScreen}`); 54 } 55 56 build() { 57 Flex({ 58 direction: FlexDirection.Column, 59 justifyContent: FlexAlign.Start, 60 alignItems: ItemAlign.Start 61 }) { 62 Column() { 63 Image($r("app.media.no_image_icon")) 64 .height(this.bigScreen ? $r('app.float.empty_page_picture_size_large') : $r('app.float.empty_page_picture_size')) 65 .width(this.bigScreen ? $r('app.float.empty_page_picture_size_large') : $r('app.float.empty_page_picture_size')) 66 .margin({ 67 bottom: $r('sys.float.ohos_id_elements_margin_vertical_m'), 68 }) 69 Text(this.title) 70 .fontSize($r('sys.float.ohos_id_text_size_body2')) 71 .fontFamily($r('app.string.id_text_font_family_regular')) 72 .fontColor($r('app.color.tertiary_title_text_color')) 73 } 74 .width('100%') 75 .offset({ x: 0, y: this.offSetY }) 76 .padding({ left: $r('app.float.max_padding_start'), right: $r('app.float.max_padding_start') }) 77 } 78 .width('100%') 79 } 80}