• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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_PATTERN_SCROLLABLE_SCROLLABLE_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLLABLE_SCROLLABLE_MODEL_NG_H
18 
19 #include "base/utils/macros.h"
20 #include "core/components/common/layout/constants.h"
21 #include "core/components_ng/base/frame_node.h"
22 #include "core/components_ng/pattern/scrollable/scrollable_paint_property.h"
23 #include "core/components_ng/pattern/scrollable/scrollable_properties.h"
24 
25 #ifdef SUPPORT_DIGITAL_CROWN
26 #include "core/event/crown_event.h"
27 #endif
28 namespace OHOS::Ace::NG {
29 
30 constexpr Dimension DEFAULT_FADING_EDGE_LENGTH_SCROLLABLE = Dimension(32.0f, DimensionUnit::VP); // default value
31 class ACE_FORCE_EXPORT ScrollableModelNG {
32 public:
33     static void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled, EffectEdge effectEdge = EffectEdge::ALL);
34 
35     static void SetScrollBarMode(DisplayMode value);
36     static void SetScrollBarMode(FrameNode* frameNode, const std::optional<DisplayMode>& value);
37     static void SetScrollBarColor(const std::string& value);
38     static void SetScrollBarColor(FrameNode* frameNode, const std::optional<Color>& value);
39     static void SetScrollBarWidth(const std::string& value);
40     static void SetScrollBarWidth(FrameNode* frameNode, const std::optional<Dimension>& value);
41 
42     static void SetOnScroll(OnScrollEvent&& onScroll);
43     static void SetOnWillScroll(OnWillScrollEvent&& onScroll);
44     static void SetOnDidScroll(OnScrollEvent&& onScroll);
45     static void SetOnScrollStart(OnScrollStartEvent&& onScrollStart);
46     static void SetOnScrollStop(OnScrollStopEvent&& onScrollStop);
47     static void SetOnReachStart(OnReachEvent&& onReachStart);
48     static void SetOnReachEnd(OnReachEvent&& onReachEnd);
49     static void SetOnScrollFrameBegin(OnScrollFrameBeginEvent&& ScrollFrameBegin);
50     static void SetFadingEdge(
51         bool fadingEdge, const Dimension& fadingEdgeLength = DEFAULT_FADING_EDGE_LENGTH_SCROLLABLE);
52     static void SetFadingEdge(FrameNode* frameNode, bool fadingEdge,
53         const Dimension& fadingEdgeLength = DEFAULT_FADING_EDGE_LENGTH_SCROLLABLE);
54     static void SetContentClip(ContentClipMode mode, const RefPtr<ShapeRect>& rect);
55     static void SetMaxFlingSpeed(double max);
56     static void SetOnWillStopDragging(OnWillStopDraggingEvent&& onWillStopDragging);
57 
58     static void SetEdgeEffect(
59         FrameNode* frameNode, EdgeEffect edgeEffect, bool alwaysEnabled, EffectEdge effectEdge = EffectEdge::ALL);
60     static void SetScrollBarMode(FrameNode* frameNode, int32_t displayNumber);
61     static void SetScrollBarWidth(FrameNode* frameNode, const std::string& value);
62     static void SetScrollBarColor(FrameNode* frameNode, const std::string& value);
63     static void SetOnWillScroll(FrameNode* frameNode, OnWillScrollEvent&& onScroll);
64     static void SetOnDidScroll(FrameNode* frameNode, OnScrollEvent&& onScroll);
65 
66     static int32_t GetEdgeEffect(FrameNode* frameNode);
67     static int32_t GetAlwaysEnabled(FrameNode* frameNode);
68     static void SetOnScroll(FrameNode* frameNode, OnScrollEvent&& onScroll);
69     static void SetOnScrollStart(FrameNode* frameNode, OnScrollStartEvent&& onScrollStart);
70     static void SetOnScrollStop(FrameNode* frameNode, OnScrollStopEvent&& onScrollStop);
71     static void SetOnReachStart(FrameNode* frameNode, OnReachEvent&& onReachStart);
72     static void SetOnReachEnd(FrameNode* frameNode, OnReachEvent&& onReachEnd);
73     static void SetOnScrollFrameBegin(FrameNode* frameNode, OnScrollFrameBeginEvent&& ScrollFrameBegin);
74     static void SetMaxFlingSpeed(FrameNode* frameNode, double max);
75     /**
76      * @return maximum fling speed, Unit: vp/s.
77      */
78     static float GetMaxFlingSpeed(FrameNode* frameNode);
79     static void SetContentClip(FrameNode* frameNode, ContentClipMode mode, const RefPtr<ShapeRect>& rect);
80     static ContentClipMode GetContentClip(FrameNode* frameNode);
81     static void ResetContentClip(FrameNode* frameNode);
82     static bool GetFadingEdge(FrameNode* frameNode);
83     static float GetFadingEdgeLength(FrameNode* frameNode);
84     static void SetOnWillStopDragging(FrameNode* frameNode, OnWillStopDraggingEvent&& onWillStopDragging);
85 
86 #ifdef SUPPORT_DIGITAL_CROWN
87     static void SetDigitalCrownSensitivity(CrownSensitivity sensitivity);
88 #endif
89     static void ResetScrollBarWidth(FrameNode* frameNode);
90     static void ResetScrollBarColor(FrameNode* frameNode);
91     static void SetNestedScroll(FrameNode* frameNode, const NestedScrollOptions& nestedOpt);
92     static void SetFriction(FrameNode* frameNode, const std::optional<double>& friction);
93 
94     static void SetBackToTop(bool backToTop);
95     static void ResetBackToTop();
96     static void SetBackToTop(FrameNode* frameNode, bool backToTop);
97     static void SetBackToTopMultiThread(FrameNode* frameNode, bool backToTop);
98     static void ResetBackToTop(FrameNode* frameNode);
99     static bool GetBackToTop(FrameNode* frameNode);
100     static void SetScrollBarMargin(const ScrollBarMargin& scrollBarMargin);
101     static void SetScrollBarMargin(FrameNode* frameNode, const ScrollBarMargin& scrollBarMargin);
102     static void ResetScrollBarMargin(FrameNode* frameNode);
103     static void GetScrollBarMargin(FrameNode* frameNode, ScrollBarMargin& scrollBarMargin);
104 
105     static void CreateWithResourceObjScrollBarColor(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj);
106 };
107 } // namespace OHOS::Ace::NG
108 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLLABLE_SCROLLABLE_MODEL_H
109