• 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
16@Styles function pressedStyles () {
17  .borderRadius($r('app.float.common_borderRadius10'))
18  .backgroundColor($r('app.color.hicloud_hmos_bg'))
19}
20
21@Styles function normalStyles () {
22  .borderRadius($r('app.float.common_borderRadius8'))
23  .backgroundColor($r('app.color.transparent_color'))
24}
25
26@Component
27export struct TopOperateBar {
28  public addFolder: () => void // 点击新建的事件回调
29  // 是否可用
30  @Prop isDisabled: boolean = false
31  // 列表或宫格
32  @Consume isList: boolean
33
34  getUsageHabitsKey(prefix: string, suffix: string): string {
35    return prefix + suffix.charAt(0).toLocaleUpperCase() + suffix.substring(1)
36  }
37
38  build() {
39    Row() {
40      Column() {
41        Image($r('app.media.hidisk_ic_add_folder'))
42          .objectFit(ImageFit.Contain)
43          .width($r('app.float.common_size24'))
44          .height($r('app.float.common_size24'))
45      }.padding({
46        left: $r('app.float.common_padding12'),
47        right: $r('app.float.common_padding12'),
48        top: $r('app.float.common_padding10'),
49        bottom: $r('app.float.common_padding10')
50      })
51      .stateStyles({
52        pressed: pressedStyles,
53        normal: normalStyles
54      })
55      .onClick(() => {
56        if (this.isDisabled) return
57        this.addFolder.call(this)
58      })
59
60      Column() {
61        if (this.isList) {
62          Image($r('app.media.hidisk_switch_grid'))
63            .width($r('app.float.common_size24'))
64            .height($r('app.float.common_size24'))
65        } else {
66          Image($r('app.media.hidisk_switch_list'))
67            .width($r('app.float.common_size24'))
68            .height($r('app.float.common_size24'))
69        }
70      }.padding({
71        top: $r('app.float.common_padding10'),
72        bottom: $r('app.float.common_padding10'),
73        left: $r('app.float.common_padding12'),
74        right: $r('app.float.common_padding12')
75      })
76      .onClick(() => {
77        if (this.isDisabled) return
78        this.isList = !this.isList
79      }).stateStyles({
80        pressed: pressedStyles,
81        normal: normalStyles
82      })
83    }
84    .width('100%')
85    .padding({
86      left: $r('app.float.common_padding4'),
87      right: $r('app.float.common_padding4'),
88      top: $r('app.float.common_padding10'),
89      bottom: $r('app.float.common_padding10')
90    })
91    .justifyContent(FlexAlign.SpaceBetween)
92    .alignItems(VerticalAlign.Center)
93    .opacity(this.isDisabled ? $r('app.float.common_opacity4') : $r('app.float.common_opacity10'))
94  }
95}