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, ActionBarMode, ActionBarProp, Constants, ScreenManager } from '@ohos/common'; 17import { ActionBar } from '@ohos/common/CommonComponents'; 18import { IS_HORIZONTAL, SelectParams } from '../utils/ThirdSelectConstants'; 19 20@Component 21export struct ThirdSelectedPageActionBar { 22 @StorageLink(IS_HORIZONTAL) @Watch('createActionBar') isHorizontal: boolean = ScreenManager.getInstance() 23 .isHorizontal(); 24 @State menuList: Action[] = []; 25 selectParams: SelectParams = SelectParams.defaultParam(); 26 @Provide selectedCount: number = 0; 27 @Link @Watch('onSelectedCountChanged') totalSelectedCount: number; 28 isSelectPhotoGrid: boolean = false; 29 onMenuClicked: Function = (): void => {}; 30 leftAction: Action = Action.BACK; 31 @Link @Watch('onSelectedCountChanged') title: string; 32 @State actionBarProp: ActionBarProp = new ActionBarProp(); 33 isFirstEnter: boolean = true; 34 @StorageLink('statusBarHeight') statusBarHeight: number = 0; 35 @Provide hidePopup: boolean = false; 36 37 aboutToAppear(): void { 38 this.onSelectedCountChanged(); 39 this.createActionBar(); 40 } 41 42 onSelectedCountChanged() { 43 this.selectedCount = this.totalSelectedCount; 44 if (this.isSelectPhotoGrid == true) { 45 if (!this.selectParams.isFromFa || this.isFirstEnter) { 46 this.menuList = [Action.NAVIGATION_ALBUMS]; 47 } else { 48 this.menuList = []; 49 } 50 } else { 51 this.menuList = []; 52 } 53 this.createActionBar(); 54 } 55 56 build() { 57 Column() { 58 ActionBar({ 59 actionBarProp: $actionBarProp, 60 onMenuClicked: this.onMenuClicked, 61 isNeedPlaceholder: false 62 }) 63 } 64 .padding({ 65 top: (this.isHorizontal && !ScreenManager.getInstance().isUIExtensionEnv()) ? 66 $r('app.float.third_selected_actionbar_padding_top') : 67 (this.statusBarHeight === 0) ? $r('app.float.third_selected_actionbar_padding_top') : px2vp(this.statusBarHeight) 68 }) 69 } 70 71 private createActionBar(): void { 72 let actionBarProp: ActionBarProp = new ActionBarProp(); 73 actionBarProp 74 .setLeftAction(this.leftAction) 75 .setTitle(this.title) 76 .setMenuList(this.menuList) 77 .setMode(ActionBarMode.STANDARD_MODE) 78 .setBackgroundColor($r('sys.color.ohos_id_color_sub_background')) 79 .setMaxSelectCount(this.selectParams.maxSelectCount); 80 this.actionBarProp = actionBarProp; 81 } 82}