• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "core/components/tab_bar/tab_bar_indicator_component.h"
17 
18 namespace OHOS::Ace {
19 namespace {
20 
21 constexpr double DOUBLE_FACTOR = 2.0;
22 
23 } // namespace
24 
TabBarIndicatorComponent(const Edge & padding,const Color & color,const Dimension & borderWidth)25 TabBarIndicatorComponent::TabBarIndicatorComponent(
26     const Edge& padding, const Color& color, const Dimension& borderWidth)
27     : indicatorStyle_(TabBarIndicatorStyle::DEFAULT), indicatorPadding_(padding), indicatorColor_(color),
28       indicatorWidth_(borderWidth)
29 {
30     // build default indicatorDecoration
31     Border border;
32     border.SetBorderRadius(Radius(borderWidth / DOUBLE_FACTOR));
33     indicatorDecoration_ = AceType::MakeRefPtr<Decoration>();
34     indicatorDecoration_->SetBorder(border);
35     indicatorDecoration_->SetBackgroundColor(color);
36     SetHeight(borderWidth.Value(), borderWidth.Unit());
37     Initialize();
38 }
39 
TabBarIndicatorComponent(const RefPtr<Decoration> & indicatorDecoration)40 TabBarIndicatorComponent::TabBarIndicatorComponent(const RefPtr<Decoration>& indicatorDecoration)
41     : indicatorStyle_(TabBarIndicatorStyle::CUSTOM), indicatorDecoration_(indicatorDecoration)
42 {
43     Initialize();
44 }
45 
Initialize()46 void TabBarIndicatorComponent::Initialize()
47 {
48     if (indicatorStyle_ == TabBarIndicatorStyle::DEFAULT) {
49         SetFlex(BoxFlex::FLEX_X);
50     } else {
51         SetFlex(BoxFlex::FLEX_XY);
52     }
53 
54     if (indicatorDecoration_) {
55         SetBackDecoration(indicatorDecoration_);
56     }
57 }
58 
59 } // namespace OHOS::Ace