100aff185Sopenharmony_ci/** 200aff185Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 300aff185Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 400aff185Sopenharmony_ci * you may not use this file except in compliance with the License. 500aff185Sopenharmony_ci * You may obtain a copy of the License at 600aff185Sopenharmony_ci * 700aff185Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 800aff185Sopenharmony_ci * 900aff185Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1000aff185Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1100aff185Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1200aff185Sopenharmony_ci * See the License for the specific language governing permissions and 1300aff185Sopenharmony_ci * limitations under the License. 1400aff185Sopenharmony_ci */ 1500aff185Sopenharmony_ci 1600aff185Sopenharmony_ciimport { Log } from '../utils/Log'; 1700aff185Sopenharmony_ciimport { TabItem, TabItemWithText } from '../model/common/TabItem'; 1800aff185Sopenharmony_ciimport { BroadCastManager } from '../model/common/BroadCastManager'; 1900aff185Sopenharmony_ciimport { BroadCast } from '../utils/BroadCast'; 2000aff185Sopenharmony_ciimport { BroadCastConstants } from '../model/common/BroadCastConstants'; 2100aff185Sopenharmony_ciimport { Constants } from '../model/common/Constants'; 2200aff185Sopenharmony_ciimport { BigDataConstants, ReportToBigDataUtil } from '../utils/ReportToBigDataUtil'; 2300aff185Sopenharmony_ci 2400aff185Sopenharmony_ciconst TAG: string = 'common_TabBar'; 2500aff185Sopenharmony_ci 2600aff185Sopenharmony_ciexport enum DeviceType { 2700aff185Sopenharmony_ci PHONE_LIKE, 2800aff185Sopenharmony_ci PC_LIKE 2900aff185Sopenharmony_ci} 3000aff185Sopenharmony_ci 3100aff185Sopenharmony_ciconst tabMap = [ 3200aff185Sopenharmony_ciBigDataConstants.PHOTO_TAB, 3300aff185Sopenharmony_ciBigDataConstants.ALBUM_TAB 3400aff185Sopenharmony_ci] 3500aff185Sopenharmony_ci 3600aff185Sopenharmony_ci@Component 3700aff185Sopenharmony_ciexport struct TabBar { 3800aff185Sopenharmony_ci @Consume isSelectedMode: boolean; 3900aff185Sopenharmony_ci @Consume isAlbumSetSelectedMode: boolean; 4000aff185Sopenharmony_ci @Consume isShowSideBar: boolean; 4100aff185Sopenharmony_ci @Link @Watch('updateCurrentIndex') currentIndex: 0 | 1; 4200aff185Sopenharmony_ci @Link isSidebar: boolean; 4300aff185Sopenharmony_ci @StorageLink('sideBarBoundaryLineOpacity') sideBarBoundaryLineOpacity: number = 1; 4400aff185Sopenharmony_ci @StorageLink('sideBarOpacity') sideBarOpacity: number = 1; 4500aff185Sopenharmony_ci private tabs: TabItem[] = []; 4600aff185Sopenharmony_ci private controller: TabsController | null = null; 4700aff185Sopenharmony_ci private appBroadCast: BroadCast = BroadCastManager.getInstance().getBroadCast(); 4800aff185Sopenharmony_ci private deviceType: DeviceType = DeviceType.PC_LIKE; 4900aff185Sopenharmony_ci private funcOnTabSelected?: Function; 5000aff185Sopenharmony_ci 5100aff185Sopenharmony_ci aboutToAppear(): void { 5200aff185Sopenharmony_ci this.funcOnTabSelected = (index: number): void => this.onTabSelected(index); 5300aff185Sopenharmony_ci this.tabs[this.currentIndex].isSelected = true; 5400aff185Sopenharmony_ci this.tabs.forEach((tab: TabItem) => { 5500aff185Sopenharmony_ci Log.info(TAG, `${JSON.stringify(tab.name)} , ${tab.iconSelected}`); 5600aff185Sopenharmony_ci }); 5700aff185Sopenharmony_ci } 5800aff185Sopenharmony_ci 5900aff185Sopenharmony_ci updateCurrentIndex(): void { 6000aff185Sopenharmony_ci this.onTabSelected(this.currentIndex); 6100aff185Sopenharmony_ci } 6200aff185Sopenharmony_ci 6300aff185Sopenharmony_ci build() { 6400aff185Sopenharmony_ci if (this.isSidebar) { 6500aff185Sopenharmony_ci if (this.deviceType == DeviceType.PC_LIKE) { 6600aff185Sopenharmony_ci Row() { 6700aff185Sopenharmony_ci Flex({ 6800aff185Sopenharmony_ci direction: FlexDirection.Column, 6900aff185Sopenharmony_ci alignItems: ItemAlign.Start, 7000aff185Sopenharmony_ci justifyContent: FlexAlign.Start 7100aff185Sopenharmony_ci }) { 7200aff185Sopenharmony_ci ForEach(this.tabs, (tab: TabItem) => { 7300aff185Sopenharmony_ci Tab({ 7400aff185Sopenharmony_ci tabItem: tab, 7500aff185Sopenharmony_ci index: this.tabs.indexOf(tab), 7600aff185Sopenharmony_ci onTabSelected: this.funcOnTabSelected, 7700aff185Sopenharmony_ci isSidebar: $isSidebar, 7800aff185Sopenharmony_ci deviceType: this.deviceType 7900aff185Sopenharmony_ci }) 8000aff185Sopenharmony_ci }, (tab: TabItem): string => { 8100aff185Sopenharmony_ci return (tab.name.id).toString(); 8200aff185Sopenharmony_ci }) 8300aff185Sopenharmony_ci } 8400aff185Sopenharmony_ci .padding({ left: 16, top: 96, right: 16 }) 8500aff185Sopenharmony_ci .flexGrow(1) 8600aff185Sopenharmony_ci .backgroundColor($r('app.color.default_background_color')) 8700aff185Sopenharmony_ci 8800aff185Sopenharmony_ci // Sidebar boundary line 8900aff185Sopenharmony_ci if (this.isShowSideBar) { 9000aff185Sopenharmony_ci Row() { 9100aff185Sopenharmony_ci } 9200aff185Sopenharmony_ci .width(0) 9300aff185Sopenharmony_ci .height(Constants.PERCENT_100) 9400aff185Sopenharmony_ci .border({ width: 0.5, color: $r('app.color.album_cover_gradient_start_color') }) 9500aff185Sopenharmony_ci .opacity(this.sideBarBoundaryLineOpacity) 9600aff185Sopenharmony_ci } 9700aff185Sopenharmony_ci } 9800aff185Sopenharmony_ci } else { 9900aff185Sopenharmony_ci Flex({ 10000aff185Sopenharmony_ci direction: FlexDirection.Column, 10100aff185Sopenharmony_ci alignItems: ItemAlign.Center, 10200aff185Sopenharmony_ci justifyContent: FlexAlign.Center 10300aff185Sopenharmony_ci }) { 10400aff185Sopenharmony_ci Column() { 10500aff185Sopenharmony_ci ForEach(this.tabs, (tab: TabItem) => { 10600aff185Sopenharmony_ci Stack() { 10700aff185Sopenharmony_ci Tab({ 10800aff185Sopenharmony_ci tabItem: tab, 10900aff185Sopenharmony_ci index: this.tabs.indexOf(tab), 11000aff185Sopenharmony_ci onTabSelected: this.funcOnTabSelected, 11100aff185Sopenharmony_ci isSidebar: $isSidebar, 11200aff185Sopenharmony_ci deviceType: this.deviceType 11300aff185Sopenharmony_ci }) 11400aff185Sopenharmony_ci } 11500aff185Sopenharmony_ci .layoutWeight(1) 11600aff185Sopenharmony_ci }, (tab: TabItem): string => { 11700aff185Sopenharmony_ci return (tab.name.id).toString(); 11800aff185Sopenharmony_ci }) 11900aff185Sopenharmony_ci } 12000aff185Sopenharmony_ci .height($r('app.float.horizontal_width')) 12100aff185Sopenharmony_ci } 12200aff185Sopenharmony_ci .width($r('app.float.tab_bar_width')) 12300aff185Sopenharmony_ci .backgroundColor($r('app.color.default_background_color')) 12400aff185Sopenharmony_ci } 12500aff185Sopenharmony_ci 12600aff185Sopenharmony_ci } else { 12700aff185Sopenharmony_ci Flex({ 12800aff185Sopenharmony_ci direction: FlexDirection.Row, 12900aff185Sopenharmony_ci alignItems: ItemAlign.Center, 13000aff185Sopenharmony_ci justifyContent: FlexAlign.Center 13100aff185Sopenharmony_ci }) { 13200aff185Sopenharmony_ci ForEach(this.tabs, (tab: TabItem) => { 13300aff185Sopenharmony_ci Stack() { 13400aff185Sopenharmony_ci TabPhone({ tabItem: tab, index: this.tabs.indexOf(tab), onTabSelected: this.funcOnTabSelected }) 13500aff185Sopenharmony_ci } 13600aff185Sopenharmony_ci .layoutWeight(1) 13700aff185Sopenharmony_ci .onClick(() => { 13800aff185Sopenharmony_ci if (this.funcOnTabSelected) { 13900aff185Sopenharmony_ci if (this.currentIndex == this.tabs.indexOf(tab)) { 14000aff185Sopenharmony_ci Log.debug(TAG, `it is same: ${this.currentIndex}`); 14100aff185Sopenharmony_ci this.appBroadCast.emit(BroadCastConstants.RESET_ZERO, [this.currentIndex]); 14200aff185Sopenharmony_ci } 14300aff185Sopenharmony_ci this.funcOnTabSelected(this.tabs.indexOf(tab)); 14400aff185Sopenharmony_ci } 14500aff185Sopenharmony_ci tab.isSelected = true; 14600aff185Sopenharmony_ci }) 14700aff185Sopenharmony_ci }, (tab: TabItem): string => { 14800aff185Sopenharmony_ci return (tab.name.id).toString(); 14900aff185Sopenharmony_ci }) 15000aff185Sopenharmony_ci } 15100aff185Sopenharmony_ci .visibility((this.isSelectedMode || this.isAlbumSetSelectedMode) ? Visibility.None : Visibility.Visible) 15200aff185Sopenharmony_ci .height($r('app.float.tab_bar_vertical_height')) 15300aff185Sopenharmony_ci .backgroundColor($r('app.color.default_background_color')) 15400aff185Sopenharmony_ci .padding({ left: $r('app.float.max_padding_start'), right: $r('app.float.max_padding_end') }) 15500aff185Sopenharmony_ci } 15600aff185Sopenharmony_ci } 15700aff185Sopenharmony_ci 15800aff185Sopenharmony_ci private onTabSelected(index: number): void { 15900aff185Sopenharmony_ci Log.debug(TAG, `TabBar this.currentIndex: ${this.currentIndex} index: ${index}`); 16000aff185Sopenharmony_ci this.currentIndex = index as 0 | 1; 16100aff185Sopenharmony_ci if (this.controller != null) { 16200aff185Sopenharmony_ci this.controller.changeIndex(this.currentIndex); 16300aff185Sopenharmony_ci }; 16400aff185Sopenharmony_ci this.tabs.forEach((tab: TabItem) => { 16500aff185Sopenharmony_ci if (this.tabs.indexOf(tab) == index) { 16600aff185Sopenharmony_ci tab.isSelected = true; 16700aff185Sopenharmony_ci } else { 16800aff185Sopenharmony_ci tab.isSelected = false; 16900aff185Sopenharmony_ci } 17000aff185Sopenharmony_ci }) 17100aff185Sopenharmony_ci let currentTab: string = tabMap[this.currentIndex] ? tabMap[this.currentIndex] : BigDataConstants.PHOTO_TAB; 17200aff185Sopenharmony_ci interface Msg { 17300aff185Sopenharmony_ci switchTab: string; 17400aff185Sopenharmony_ci current: string; 17500aff185Sopenharmony_ci } 17600aff185Sopenharmony_ci let msg: Msg = { 17700aff185Sopenharmony_ci switchTab: BigDataConstants.CLICK_SWITCH, 17800aff185Sopenharmony_ci current: currentTab, 17900aff185Sopenharmony_ci } 18000aff185Sopenharmony_ci ReportToBigDataUtil.report(BigDataConstants.TAB_SWITCH_ID, msg); 18100aff185Sopenharmony_ci Log.info(TAG, `select ${this.currentIndex}`); 18200aff185Sopenharmony_ci } 18300aff185Sopenharmony_ci} 18400aff185Sopenharmony_ci 18500aff185Sopenharmony_ci// single tab 18600aff185Sopenharmony_ci@Component 18700aff185Sopenharmony_cistruct Tab { 18800aff185Sopenharmony_ci @ObjectLink tabItem: TabItem; 18900aff185Sopenharmony_ci @Link isSidebar: boolean; 19000aff185Sopenharmony_ci index: number = 0; 19100aff185Sopenharmony_ci onTabSelected?: Function; 19200aff185Sopenharmony_ci private deviceType: number = 0; 19300aff185Sopenharmony_ci 19400aff185Sopenharmony_ci build() { 19500aff185Sopenharmony_ci if (this.deviceType == DeviceType.PC_LIKE) { 19600aff185Sopenharmony_ci Flex({ 19700aff185Sopenharmony_ci direction: FlexDirection.Row, 19800aff185Sopenharmony_ci alignItems: ItemAlign.Center, 19900aff185Sopenharmony_ci justifyContent: FlexAlign.Start 20000aff185Sopenharmony_ci }) { 20100aff185Sopenharmony_ci Stack() { 20200aff185Sopenharmony_ci Image(this.tabItem.getIcon(this.tabItem.isSelected)) 20300aff185Sopenharmony_ci .draggable(false) 20400aff185Sopenharmony_ci .height($r('app.float.icon_size')) 20500aff185Sopenharmony_ci .width($r('app.float.icon_size')) 20600aff185Sopenharmony_ci .objectFit(ImageFit.Fill) 20700aff185Sopenharmony_ci } 20800aff185Sopenharmony_ci .padding({ 20900aff185Sopenharmony_ci left: $r('app.float.tab_bar_text_padding_left'), 21000aff185Sopenharmony_ci }) 21100aff185Sopenharmony_ci 21200aff185Sopenharmony_ci Text(this.tabItem.name) 21300aff185Sopenharmony_ci .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) 21400aff185Sopenharmony_ci .fontWeight(FontWeight.Medium) 21500aff185Sopenharmony_ci .fontColor(this.tabItem.getTextColor()) 21600aff185Sopenharmony_ci .padding({ 21700aff185Sopenharmony_ci left: $r('app.float.tab_bar_text_padding_left'), 21800aff185Sopenharmony_ci top: $r('app.float.tab_bar_text_padding_horizontal'), 21900aff185Sopenharmony_ci bottom: $r('app.float.tab_bar_text_padding_horizontal') 22000aff185Sopenharmony_ci }) 22100aff185Sopenharmony_ci .height($r('app.float.menu_height')) 22200aff185Sopenharmony_ci } 22300aff185Sopenharmony_ci .backgroundColor(this.tabItem.isSelected ? '#DAE2F5' : $r('app.color.transparent')) 22400aff185Sopenharmony_ci .borderRadius($r('app.float.single_tab_margin')) 22500aff185Sopenharmony_ci .onClick((): void => { 22600aff185Sopenharmony_ci this.onTabSelected && this.onTabSelected(this.index); 22700aff185Sopenharmony_ci this.tabItem.isSelected = true; 22800aff185Sopenharmony_ci }) 22900aff185Sopenharmony_ci } else { 23000aff185Sopenharmony_ci Flex({ 23100aff185Sopenharmony_ci direction: FlexDirection.Column, 23200aff185Sopenharmony_ci alignItems: ItemAlign.Center, 23300aff185Sopenharmony_ci justifyContent: FlexAlign.Center, 23400aff185Sopenharmony_ci }) { 23500aff185Sopenharmony_ci Stack() { 23600aff185Sopenharmony_ci Image(this.tabItem.getIcon(this.tabItem.isSelected)) 23700aff185Sopenharmony_ci .draggable(false) 23800aff185Sopenharmony_ci .height($r('app.float.icon_size')) 23900aff185Sopenharmony_ci .width($r('app.float.icon_size')) 24000aff185Sopenharmony_ci .objectFit(ImageFit.Fill) 24100aff185Sopenharmony_ci } 24200aff185Sopenharmony_ci .padding({ 24300aff185Sopenharmony_ci left: this.isSidebar ? 0 : $r('app.float.tab_bar_text_padding_left'), 24400aff185Sopenharmony_ci }) 24500aff185Sopenharmony_ci 24600aff185Sopenharmony_ci Text(this.tabItem.name) 24700aff185Sopenharmony_ci .fontSize($r('sys.float.ohos_id_text_size_caption1')) 24800aff185Sopenharmony_ci .fontFamily($r('app.string.id_text_font_family_medium')) 24900aff185Sopenharmony_ci .fontColor(this.tabItem.getTextColor()) 25000aff185Sopenharmony_ci .padding({ 25100aff185Sopenharmony_ci left: $r('app.float.tab_bar_text_padding_horizontal'), 25200aff185Sopenharmony_ci top: $r('app.float.tab_bar_text_padding_top'), 25300aff185Sopenharmony_ci right: $r('app.float.tab_bar_text_padding_horizontal') 25400aff185Sopenharmony_ci }) 25500aff185Sopenharmony_ci } 25600aff185Sopenharmony_ci .onClick((): void => { 25700aff185Sopenharmony_ci this.onTabSelected && this.onTabSelected(this.index); 25800aff185Sopenharmony_ci this.tabItem.isSelected = true; 25900aff185Sopenharmony_ci }) 26000aff185Sopenharmony_ci } 26100aff185Sopenharmony_ci } 26200aff185Sopenharmony_ci} 26300aff185Sopenharmony_ci 26400aff185Sopenharmony_ci// phone bottom tab 26500aff185Sopenharmony_ci@Component 26600aff185Sopenharmony_cistruct TabPhone { 26700aff185Sopenharmony_ci @ObjectLink tabItem: TabItem; 26800aff185Sopenharmony_ci index: number = 0; 26900aff185Sopenharmony_ci onTabSelected?: Function; 27000aff185Sopenharmony_ci 27100aff185Sopenharmony_ci build() { 27200aff185Sopenharmony_ci Flex({ 27300aff185Sopenharmony_ci direction: FlexDirection.Column, 27400aff185Sopenharmony_ci alignItems: ItemAlign.Center, 27500aff185Sopenharmony_ci justifyContent: FlexAlign.Center 27600aff185Sopenharmony_ci }) { 27700aff185Sopenharmony_ci Image(this.tabItem.getIcon(this.tabItem.isSelected)) 27800aff185Sopenharmony_ci .draggable(false) 27900aff185Sopenharmony_ci .height($r('app.float.icon_size')) 28000aff185Sopenharmony_ci .width($r('app.float.icon_size')) 28100aff185Sopenharmony_ci .objectFit(ImageFit.Fill) 28200aff185Sopenharmony_ci .margin({ 28300aff185Sopenharmony_ci bottom: $r('app.float.tab_bar_image_bottom') 28400aff185Sopenharmony_ci }) 28500aff185Sopenharmony_ci Text(this.tabItem.name) 28600aff185Sopenharmony_ci .fontSize($r('app.float.tab_bar_text_size')) 28700aff185Sopenharmony_ci .fontWeight(FontWeight.Medium) 28800aff185Sopenharmony_ci .fontColor(this.tabItem.getTextColor()) 28900aff185Sopenharmony_ci } 29000aff185Sopenharmony_ci .key('Tab' + this.tabItem.componentKey) 29100aff185Sopenharmony_ci .padding({ 29200aff185Sopenharmony_ci top: $r('app.float.tab_bar_padding_top'), 29300aff185Sopenharmony_ci left: $r('app.float.tab_bar_padding_left'), 29400aff185Sopenharmony_ci right: $r('app.float.tab_bar_padding_right'), 29500aff185Sopenharmony_ci bottom: $r('app.float.tab_bar_padding_bottom'), 29600aff185Sopenharmony_ci }) 29700aff185Sopenharmony_ci .height($r('app.float.tab_bar_vertical_height')) 29800aff185Sopenharmony_ci .borderRadius($r('app.float.single_tab_margin')) 29900aff185Sopenharmony_ci } 30000aff185Sopenharmony_ci} 30100aff185Sopenharmony_ci 30200aff185Sopenharmony_ci// For Album Set 30300aff185Sopenharmony_ci@Component 30400aff185Sopenharmony_ciexport struct TabBarForAlbumSet { 30500aff185Sopenharmony_ci @Consume isTabBarShow: boolean; 30600aff185Sopenharmony_ci private currentIndex: number = 0; 30700aff185Sopenharmony_ci private tabs: TabItemWithText[] = []; 30800aff185Sopenharmony_ci private controller: TabsController | null = null; 30900aff185Sopenharmony_ci private funcOnTabSelected?: Function; 31000aff185Sopenharmony_ci 31100aff185Sopenharmony_ci aboutToAppear(): void { 31200aff185Sopenharmony_ci this.funcOnTabSelected = (index: number): void => this.onTabSelected(index); 31300aff185Sopenharmony_ci this.tabs[this.currentIndex].isSelected = true; 31400aff185Sopenharmony_ci this.tabs.forEach((tab: TabItemWithText) => { 31500aff185Sopenharmony_ci Log.info(TAG, `${JSON.stringify(tab.name)}, ${tab.isSelected}`); 31600aff185Sopenharmony_ci }); 31700aff185Sopenharmony_ci } 31800aff185Sopenharmony_ci 31900aff185Sopenharmony_ci build() { 32000aff185Sopenharmony_ci if (this.isTabBarShow) { 32100aff185Sopenharmony_ci Flex({ 32200aff185Sopenharmony_ci direction: FlexDirection.Row, 32300aff185Sopenharmony_ci justifyContent: FlexAlign.Center, 32400aff185Sopenharmony_ci alignItems: ItemAlign.Start 32500aff185Sopenharmony_ci }) { 32600aff185Sopenharmony_ci ForEach(this.tabs, (tab: TabItemWithText) => { 32700aff185Sopenharmony_ci TabWithText({ tabItemWithText: tab, index: this.tabs.indexOf(tab), onTabSelected: this.funcOnTabSelected }) 32800aff185Sopenharmony_ci }, (tab: TabItemWithText): string => { 32900aff185Sopenharmony_ci return (tab.name.id).toString(); 33000aff185Sopenharmony_ci }) 33100aff185Sopenharmony_ci } 33200aff185Sopenharmony_ci .width('100%') 33300aff185Sopenharmony_ci .height($r('app.float.album_set_tab_bar_height')) 33400aff185Sopenharmony_ci .padding({ left: $r('app.float.max_padding_start'), right: $r('app.float.max_padding_end') }) 33500aff185Sopenharmony_ci .backgroundColor($r('app.color.default_background_color')) 33600aff185Sopenharmony_ci } 33700aff185Sopenharmony_ci } 33800aff185Sopenharmony_ci 33900aff185Sopenharmony_ci private onTabSelected(index: number): void { 34000aff185Sopenharmony_ci Log.info(TAG, `TabBarForAlbumSet this.currentIndex: ${this.currentIndex} index: ${index}`); 34100aff185Sopenharmony_ci this.currentIndex = index; 34200aff185Sopenharmony_ci if (this.controller != null) { 34300aff185Sopenharmony_ci this.controller.changeIndex(this.currentIndex); 34400aff185Sopenharmony_ci }; 34500aff185Sopenharmony_ci this.tabs.forEach((tab: TabItemWithText) => { 34600aff185Sopenharmony_ci tab.isSelected = false; 34700aff185Sopenharmony_ci }) 34800aff185Sopenharmony_ci Log.info(TAG, `select ${this.currentIndex}`); 34900aff185Sopenharmony_ci } 35000aff185Sopenharmony_ci} 35100aff185Sopenharmony_ci 35200aff185Sopenharmony_ci// single tab which only has text 35300aff185Sopenharmony_ci// For Album Set 35400aff185Sopenharmony_ci@Component 35500aff185Sopenharmony_cistruct TabWithText { 35600aff185Sopenharmony_ci @Consume isAlbumSetSelectedMode: boolean; 35700aff185Sopenharmony_ci @ObjectLink tabItemWithText: TabItemWithText; 35800aff185Sopenharmony_ci @State tabWidth: number = 0; 35900aff185Sopenharmony_ci index: number = 0; 36000aff185Sopenharmony_ci onTabSelected?: Function; 36100aff185Sopenharmony_ci 36200aff185Sopenharmony_ci aboutToAppear(): void { 36300aff185Sopenharmony_ci // Determine the length of the underline based on the font length 36400aff185Sopenharmony_ci if (this.index == 0) { 36500aff185Sopenharmony_ci this.tabWidth = px2vp(fp2px(Constants.TEXT_SIZE_SUB_TITLE2)) * 2; 36600aff185Sopenharmony_ci } else { 36700aff185Sopenharmony_ci this.tabWidth = px2vp(fp2px(Constants.TEXT_SIZE_SUB_TITLE2)) * 4; 36800aff185Sopenharmony_ci } 36900aff185Sopenharmony_ci Log.info(TAG, `index is ${this.index} and tabWidth is ${this.tabWidth}`); 37000aff185Sopenharmony_ci } 37100aff185Sopenharmony_ci 37200aff185Sopenharmony_ci build() { 37300aff185Sopenharmony_ci Flex({ 37400aff185Sopenharmony_ci direction: FlexDirection.Column, 37500aff185Sopenharmony_ci justifyContent: FlexAlign.Center, 37600aff185Sopenharmony_ci alignItems: ItemAlign.Center 37700aff185Sopenharmony_ci }) { 37800aff185Sopenharmony_ci Text(this.tabItemWithText.name) 37900aff185Sopenharmony_ci .fontSize(this.tabItemWithText.getTextSize()) 38000aff185Sopenharmony_ci .fontWeight(this.tabItemWithText.getTextWeight()) 38100aff185Sopenharmony_ci .fontColor(this.tabItemWithText.getTextColor()) 38200aff185Sopenharmony_ci .maxLines(1) 38300aff185Sopenharmony_ci .margin({ top: $r('app.float.tab_bar_line_margin_top'), 38400aff185Sopenharmony_ci left: $r('app.float.single_tab_margin'), 38500aff185Sopenharmony_ci right: $r('app.float.single_tab_margin'), 38600aff185Sopenharmony_ci bottom: $r('app.float.tab_bar_line_margin_top') }) 38700aff185Sopenharmony_ci Column() 38800aff185Sopenharmony_ci .width(this.tabWidth) 38900aff185Sopenharmony_ci .height($r('app.float.tab_bar_line_height')) 39000aff185Sopenharmony_ci .borderRadius($r('app.float.tab_bar_line_radius')) 39100aff185Sopenharmony_ci .backgroundColor(this.tabItemWithText.getTextColor()) 39200aff185Sopenharmony_ci .visibility(this.tabItemWithText.isSelected ? Visibility.Visible : Visibility.Hidden) 39300aff185Sopenharmony_ci } 39400aff185Sopenharmony_ci .height('100%') 39500aff185Sopenharmony_ci .onClick(() => { 39600aff185Sopenharmony_ci if (!this.isAlbumSetSelectedMode) { 39700aff185Sopenharmony_ci this.onTabSelected && this.onTabSelected(this.index); 39800aff185Sopenharmony_ci this.tabItemWithText.isSelected = true 39900aff185Sopenharmony_ci } 40000aff185Sopenharmony_ci }) 40100aff185Sopenharmony_ci } 40200aff185Sopenharmony_ci}