• 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        }.width(Constants.CLICK_SHADOW_LENGTH)
40        .height(Constants.CLICK_SHADOW_LENGTH)
41        .borderRadius($r('sys.float.ohos_id_corner_radius_clicked'))
42        .alignItems(VerticalAlign.Center)
43        .justifyContent(FlexAlign.Center)
44        .margin({
45          left: Constants.DEFAULT_MARGIN_START,
46          right: Constants.BACKBAR_MARGIN_RIGHT
47        })
48        .backgroundColor(this.isBack ? $r('sys.color.ohos_id_color_click_effect') : '')
49        .onTouch(event => {
50          if (event === undefined) {
51            return;
52          }
53          if (event.type === TouchType.Down) {
54            this.isBack = true;
55          }
56          if (event.type === TouchType.Up) {
57            this.isBack = false;
58          }
59        })
60        .onClick(() => {
61          let length = router.getLength();
62          Number(length) == 1 ? this.context.terminateSelf() : router.back();
63        })
64        Text(JSON.parse(this.title))
65          .align(Alignment.Start)
66          .fontColor($r('sys.color.ohos_id_color_text_primary'))
67          .maxLines(Constants.MAXIMUM_HEADER_LINES)
68          .textOverflow({ overflow: TextOverflow.Ellipsis })
69          .fontSize(Constants.TEXT_BIG_FONT_SIZE)
70          .flexGrow(Constants.FLEX_GROW)
71          .fontWeight(FontWeight.Bold)
72        if (this.recordable) {
73          Row() {
74            Image($r("app.media.gongneng_dian"))
75              .fillColor($r('sys.color.ohos_id_color_primary'))
76              .objectFit(ImageFit.Contain)
77              .height(Constants.BACKBAR_IMAGE_HEIGHT)
78              .width(Constants.BACKBAR_IMAGE_WIDTH)
79          }.width(Constants.CLICK_SHADOW_LENGTH)
80          .height(Constants.CLICK_SHADOW_LENGTH)
81          .borderRadius($r('sys.float.ohos_id_corner_radius_clicked'))
82          .alignItems(VerticalAlign.Center)
83          .justifyContent(FlexAlign.Center)
84          .margin({
85            right: Constants.DEFAULT_MARGIN_END
86          })
87          .bindMenu(this.MenuBuilder())
88          .backgroundColor(this.isMore ? $r('sys.color.ohos_id_color_click_effect') : '')
89          .onTouch(event => {
90            if (event === undefined) {
91              return;
92            }
93            if (event.type === TouchType.Down) {
94              this.isMore = true;
95            }
96            if (event.type === TouchType.Up) {
97              this.isMore = false;
98            }
99          })
100        }
101      }
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.ohos_id_color_sub_background"))
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.ohos_id_color_text_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.ohos_id_color_list_card_bg"), 1], [$r("sys.color.ohos_id_color_list_card_bg"), 1]]
129        })
130      .onTouch(event => {
131        if (event === undefined) {
132          return;
133        }
134        if (event.type === TouchType.Down) {
135          this.isTouch = 'true';
136        }
137        if (event.type === TouchType.Up) {
138          this.isTouch = '';
139        }
140      })
141      .onClick(() => {
142        router.pushUrl({ url: 'pages/permission-access-record' })
143      })
144    }
145  }
146}