• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 common from '@ohos.app.ability.common';
17import Constants from '../utils/constant';
18import { Log } from '../utils/utils';
19
20@Component
21export struct backBar {
22  private context = this.getUIContext().getHostContext() 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            Log.info('touch event is undefined.');
49            return;
50          }
51          if (event.type === TouchType.Down) {
52            this.isBack = true;
53          }
54          if (event.type === TouchType.Up) {
55            this.isBack = false;
56          }
57        })
58        .onClick(() => {
59          let router = this.getUIContext().getRouter();
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        this.getUIContext().getRouter().pushUrl({ url: 'pages/permission-access-record' })
144      })
145    }
146  }
147}