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_NG_PATTERNS_STAGE_STAGE_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_STAGE_STAGE_PATTERN_H
18 
19 #include "stage_layout_algorithm.h"
20 
21 #include "base/utils/noncopyable.h"
22 #include "core/components_ng/pattern/pattern.h"
23 
24 namespace OHOS::Ace::NG {
25 // StagePattern is the base class for root render node to perform page switch.
26 class ACE_EXPORT StagePattern : public Pattern {
27     DECLARE_ACE_TYPE(StagePattern, Pattern);
28 
29 public:
30     StagePattern() = default;
31     ~StagePattern() override = default;
32 
IsMeasureBoundary()33     bool IsMeasureBoundary() const override
34     {
35         return true;
36     }
37 
IsAtomicNode()38     bool IsAtomicNode() const override
39     {
40         return false;
41     }
42 
43     void OnAttachToFrameNode() override;
44 
OnRebuildFrame()45     void OnRebuildFrame() override
46     {
47         if (onRebuildFrameCallback_) {
48             onRebuildFrameCallback_();
49         }
50     }
51 
SetOnRebuildFrameCallback(std::function<void ()> && callback)52     void SetOnRebuildFrameCallback(std::function<void()>&& callback)
53     {
54         onRebuildFrameCallback_ = std::move(callback);
55     }
56 
SetPrimaryPage(const RefPtr<FrameNode> & primaryPage)57     virtual void SetPrimaryPage(const RefPtr<FrameNode>& primaryPage) {}
58 
SetCurrentPageIndex(int32_t index)59     void SetCurrentPageIndex(int32_t index)
60     {
61         currentPageIndex_ = index;
62     }
63 
64 protected:
65     std::function<void()> onRebuildFrameCallback_;
66     int32_t currentPageIndex_ = 0;
67 
68     ACE_DISALLOW_COPY_AND_MOVE(StagePattern);
69 };
70 } // namespace OHOS::Ace::NG
71 
72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_STAGE_STAGE_PATTERN_H
73