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