• 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 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          Image($r('app.media.ic_public_back'))
35            .fillColor($r('sys.color.ohos_id_color_primary'))
36            .objectFit(ImageFit.Contain)
37            .height(Constants.BACKBAR_IMAGE_HEIGHT)
38            .width(Constants.BACKBAR_IMAGE_WIDTH)
39            .draggable(false)
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        .margin({
46          left: Constants.DEFAULT_MARGIN_START,
47          right: Constants.BACKBAR_MARGIN_RIGHT
48        })
49        .backgroundColor(this.isBack ? $r('sys.color.ohos_id_color_click_effect') : '')
50        .onTouch(event => {
51          if (event === undefined) {
52            return;
53          }
54          if (event.type === TouchType.Down) {
55            this.isBack = true;
56          }
57          if (event.type === TouchType.Up) {
58            this.isBack = false;
59          }
60        })
61        .onClick(() => {
62          let length = router.getLength();
63          Number(length) == 1 ? this.context.terminateSelf() : router.back();
64        })
65        Text(JSON.parse(this.title))
66          .align(Alignment.Start)
67          .fontColor($r('sys.color.ohos_id_color_text_primary'))
68          .maxLines(Constants.MAXIMUM_HEADER_LINES)
69          .textOverflow({ overflow: TextOverflow.Ellipsis })
70          .fontSize(Constants.TEXT_BIG_FONT_SIZE)
71          .flexGrow(Constants.FLEX_GROW)
72          .fontWeight(FontWeight.Bold)
73        if (this.recordable) {
74          Row() {
75            Image($r("sys.media.ohos_ic_public_more"))
76              .fillColor($r('sys.color.ohos_id_color_primary'))
77              .objectFit(ImageFit.Contain)
78              .height(Constants.BACKBAR_IMAGE_WIDTH)
79              .width(Constants.BACKBAR_IMAGE_HEIGHT)
80              .draggable(false)
81          }.width(Constants.CLICK_SHADOW_LENGTH)
82          .height(Constants.CLICK_SHADOW_LENGTH)
83          .borderRadius($r('sys.float.ohos_id_corner_radius_clicked'))
84          .alignItems(VerticalAlign.Center)
85          .justifyContent(FlexAlign.Center)
86          .margin({
87            right: Constants.DEFAULT_MARGIN_END
88          })
89          .bindMenu(this.MenuBuilder())
90          .backgroundColor(this.isMore ? $r('sys.color.ohos_id_color_click_effect') : '')
91          .onTouch(event => {
92            if (event === undefined) {
93              return;
94            }
95            if (event.type === TouchType.Down) {
96              this.isMore = true;
97            }
98            if (event.type === TouchType.Up) {
99              this.isMore = false;
100            }
101          })
102        }
103      }
104    }
105    .height(Constants.BACKBAR_HEIGHT)
106    .constraintSize({ minHeight: Constants.BACKBAR_MINHEIGHT })
107    .alignItems(HorizontalAlign.Start)
108    .justifyContent(FlexAlign.Center)
109    .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
110  }
111
112  @Builder MenuBuilder() {
113    Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
114      Row() {
115        Text($r("app.string.permission_access_record"))
116          .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE)
117          .fontWeight(FontWeight.Medium)
118          .fontColor($r('sys.color.ohos_id_color_text_primary'))
119      }.constraintSize({ minWidth: Constants.MAXIMUM_HEADER_WIDTH })
120      .height(Constants.LISTITEM_ROW_HEIGHT)
121      .padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') })
122      .borderRadius($r("sys.float.ohos_id_corner_radius_default_l"))
123      .linearGradient((this.isTouch === 'true') ? {
124          angle: 90,
125          direction: GradientDirection.Right,
126          colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]]
127        } : {
128          angle: 90,
129          direction: GradientDirection.Right,
130          colors: [[$r("sys.color.ohos_id_color_list_card_bg"), 1], [$r("sys.color.ohos_id_color_list_card_bg"), 1]]
131        })
132      .onTouch(event => {
133        if (event === undefined) {
134          return;
135        }
136        if (event.type === TouchType.Down) {
137          this.isTouch = 'true';
138        }
139        if (event.type === TouchType.Up) {
140          this.isTouch = '';
141        }
142      })
143      .onClick(() => {
144        router.pushUrl({ url: 'pages/permission-access-record' })
145      })
146    }
147  }
148}