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 { Log } from '@ohos/base/src/main/ets/utils/Log'; 17import { ActionBarProp } from '../browserOperation/ActionBarProp'; 18import { Action } from '../browserOperation/Action'; 19import { ActionBarMode } from '../browserOperation/ActionBarMode'; 20import { SingleTitle } from './SingleTitle'; 21import { DetailTitle } from './DetailTitle'; 22import { SelectionTitle } from './SelectionTitle'; 23import { DetailMenuPanel } from './DetailMenuPanel'; 24import { Constants } from '../../model/common/Constants'; 25import { ActionBarButton } from './ActionBarButton'; 26 27const TAG: string = 'ActionBar'; 28 29// ActionBar,It consists of action on the left, title in the middle and menu panel on the right 30@Component 31export struct ActionBar { 32 @Link actionBarProp: ActionBarProp; 33 onMenuClicked: Function; 34 isVideoPage: boolean = false; 35 @State hasTabBar: boolean = false; 36 37 private onBuildDone(): void { 38 Log.info(TAG, `onBuildDone,actionBarProp:${this.actionBarProp.getHasTabBar()}`); 39 } 40 41 aboutToAppear(): void { 42 Log.info(TAG, `aboutToAppear`); 43 this.hasTabBar = this.actionBarProp.getHasTabBar(); 44 } 45 46 createArray(): ActionBarProp[] { 47 let actionBarProp = new Array<ActionBarProp>(); 48 actionBarProp.push(this.actionBarProp); 49 return actionBarProp; 50 } 51 52 build() { 53 Row() { 54 if (!this.actionBarProp.getLeftAction().equals(Action.NONE)) { 55 ForEach(this.createArray(), (item)=>{ 56 ActionBarButton({ 57 res: item.getLeftAction().iconRes, 58 action: item.getLeftAction(), 59 onMenuClicked: this.onMenuClicked, 60 isAutoTint: item.getLeftAction().isAutoTint, 61 colorMode: item.getColorMode(), 62 isFirst: true 63 }) 64 }, (item: ActionBarProp) => {return item.getLeftAction().actionID.toString()}) 65 } 66 if (this.actionBarProp.getMode() === ActionBarMode.DETAIL_MODE) { 67 } else if (this.actionBarProp.getMode() === ActionBarMode.SELECTION_MODE) { 68 Stack({ alignContent: Alignment.Start }) { 69 SelectionTitle({ actionBarProp: $actionBarProp }) 70 }.flexGrow(1) 71 } else if (this.actionBarProp.getMode() === ActionBarMode.TOP_MODE) { 72 Stack({ alignContent: Alignment.Start }) { 73 DetailTitle({ isVideoPage: this.isVideoPage }) 74 }.flexGrow(1) 75 } else { 76 Stack({ alignContent: Alignment.Start }) { 77 SingleTitle({ actionBarProp: $actionBarProp }) 78 }.flexGrow(1) 79 } 80 DetailMenuPanel({ actionBarProp: $actionBarProp, onMenuClicked: this.onMenuClicked }) 81 } 82 .height(Constants.ActionBarHeight) 83 .alignItems(VerticalAlign.Center) 84 .zIndex(3) 85 .width('100%') 86 .backgroundColor(this.actionBarProp.getBackgroundColor()) 87 .opacity(this.actionBarProp.getAlpha()) 88 .padding({ right: $r('app.float.default_actionbar_padding_right'), 89 left: (this.hasTabBar ? 90 $r('app.float.default_padding_start_with_tab_bar') : 91 $r('app.float.default_actionbar_padding_start_without_tab_bar')) 92 }) 93 } 94}