1/* 2 * Copyright (c) 2022-2023 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 { Action } from './browserOperation/Action'; 17import { ActionBar } from './actionbar/ActionBar'; 18import { ActionBarProp } from './browserOperation/ActionBarProp'; 19import { ActionBarColorMode, ActionBarMode, ActionBarSelectionMode } from './browserOperation/ActionBarMode'; 20import { ScreenManager } from '../model/common/ScreenManager'; 21import { Constants } from '../model/common/Constants'; 22 23const TAG: string = 'common_ThirdSelectPhotoBrowserActionBar'; 24 25@Component 26export struct ThirdSelectPhotoBrowserActionBar { 27 @StorageLink('leftBlank') leftBlank: number[] 28 = [0, ScreenManager.getInstance().getStatusBarHeight(), 0, ScreenManager.getInstance().getNaviBarHeight()]; 29 @State isMultiPick: boolean = false; 30 @Consume @Watch('createActionBar') isSelected: boolean; 31 onMenuClicked: Function = (): void => {}; 32 @StorageLink('isHorizontal') @Watch('createActionBar') isHorizontal: boolean = ScreenManager.getInstance() 33 .isHorizontal(); 34 @State actionBarProp: ActionBarProp = new ActionBarProp(); 35 @StorageLink('statusBarHeight') statusBarHeight: number = 0; 36 @Link isShowBar: boolean; 37 @Provide('selectedCount') selectedCount: number = 0; 38 @Link @Watch('onSelectedCountChanged') totalSelectedCount: number; 39 @Provide moreMenuList: Action[] = new Array<Action>(); 40 @Provide hidePopup: boolean = false; 41 private title: string | Resource = ''; 42 private isThird: boolean = false; 43 44 aboutToAppear() { 45 this.createActionBar(); 46 this.onSelectedCountChanged(); 47 } 48 49 build() { 50 Stack({ alignContent: Alignment.TopStart }) { 51 Image($r('app.media.gradientBasePlate')).width(Constants.PERCENT_100) 52 .height(Constants.PERCENT_100).objectFit(ImageFit.Fill) 53 ActionBar({ 54 actionBarProp: $actionBarProp, 55 onMenuClicked: this.onMenuClicked, 56 isNeedPlaceholder: false 57 }) 58 .padding({ 59 top: this.isHorizontal ? Constants.NUMBER_0 : px2vp(this.statusBarHeight) 60 }) 61 } 62 .height(this.isHorizontal ? Constants.ActionBarHeight * Constants.PHOTO_BAR_MULTIPLES_1_5 63 : Constants.ActionBarHeight * Constants.PHOTO_BAR_MULTIPLES_1_5 64 + px2vp(this.statusBarHeight)) 65 .markAnchor({ x: Constants.PERCENT_0, y: Constants.PERCENT_0 }) 66 .position({ x: Constants.PERCENT_0, y: this.leftBlank[1] }) 67 .visibility(this.isShowBar ? Visibility.Visible : Visibility.Hidden) 68 } 69 70 private onSelectedCountChanged() { 71 this.selectedCount = this.totalSelectedCount; 72 } 73 74 private createActionBar(): void { 75 let actionBarProp: ActionBarProp = new ActionBarProp(); 76 actionBarProp 77 .setLeftAction(Action.BACK) 78 .setMode(ActionBarMode.SELECTION_MODE) 79 .setSelectionMode(this.isMultiPick ? ActionBarSelectionMode.MULTI : ActionBarSelectionMode.SINGLE) 80 .setColorMode(ActionBarColorMode.TRANSPARENT) 81 .setAlpha(ActionBarProp.PHOTO_BROWSER_ACTIONBAR_ALPHA) 82 83 if (this.isMultiPick && !this.isThird) { 84 let menuList = [this.isSelected ? Action.SELECTED : Action.MATERIAL_SELECT]; 85 actionBarProp.setMenuList(menuList) 86 } 87 88 if (this.title) { 89 actionBarProp 90 .setIsNeedTitle(false); 91 } 92 this.actionBarProp = actionBarProp; 93 } 94}