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 ConfigData from '../Utils/ConfigData'; 16import Router from '@system.router'; 17 18/** 19 * head custom component 20 */ 21@Component 22export default 23struct HeadComponent { 24 private isActive: boolean= true; 25 private icBackIsVisibility: boolean= true; 26 private headName: string | Resource = ''; 27 @State isTouch: boolean= false; 28 29 build() { 30 Row() { 31 Stack({ alignContent: Alignment.Center }) { 32 Image($r('app.media.ic_back')) 33 .width($r('app.float.wh_value_30')) 34 .height($r('app.float.wh_value_30')) 35 } 36 .margin({left: $r('app.float.wh_value_4'), right: $r('app.float.wh_value_16')}) 37 .backgroundColor(this.isTouch ? $r('app.color.color_E3E3E3_grey') : $r('app.color.color_00000000_transparent')) 38 .visibility(this.icBackIsVisibility ? Visibility.Visible : Visibility.None) 39 .onClick(() => { 40 Router.back(); 41 }) 42 .onTouch((event: TouchEvent) => { 43 if (event.type === TouchType.Down) { 44 this.isTouch = true; 45 } 46 if (event.type === TouchType.Up) { 47 this.isTouch = false; 48 } 49 }); 50 51 Text(this.headName) 52 .fontSize($r('app.float.font_24')) 53 .lineHeight($r('app.float.wh_value_33')) 54 .fontFamily('HarmonyHeiTi-Bold') 55 .fontWeight(FontWeight.Bold) 56 .fontColor($r('app.color.font_color_182431')) 57 .maxLines(ConfigData.MAX_LINES_1) 58 .textOverflow({ overflow: TextOverflow.Ellipsis }) 59 .textAlign(TextAlign.Start) 60 .margin({ top: $r('app.float.wh_value_13'), bottom: $r('app.float.wh_value_15') }); 61 } 62 .width(ConfigData.WH_100_100) 63 .padding({ left: $r('app.float.wh_value_8') }) 64 .height($r('app.float.wh_value_56')) 65 .alignItems(VerticalAlign.Center) 66 .align(Alignment.Start); 67 } 68}