• 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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TABS_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TABS_PATTERN_H
18 
19 #include <optional>
20 
21 #include "base/geometry/axis.h"
22 #include "base/memory/referenced.h"
23 #include "core/components/common/layout/constants.h"
24 #include "core/components_ng/event/event_hub.h"
25 #include "core/components_ng/pattern/pattern.h"
26 #include "core/components_ng/pattern/tabs/tabs_layout_algorithm.h"
27 #include "core/components_ng/pattern/tabs/tabs_layout_property.h"
28 
29 namespace OHOS::Ace::NG {
30 
31 class TabsPattern : public Pattern {
32     DECLARE_ACE_TYPE(TabsPattern, Pattern);
33 
34 public:
35     using ChangeEvent = std::function<void(int32_t)>;
36     using ChangeEventPtr = std::shared_ptr<ChangeEvent>;
37 
38     TabsPattern() = default;
39     ~TabsPattern() override = default;
40 
IsAtomicNode()41     bool IsAtomicNode() const override
42     {
43         return false;
44     }
45 
CreateLayoutProperty()46     RefPtr<LayoutProperty> CreateLayoutProperty() override
47     {
48         return MakeRefPtr<TabsLayoutProperty>();
49     }
50 
CreateLayoutAlgorithm()51     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
52     {
53         return MakeRefPtr<TabsLayoutAlgorithm>();
54     }
55 
GetFocusPattern()56     FocusPattern GetFocusPattern() const override
57     {
58         return { FocusType::SCOPE, true };
59     }
60 
61     ScopeFocusAlgorithm GetScopeFocusAlgorithm() override;
62 
63     void SetOnChangeEvent(std::function<void(const BaseEventInfo*)>&& event);
64 
65     void SetOnTabBarClickEvent(std::function<void(const BaseEventInfo*)>&& event);
66 
GetTabBarClickEvent()67     ChangeEventPtr GetTabBarClickEvent()
68     {
69         return onTabBarClickEvent_;
70     }
71 
72     void OnModifyDone() override;
73 
74     std::string ProvideRestoreInfo() override;
75 
76     void OnRestoreInfo(const std::string& restoreInfo) override;
77 
78     void SetOnIndexChangeEvent(std::function<void(const BaseEventInfo*)>&& event);
79 
80 private:
81     void OnAttachToFrameNode() override;
82     void OnUpdateShowDivider();
83     WeakPtr<FocusHub> GetNextFocusNode(FocusStep step, const WeakPtr<FocusHub>& currentFocusNode);
84 
85     ChangeEventPtr onChangeEvent_;
86     ChangeEventPtr onTabBarClickEvent_;
87     ChangeEventPtr onIndexChangeEvent_;
88 };
89 
90 } // namespace OHOS::Ace::NG
91 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TABS_PATTERN_H
92