• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { Constants } from './Constants';
2/*
3 * Copyright (c) 2022 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17@Observed
18export class TabItem {
19  name: Resource;
20  iconResource: Resource;
21  iconSelectedResource: Resource;
22  iconDefault: Resource = $r('sys.color.ohos_id_color_bottom_tab_icon_off');
23  iconSelected: Resource | null = null;
24  textColorDefault: Resource = $r('sys.color.ohos_id_color_text_primary');
25  textColorSelected: Resource = $r('sys.color.ohos_id_color_bottom_tab_text_on');
26  textFamilyDefault: Resource = $r('sys.string.ohos_id_text_font_family_medium');
27  textFamilySelected: Resource = $r('sys.string.ohos_id_text_font_family_medium');
28  isSelected: boolean;
29  componentKey: string;
30
31  constructor(name: Resource, iconResource: Resource, iconSelectedResource: Resource, isSelected: boolean, textColorDefault: Resource, componentKey: string) {
32    this.name = name;
33    this.iconResource = iconResource;
34    this.iconSelectedResource = iconSelectedResource;
35    this.isSelected = isSelected;
36    this.textColorDefault = textColorDefault;
37    this.componentKey = componentKey;
38  }
39
40  getConditionIcon(isSelected: boolean): Resource {
41    return isSelected ? this.iconSelected as Resource : this.iconDefault;
42  }
43
44  getIcon(isSelected: boolean): Resource {
45    return isSelected ? this.iconSelectedResource : this.iconResource;
46  }
47
48  getTextColor(): Resource {
49    return this.isSelected ? this.textColorSelected : this.textColorDefault;
50  }
51
52  getTextFamily(): Resource {
53    return this.isSelected ? this.textColorSelected : this.textColorDefault;
54  }
55}
56
57// Tab Bar which only has text
58// For Album Set
59@Observed
60export class TabItemWithText {
61  name: Resource;
62  isSelected: boolean;
63  textSizeDefault: Resource = $r('sys.float.ohos_id_text_size_body1');
64  textSizeSelected: Resource = $r('sys.float.ohos_id_text_size_sub_title2');
65  textWeightDefault: FontWeight = FontWeight.Regular;
66  textWeightSelected: FontWeight = FontWeight.Medium;
67  textColorDefault: Resource = $r('sys.color.ohos_id_color_bottom_tab_text_off');
68  textColorSelected: Resource = $r('app.color.color_system_highlight');
69
70  constructor(name: Resource, isSelected: boolean) {
71    this.name = name;
72    this.isSelected = isSelected;
73  }
74
75  getTextSize(): Resource {
76    return this.isSelected ? this.textSizeSelected : this.textSizeDefault;
77  }
78
79  getTextWeight(): FontWeight {
80    return this.isSelected ? this.textWeightSelected : this.textWeightDefault;
81  }
82
83  getTextColor(): Resource {
84    return this.isSelected ? this.textColorSelected : this.textColorDefault;
85  }
86}