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 */ 15import router from '@ohos.router' 16 17@Component 18export default struct TitleBar { 19 private title: string | Resource = $r('app.string.MainAbility_label') 20 private rightBtn?: Resource 21 private onRightBtnClicked?: () => void 22 private hasBackPress: boolean = false 23 24 build() { 25 Row() { 26 if (this.hasBackPress) { 27 Image($r('app.media.ic_back')) 28 .width(50).height('100%') 29 .objectFit(ImageFit.Contain) 30 .onClick(() => { 31 router.back() 32 }) 33 } 34 Text(this.title) 35 .fontColor(Color.White) 36 .fontSize(28) 37 Blank() 38 if (this.rightBtn) { 39 Image(this.rightBtn) 40 .width(50).height('100%') 41 .objectFit(ImageFit.Contain) 42 .onClick(this.onRightBtnClicked) 43 } 44 } 45 .width('100%') 46 .height('8%') 47 .constraintSize({ minHeight: 70 }) 48 .padding({ left: 10, right: 10 }) 49 .backgroundColor('#0D9FFB') 50 } 51}