1 /*
2  * Copyright (c) 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_SCROLLABLE_REFRESH_COORDINATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SCROLLABLE_REFRESH_COORDINATION_H
18 
19 #include <utility>
20 
21 #include "base/memory/ace_type.h"
22 #include "core/components_ng/base/frame_node.h"
23 #include "core/components_ng/pattern/scrollable/scrollable_coordination_event.h"
24 
25 namespace OHOS::Ace::NG {
26 class RefreshCoordination : public AceType {
27 public:
RefreshCoordination(RefPtr<FrameNode> scrollableNode)28     RefreshCoordination(RefPtr<FrameNode> scrollableNode)
29     {
30         scrollableNode_ = WeakClaim(RawPtr(scrollableNode));
31         auto refreshNode = FindRefreshNode();
32         refreshNode_ = WeakClaim(RawPtr(refreshNode));
33         coordinationEvent_ = CreateCoordinationEvent();
34     };
35     ~RefreshCoordination() = default;
36     void OnScrollStart(bool isDrag, float mainVelocity) const;
37     bool OnScroll(float offset, float mainVelocity) const;
38     void OnScrollEnd(float mainVelocity) const;
InCoordination()39     bool InCoordination()
40     {
41         auto refreshNode = refreshNode_.Upgrade();
42         CHECK_NULL_RETURN(refreshNode, false);
43         return !!refreshNode;
44     }
45     bool IsRefreshInScroll() const;
46 
47 private:
48     RefPtr<FrameNode> FindRefreshNode() const;
49     RefPtr<ScrollableCoordinationEvent> CreateCoordinationEvent();
50     WeakPtr<FrameNode> refreshNode_;
51     WeakPtr<FrameNode> scrollableNode_;
52     RefPtr<ScrollableCoordinationEvent> coordinationEvent_;
53 };
54 
55 enum class RefreshCoordinationMode : char {
56     UNKNOWN = 0,
57     REFRESH_SCROLL = 1,
58     SCROLLABLE_SCROLL = 2,
59 };
60 } // namespace OHOS::Ace::NG
61 #endif