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_SEMI_MODAL_RENDER_SEMI_MODAL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEMI_MODAL_RENDER_SEMI_MODAL_H
18 
19 #include "core/animation/animator.h"
20 #include "core/components/box/render_box.h"
21 #include "core/components/drag_bar/render_drag_bar.h"
22 #include "core/components/scroll/render_single_child_scroll.h"
23 #include "core/components/semi_modal/semi_modal_component.h"
24 #include "core/gestures/click_recognizer.h"
25 #include "core/gestures/drag_recognizer.h"
26 #include "core/pipeline/base/render_node.h"
27 
28 namespace OHOS::Ace {
29 
30 class RenderSemiModal : public RenderNode {
31     DECLARE_ACE_TYPE(RenderSemiModal, RenderNode);
32 
33 public:
34     static RefPtr<RenderNode> Create();
35     void Update(const RefPtr<Component>& component) override;
36     void PerformLayout() override;
37     bool TouchTest(const Point& globalPoint, const Point& parentLocalPoint, const TouchRestrict& touchRestrict,
38         TouchTestResult& result) override;
39 
40     void ResetContentHeight();
41     void ExtendContentHeight();
42     void OnExtendAnimationEnd();
43     void OnAnimationStop();
44     void AnimateToExitApp();
45     void AnimateToFullWindow(int32_t duration);
46     void OnNavigationBarHeightChanged(const Dimension& height);
47     void OnStatusBarHeightChanged(const Dimension& height);
48 
GetBlankHeight()49     double GetBlankHeight() const
50     {
51         return blankHeight_;
52     }
53 
GetDragBar()54     const RefPtr<RenderDragBar>& GetDragBar() const
55     {
56         return dragBar_;
57     }
58 
59     void Dump() override;
60 
61 protected:
62     void OnTouchTestHit(
63         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override;
64 
65 private:
66     void InitializeRecognizer();
67     void HandleClick(const Offset& clickPosition);
68     void HandleDragStart(const Offset& startPoint);
69     void HandleDragUpdate(const Offset& currentPoint);
70     void HandleDragEnd(const Offset& endPoint);
71     void FirstLayout();
72     void LayoutFullScreen(const RefPtr<RenderNode>& boxForContent);
73     double GetScrollContentHeight();
74     void AnimateTo(double blankHeight);
75     void AppendBlankHeightAnimation(double blankHeight);
76     void AppendContentRadiusAnimation(double radius);
77     void UpdateDragImg();
78     void UpdateMinBlankHeight();
79     void UpdateDefaultBlankHeight();
80     void ShowUpAnimation();
81     void InnerLayout();
82     bool IsPageReady() const;
83     void MovePage(double delta);
84     double UpdateTargetBlankHeight(double oldHeight);
85 
86     RefPtr<RenderNode> boxForBlank_;
87     RefPtr<ClickRecognizer> clickDetector_;
88     RefPtr<Animator> animator_;
89     RefPtr<DragRecognizer> dragDetector_;
90     RefPtr<RenderDragBar> dragBar_;
91     Rect blankTouchRegion_;
92     WeakPtr<RenderNode> cachedPage_;
93     double cachedContentHeight_ = 0.0;
94     double blankHeight_ = -std::numeric_limits<double>::max();
95     double normalBlankHeight_ = -std::numeric_limits<double>::max(); // save blank height when keyboard not show up
96     double defaultBlankHeight_ = 0.0;
97     double minBlankHeight_ = 0.0;
98     bool isFirstUpdate_ = true;
99     bool isFirstLayout_ = true;
100     Offset dragStartPoint_;
101     double dragStartBlankHeight_ = 0.0;
102     bool canHandleDrag_ = false;
103     bool forbiddenSwipe_ = true;
104     bool isAnimating_ = false;
105     bool isAnimatingToDefault_ = false;
106     bool isFullScreen_ = false;
107     double navigationHeight_ = 0.0;
108     double statusBarHeight_ = 0.0;
109     bool updateMinBlank_ = true;
110     bool updateDefaultBlank_ = true;
111     bool isExit_ = false;
112     double inputHeight_ = 0.0;
113     bool hasInputHeight_ = false;
114     double maxWidth_ = 0.0;
115     DeviceOrientation orientation_ = DeviceOrientation::ORIENTATION_UNDEFINED;
116 };
117 
118 } // namespace OHOS::Ace
119 
120 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEMI_MODAL_RENDER_SEMI_MODAL_H
121