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