1 /*
2  * Copyright (c) 2022 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS__TAB_CONTENT_PROXY_ELEMENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS__TAB_CONTENT_PROXY_ELEMENT_H
18 
19 #include <list>
20 #include <unordered_map>
21 
22 #include "core/components/tab_bar/tab_content_element.h"
23 #include "core/components/tab_bar/tab_controller.h"
24 #include "core/components_v2/common/element_proxy.h"
25 #include "core/focus/focus_node.h"
26 
27 namespace OHOS::Ace::V2 {
28 
29 class TabContentProxyElement : public TabContentElement, private ElementProxyHost {
30     DECLARE_ACE_TYPE(TabContentProxyElement, TabContentElement);
31 
32 public:
TabContentProxyElement(const std::list<RefPtr<Component>> & contents)33     explicit TabContentProxyElement(const std::list<RefPtr<Component>>& contents) : TabContentElement(contents) {};
34     ~TabContentProxyElement() override = default;
35 
36     void PerformBuild() override;
37     void Update() override;
38 
39     void ChangeByBar(int32_t index, bool isFromController = false) override;
40     void PrepareContent(int32_t index) override;
41     void UpdateIndex() override;
42 
GetElementByIndex(size_t index)43     RefPtr<Element> GetElementByIndex(size_t index)
44     {
45         return ElementProxyHost::GetElementByIndex(index);
46     }
47 
48 private:
49     RefPtr<Element> OnUpdateElement(const RefPtr<Element>& element, const RefPtr<Component>& component) override;
50     RefPtr<Component> OnMakeEmptyComponent() override;
51     void OnDataSourceUpdated(size_t startIndex) override;
52 
53     RefPtr<FocusNode> GetChildFocusNode(const RefPtr<Element>& node);
54 };
55 
56 } // namespace OHOS::Ace::V2
57 
58 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_TABS__TAB_CONTENT_PROXY_ELEMENT_H
59