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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DIALOG_MODAL_RENDER_DIALOG_MODAL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DIALOG_MODAL_RENDER_DIALOG_MODAL_H
18 
19 #include "core/animation/animator.h"
20 #include "core/components/clip/render_clip.h"
21 #include "core/components/dialog_modal/dialog_modal_component.h"
22 #include "core/pipeline/base/render_node.h"
23 
24 namespace OHOS::Ace {
25 
26 class RenderDialogModal : public RenderNode {
27     DECLARE_ACE_TYPE(RenderDialogModal, RenderNode);
28 
29 public:
30     static RefPtr<RenderNode> Create();
31 
32     void Update(const RefPtr<Component>& component) override;
33 
34     void PerformLayout() override;
35 
36     void UpdateSystemBarHeight(double statusBar, double navigationBar);
37 
38     void AnimateTo(double childHeight, bool reverse);
39 
40     RefPtr<RenderClip> GetRenderClip() const;
41 
42     using LayoutNotify = std::function<void()>;
SetLayoutNotify(LayoutNotify && layoutNotify)43     void SetLayoutNotify(LayoutNotify&& layoutNotify)
44     {
45         notify_ = std::move(layoutNotify);
46     }
47 
48 private:
49     void PerformClip();
50     double PerformClipAnimation(const RefPtr<RenderClip>& clip);
51     bool CanRouterPage() const;
52     Size GetTopPageLayoutSize() const;
IsAnimating()53     bool IsAnimating() const
54     {
55         return controller_->IsRunning() || lastAnimateFrame_;
56     }
57     void MovePage(double delta);
58 
59     RefPtr<Animator> controller_;
60     bool lastAnimateFrame_ = false;
61     double animatingPageHeight_ = 0.0;
62     double animateTargetHeight_ = 0.0;
63     bool animatingPush_ = true;
64     double statusBarHeight_ = 0.0;
65     double navigationBarHeight_ = 0.0;
66     LayoutNotify notify_;
67 };
68 
69 } // namespace OHOS::Ace
70 
71 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DIALOG_MODAL_RENDER_DIALOG_MODAL_H
72