1/* 2 * Copyright (c) 2021-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 router from '@ohos.router'; 17import common from '@ohos.app.ability.common'; 18import Constants from '../utils/constant'; 19 20@Component 21export struct backBar { 22 private context = getContext(this) as common.UIAbilityContext; 23 @Prop title: string = ''; // return title name 24 @Prop recordable: boolean = false; 25 @State record: string = ''; 26 @State isTouch: string = ''; 27 @State isBack: boolean = false; 28 @State isMore: boolean = false; 29 30 build() { 31 Column() { 32 Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { 33 Row() { 34 SymbolGlyph($r('sys.symbol.arrow_left')) 35 .width(Constants.BACKBAR_IMAGE_WIDTH) 36 .height(Constants.BACKBAR_IMAGE_HEIGHT) 37 .fontSize(Constants.FONT_SIZE_24_vp) 38 .fontColor([$r('sys.color.icon_primary')]) 39 .fontWeight(FontWeight.Medium) 40 }.width(Constants.CLICK_SHADOW_LENGTH) 41 .height(Constants.CLICK_SHADOW_LENGTH) 42 .borderRadius($r('sys.float.ohos_id_corner_radius_clicked')) 43 .alignItems(VerticalAlign.Center) 44 .justifyContent(FlexAlign.Center) 45 .backgroundColor(this.isBack ? $r('sys.color.interactive_click') : '') 46 .onTouch(event => { 47 if (event === undefined) { 48 return; 49 } 50 if (event.type === TouchType.Down) { 51 this.isBack = true; 52 } 53 if (event.type === TouchType.Up) { 54 this.isBack = false; 55 } 56 }) 57 .onClick(() => { 58 let length = router.getLength(); 59 Number(length) == 1 ? this.context.terminateSelf() : router.back(); 60 }) 61 Text(JSON.parse(this.title)) 62 .align(Alignment.Start) 63 .fontColor($r('sys.color.font_primary')) 64 .maxLines(Constants.MAXIMUM_HEADER_LINES) 65 .textOverflow({ overflow: TextOverflow.Ellipsis }) 66 .fontSize(Constants.TEXT_BIG_FONT_SIZE) 67 .flexGrow(Constants.FLEX_GROW) 68 .fontWeight(FontWeight.Bold) 69 .margin({ left: Constants.MARGIN_4, right: Constants.MARGIN_4 }) 70 if (this.recordable) { 71 Row() { 72 Image($r('sys.media.ohos_ic_public_more')) 73 .fillColor($r('sys.color.icon_primary')) 74 .objectFit(ImageFit.Contain) 75 .height(Constants.BACKBAR_IMAGE_WIDTH) 76 .width(Constants.BACKBAR_IMAGE_HEIGHT) 77 .draggable(false) 78 }.width(Constants.CLICK_SHADOW_LENGTH) 79 .height(Constants.CLICK_SHADOW_LENGTH) 80 .borderRadius($r('sys.float.ohos_id_corner_radius_clicked')) 81 .alignItems(VerticalAlign.Center) 82 .justifyContent(FlexAlign.Center) 83 .bindMenu(this.MenuBuilder()) 84 .backgroundColor(this.isMore ? $r('sys.color.interactive_click') : '') 85 .onTouch(event => { 86 if (event === undefined) { 87 return; 88 } 89 if (event.type === TouchType.Down) { 90 this.isMore = true; 91 } 92 if (event.type === TouchType.Up) { 93 this.isMore = false; 94 } 95 }) 96 } 97 } 98 .margin({ left: Constants.DEFAULT_MARGIN_START, right: Constants.DEFAULT_MARGIN_END }) 99 } 100 .height(Constants.BACKBAR_HEIGHT) 101 .constraintSize({ minHeight: Constants.BACKBAR_MINHEIGHT }) 102 .alignItems(HorizontalAlign.Start) 103 .justifyContent(FlexAlign.Center) 104 .backgroundColor($r('sys.color.background_secondary')) 105 } 106 107 @Builder MenuBuilder() { 108 Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 109 Row() { 110 Text($r('app.string.permission_access_record')) 111 .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) 112 .fontWeight(FontWeight.Medium) 113 .fontColor($r('sys.color.font_primary')) 114 }.constraintSize({ minWidth: Constants.MAXIMUM_HEADER_WIDTH }) 115 .height(Constants.LISTITEM_ROW_HEIGHT) 116 .padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) 117 .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) 118 .linearGradient((this.isTouch === 'true') ? { 119 angle: 90, 120 direction: GradientDirection.Right, 121 colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]] 122 } : { 123 angle: 90, 124 direction: GradientDirection.Right, 125 colors: [[$r('sys.color.comp_background_list_card'), 1], [$r('sys.color.comp_background_list_card'), 1]] 126 }) 127 .onTouch(event => { 128 if (event === undefined) { 129 return; 130 } 131 if (event.type === TouchType.Down) { 132 this.isTouch = 'true'; 133 } 134 if (event.type === TouchType.Up) { 135 this.isTouch = ''; 136 } 137 }) 138 .onClick(() => { 139 router.pushUrl({ url: 'pages/permission-access-record' }) 140 }) 141 } 142 } 143}