• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-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 {
17  BroadCast,
18  BroadCastConstants,
19} from '@ohos/common';
20import deviceInfo from '@ohos.deviceInfo';
21import SmartPickerConstants from '../common/SmartPickerConstants';
22import SmartPickerRecommendTabInfo from '../common/SmartPickerRecommendTabInfo';
23
24@Component
25export struct ThirdSelectSmartRecommendTabBar {
26  @Link currentTabIndex: number;
27  @Link smartRecommendTabItems: Array<SmartPickerRecommendTabInfo>;
28  @Consume broadCast: BroadCast;
29  private staticTitleMap = new Map([
30    [SmartPickerConstants.LABEL_ID_CARD, $r('app.string.photo_id_card')],
31    [SmartPickerConstants.LABEL_QR_CODE, $r('app.string.photo_qr_code')],
32    [SmartPickerConstants.LABEL_BAR_CODE, $r('app.string.photo_bar_code')],
33    [SmartPickerConstants.LABEL_ALL_PHOTO, $r('app.string.photo_all')],
34    [SmartPickerConstants.LABEL_AVATAR, $r('app.string.photo_profile_picture')],
35  ]);
36
37  build() {
38    Row() {
39      ForEach(this.smartRecommendTabItems, (item: SmartPickerRecommendTabInfo, index: number) => {
40        Row() {
41          Text(this.getTabTitle(item))
42            .fontColor(this.currentTabIndex === index ? $r('sys.color.ohos_id_color_text_primary_dark') : $r('sys.color.ohos_id_color_text_secondary'))
43            .fontSize($r('sys.float.ohos_id_text_size_button3'))
44            .fontWeight(FontWeight.Regular)
45            .draggable(false)
46            .margin({ left: $r('app.float.picker_smart_recommend_tab_text_margin_left') })
47            .lineHeight($r('app.float.picker_smart_recommend_tab_text_height'))
48        }
49        .backgroundColor(this.currentTabIndex === index ? $r('sys.color.ohos_id_color_secondary') : $r('sys.color.ohos_id_color_button_normal'))
50        .height($r('app.float.picker_smart_recommend_tab_height'))
51        .margin({ left: index === 0 ? 0 : $r('app.float.picker_smart_recommend_tab_margin_left') })
52        .padding({ left: $r('app.float.picker_smart_recommend_tab_left_padding'), right: $r('app.float.picker_smart_recommend_tab_right_padding') })
53        .borderRadius(SmartPickerConstants.RECOMMEND_TAB_BORDER_RADIUS)
54        .key('pickerRecommendTab_' + index)
55        .onClick((event: ClickEvent) => {
56          this.changeTab(index);
57        })
58      })
59    }
60    .alignSelf(ItemAlign.Start)
61    .margin({ bottom: $r('app.float.picker_smart_recommend_tab_bar_margin_bottom') })
62    .padding({ top: $r('app.float.picker_smart_recommend_tab_bar_padding_top'), bottom: $r('app.float.picker_smart_recommend_tab_bar_padding_bottom') })
63  }
64
65  private changeTab(index: number): void {
66    if (this.currentTabIndex === index) {
67      return;
68    }
69    this.currentTabIndex = index;
70    this.broadCast.emit(BroadCastConstants.THIRD_PICKER_SWITCH_SMART_RECOMMEND_TAB, [this.currentTabIndex]);
71  }
72
73  private getTabTitle(item: SmartPickerRecommendTabInfo): Resource {
74    let titleRes: Resource = $r('app.string.photo_all');
75    if (this.staticTitleMap.has(item.getLabelId())) {
76      titleRes = this.staticTitleMap.get(item.getLabelId()) as Resource;
77    }
78    return titleRes;
79  }
80}