• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_REFRESH_REFRESH_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_REFRESH_REFRESH_COMPONENT_H
18 
19 #include "base/geometry/dimension.h"
20 #include "core/components_v2/common/common_def.h"
21 #include "core/pipeline/base/sole_child_component.h"
22 
23 namespace OHOS::Ace {
24 
25 inline constexpr double DEFAULT_INDICATOR_OFFSET = 16.0;
26 inline constexpr int32_t MIN_FRICTION_RATIO = 0;
27 inline constexpr int32_t MAX_FRICTION_RATIO = 100;
28 #ifdef WEARABLE_PRODUCT
29 inline constexpr int32_t DEFAULT_FRICTION_RATIO = 62;
30 #else
31 inline constexpr int32_t DEFAULT_FRICTION_RATIO = 42;
32 #endif
33 
34 class ACE_EXPORT RefreshComponent : public SoleChildComponent {
35     DECLARE_ACE_TYPE(RefreshComponent, SoleChildComponent);
36 
37 public:
RefreshComponent()38     RefreshComponent() : SoleChildComponent() {}
39 
40     ~RefreshComponent() override = default;
41 
42     RefPtr<Element> CreateElement() override;
43 
44     RefPtr<RenderNode> CreateRenderNode() override;
45 
GetIndicatorOffset()46     const Dimension& GetIndicatorOffset() const
47     {
48         return indicatorOffset_;
49     }
50 
51     ACE_DEFINE_COMPONENT_EVENT(OnStateChange, void(int));
52 
53     ACE_DEFINE_COMPONENT_EVENT(OnRefreshing, void());
54 
SetIndicatorOffset(const Dimension & indicatorOffset)55     void SetIndicatorOffset(const Dimension& indicatorOffset)
56     {
57         if (GreatOrEqual(indicatorOffset.Value(), 0.0)) {
58             indicatorOffset_ = indicatorOffset;
59         }
60     }
61 
IsRefreshing()62     bool IsRefreshing() const
63     {
64         return refreshing_;
65     }
66 
IsRefresh(bool isRefresh)67     void IsRefresh(bool isRefresh)
68     {
69         isRefresh_ = isRefresh;
70     }
71 
GetIsRefresh()72     bool GetIsRefresh() const
73     {
74         return isRefresh_;
75     }
76 
SetRefreshing(bool isRefreshing)77     void SetRefreshing(bool isRefreshing)
78     {
79         refreshing_ = isRefreshing;
80     }
81 
IsUseOffset()82     bool IsUseOffset() const
83     {
84         return useOffset_;
85     }
86 
SetUseOffset(bool isUseOffset)87     void SetUseOffset(bool isUseOffset)
88     {
89         useOffset_ = isUseOffset;
90     }
91 
GetRefreshType()92     RefreshType GetRefreshType() const
93     {
94         return refreshType_;
95     }
96 
SetRefreshType(RefreshType refreshType)97     void SetRefreshType(RefreshType refreshType)
98     {
99         refreshType_ = refreshType;
100     }
101 
IsShowLastTime()102     bool IsShowLastTime() const
103     {
104         return showLastTime_;
105     }
106 
SetShowLastTime(bool isShowLastTime)107     void SetShowLastTime(bool isShowLastTime)
108     {
109         showLastTime_ = isShowLastTime;
110     }
111 
SetRefreshEventId(const EventMarker & refreshEventId)112     void SetRefreshEventId(const EventMarker& refreshEventId)
113     {
114         refreshEventId_ = refreshEventId;
115     }
116 
SetTimeOffset(const Dimension & timeOffset)117     void SetTimeOffset(const Dimension& timeOffset)
118     {
119         timeOffset_ = timeOffset;
120     }
121 
GetTimeOffset()122     const Dimension& GetTimeOffset() const
123     {
124         return timeOffset_;
125     }
126 
GetRefreshEventId()127     const EventMarker& GetRefreshEventId() const
128     {
129         return refreshEventId_;
130     }
131 
SetPulldownEventId(const EventMarker & pulldownEventId)132     void SetPulldownEventId(const EventMarker& pulldownEventId)
133     {
134         pullDownEventId_ = pulldownEventId;
135     }
136 
GetPulldownEventId()137     const EventMarker& GetPulldownEventId() const
138     {
139         return pullDownEventId_;
140     }
141 
GetBackgroundColor()142     const Color& GetBackgroundColor() const
143     {
144         return backgroundColor_;
145     }
146 
SetBackgroundColor(const Color & backgroundColor)147     void SetBackgroundColor(const Color& backgroundColor)
148     {
149         backgroundColor_ = backgroundColor;
150     }
151 
GetProgressColor()152     const Color& GetProgressColor() const
153     {
154         return progressColor_;
155     }
156 
SetProgressColor(const Color & progressColor)157     void SetProgressColor(const Color& progressColor)
158     {
159         progressColor_ = progressColor;
160     }
161 
GetLoadingDistance()162     const Dimension& GetLoadingDistance() const
163     {
164         return loadingDistance_;
165     }
166 
SetLoadingDistance(const Dimension & loadingDistance)167     void SetLoadingDistance(const Dimension& loadingDistance)
168     {
169         loadingDistance_ = loadingDistance;
170     }
171 
GetRefreshDistance()172     const Dimension& GetRefreshDistance() const
173     {
174         return refreshDistance_;
175     }
176 
SetRefreshDistance(const Dimension & refreshDistance)177     void SetRefreshDistance(const Dimension& refreshDistance)
178     {
179         if (GreatOrEqual(refreshDistance.Value(), 0.0)) {
180             refreshDistance_ = refreshDistance;
181         } else {
182             refreshDistance_ = Dimension(0.0, DimensionUnit::VP);
183         }
184 
185     }
186 
GetProgressDistance()187     const Dimension& GetProgressDistance() const
188     {
189         return progressDistance_;
190     }
191 
SetProgressDistance(const Dimension & progressDistance)192     void SetProgressDistance(const Dimension& progressDistance)
193     {
194         progressDistance_ = progressDistance;
195     }
196 
GetMaxDistance()197     const Dimension& GetMaxDistance() const
198     {
199         return maxDistance_;
200     }
201 
SetMaxDistance(const Dimension & maxDistance)202     void SetMaxDistance(const Dimension& maxDistance)
203     {
204         maxDistance_ = maxDistance;
205     }
206 
GetProgressDiameter()207     const Dimension& GetProgressDiameter() const
208     {
209         return progressDiameter_;
210     }
211 
SetProgressDiameter(const Dimension & progressDiameter)212     void SetProgressDiameter(const Dimension& progressDiameter)
213     {
214         progressDiameter_ = progressDiameter;
215     }
216 
GetShowTimeDistance()217     const Dimension& GetShowTimeDistance() const
218     {
219         return showTimeDistance_;
220     }
221 
SetShowTimeDistance(const Dimension & showTimeDistance)222     void SetShowTimeDistance(const Dimension& showTimeDistance)
223     {
224         showTimeDistance_ = showTimeDistance;
225     }
226 
SetFriction(int32_t friction)227     void SetFriction(int32_t friction)
228     {
229         if (friction >= MIN_FRICTION_RATIO && friction <= MAX_FRICTION_RATIO) {
230             friction_ = friction;
231         } else if (friction < MIN_FRICTION_RATIO) {
232             friction_ = MIN_FRICTION_RATIO;
233         } else {
234             friction_ = MAX_FRICTION_RATIO;
235         }
236     }
237 
GetFriction()238     int32_t GetFriction() const
239     {
240         return friction_;
241     }
242 
GetTextStyle()243     const TextStyle& GetTextStyle() const
244     {
245         return textStyle_;
246     }
247 
SetTextStyle(const TextStyle & textStyle)248     void SetTextStyle(const TextStyle& textStyle)
249     {
250         textStyle_ = textStyle;
251     }
252 
GetChangeEvent()253     const EventMarker& GetChangeEvent() const
254     {
255         return changeEvent_;
256     }
257 
SetChangeEvent(const EventMarker & changeEvent)258     void SetChangeEvent(const EventMarker& changeEvent)
259     {
260         changeEvent_ = changeEvent;
261     }
262 
263 private:
264     Dimension indicatorOffset_ = Dimension(DEFAULT_INDICATOR_OFFSET, DimensionUnit::VP);
265     Dimension loadingDistance_;
266     Dimension progressDistance_;
267     Dimension showTimeDistance_;
268     Dimension refreshDistance_;
269     Dimension maxDistance_;
270     Dimension progressDiameter_;
271     Dimension timeOffset_;
272 
273     bool useOffset_ = false;
274     bool showLastTime_ = false;
275     bool refreshing_ = false;
276     RefreshType refreshType_ = RefreshType::AUTO;
277     bool isRefresh_ = false;
278 
279     int32_t friction_ = DEFAULT_FRICTION_RATIO;
280     TextStyle textStyle_;
281 
282 #ifdef WEARABLE_PRODUCT
283     Color backgroundColor_ = Color::BLACK;
284     Color progressColor_ = Color::WHITE;
285 #else
286     Color backgroundColor_ = Color::WHITE;
287     Color progressColor_ = Color::BLACK;
288 #endif
289     EventMarker refreshEventId_;
290     EventMarker pullDownEventId_;
291     EventMarker changeEvent_;
292 };
293 
294 } // namespace OHOS::Ace
295 
296 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_REFRESH_REFRESH_COMPONENT_H
297