• 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         } else {
60             LOGD("indicatorOffset value is invalid");
61         }
62     }
63 
IsRefreshing()64     bool IsRefreshing() const
65     {
66         return refreshing_;
67     }
68 
IsRefresh(bool isRefresh)69     void IsRefresh(bool isRefresh)
70     {
71         isRefresh_ = isRefresh;
72     }
73 
GetIsRefresh()74     bool GetIsRefresh() const
75     {
76         return isRefresh_;
77     }
78 
SetRefreshing(bool isRefreshing)79     void SetRefreshing(bool isRefreshing)
80     {
81         refreshing_ = isRefreshing;
82     }
83 
IsUseOffset()84     bool IsUseOffset() const
85     {
86         return useOffset_;
87     }
88 
SetUseOffset(bool isUseOffset)89     void SetUseOffset(bool isUseOffset)
90     {
91         useOffset_ = isUseOffset;
92     }
93 
GetRefreshType()94     RefreshType GetRefreshType() const
95     {
96         return refreshType_;
97     }
98 
SetRefreshType(RefreshType refreshType)99     void SetRefreshType(RefreshType refreshType)
100     {
101         refreshType_ = refreshType;
102     }
103 
IsShowLastTime()104     bool IsShowLastTime() const
105     {
106         return showLastTime_;
107     }
108 
SetShowLastTime(bool isShowLastTime)109     void SetShowLastTime(bool isShowLastTime)
110     {
111         showLastTime_ = isShowLastTime;
112     }
113 
SetRefreshEventId(const EventMarker & refreshEventId)114     void SetRefreshEventId(const EventMarker& refreshEventId)
115     {
116         refreshEventId_ = refreshEventId;
117     }
118 
SetTimeOffset(const Dimension & timeOffset)119     void SetTimeOffset(const Dimension& timeOffset)
120     {
121         timeOffset_ = timeOffset;
122     }
123 
GetTimeOffset()124     const Dimension& GetTimeOffset() const
125     {
126         return timeOffset_;
127     }
128 
GetRefreshEventId()129     const EventMarker& GetRefreshEventId() const
130     {
131         return refreshEventId_;
132     }
133 
SetPulldownEventId(const EventMarker & pulldownEventId)134     void SetPulldownEventId(const EventMarker& pulldownEventId)
135     {
136         pullDownEventId_ = pulldownEventId;
137     }
138 
GetPulldownEventId()139     const EventMarker& GetPulldownEventId() const
140     {
141         return pullDownEventId_;
142     }
143 
GetBackgroundColor()144     const Color& GetBackgroundColor() const
145     {
146         return backgroundColor_;
147     }
148 
SetBackgroundColor(const Color & backgroundColor)149     void SetBackgroundColor(const Color& backgroundColor)
150     {
151         backgroundColor_ = backgroundColor;
152     }
153 
GetProgressColor()154     const Color& GetProgressColor() const
155     {
156         return progressColor_;
157     }
158 
SetProgressColor(const Color & progressColor)159     void SetProgressColor(const Color& progressColor)
160     {
161         progressColor_ = progressColor;
162     }
163 
GetLoadingDistance()164     const Dimension& GetLoadingDistance() const
165     {
166         return loadingDistance_;
167     }
168 
SetLoadingDistance(const Dimension & loadingDistance)169     void SetLoadingDistance(const Dimension& loadingDistance)
170     {
171         loadingDistance_ = loadingDistance;
172     }
173 
GetRefreshDistance()174     const Dimension& GetRefreshDistance() const
175     {
176         return refreshDistance_;
177     }
178 
SetRefreshDistance(const Dimension & refreshDistance)179     void SetRefreshDistance(const Dimension& refreshDistance)
180     {
181         if (GreatOrEqual(refreshDistance.Value(), 0.0)) {
182             refreshDistance_ = refreshDistance;
183         } else {
184             refreshDistance_ = Dimension(0.0, DimensionUnit::VP);
185         }
186 
187     }
188 
GetProgressDistance()189     const Dimension& GetProgressDistance() const
190     {
191         return progressDistance_;
192     }
193 
SetProgressDistance(const Dimension & progressDistance)194     void SetProgressDistance(const Dimension& progressDistance)
195     {
196         progressDistance_ = progressDistance;
197     }
198 
GetMaxDistance()199     const Dimension& GetMaxDistance() const
200     {
201         return maxDistance_;
202     }
203 
SetMaxDistance(const Dimension & maxDistance)204     void SetMaxDistance(const Dimension& maxDistance)
205     {
206         maxDistance_ = maxDistance;
207     }
208 
GetProgressDiameter()209     const Dimension& GetProgressDiameter() const
210     {
211         return progressDiameter_;
212     }
213 
SetProgressDiameter(const Dimension & progressDiameter)214     void SetProgressDiameter(const Dimension& progressDiameter)
215     {
216         progressDiameter_ = progressDiameter;
217     }
218 
GetShowTimeDistance()219     const Dimension& GetShowTimeDistance() const
220     {
221         return showTimeDistance_;
222     }
223 
SetShowTimeDistance(const Dimension & showTimeDistance)224     void SetShowTimeDistance(const Dimension& showTimeDistance)
225     {
226         showTimeDistance_ = showTimeDistance;
227     }
228 
SetFriction(int32_t friction)229     void SetFriction(int32_t friction)
230     {
231         if (friction >= MIN_FRICTION_RATIO && friction <= MAX_FRICTION_RATIO) {
232             friction_ = friction;
233         } else if (friction < MIN_FRICTION_RATIO) {
234             friction_ = MIN_FRICTION_RATIO;
235         } else {
236             friction_ = MAX_FRICTION_RATIO;
237         }
238     }
239 
GetFriction()240     int32_t GetFriction() const
241     {
242         return friction_;
243     }
244 
GetTextStyle()245     const TextStyle& GetTextStyle() const
246     {
247         return textStyle_;
248     }
249 
SetTextStyle(const TextStyle & textStyle)250     void SetTextStyle(const TextStyle& textStyle)
251     {
252         textStyle_ = textStyle;
253     }
254 
GetChangeEvent()255     const EventMarker& GetChangeEvent() const
256     {
257         return changeEvent_;
258     }
259 
SetChangeEvent(const EventMarker & changeEvent)260     void SetChangeEvent(const EventMarker& changeEvent)
261     {
262         changeEvent_ = changeEvent;
263     }
264 
265 private:
266     Dimension indicatorOffset_ = Dimension(DEFAULT_INDICATOR_OFFSET, DimensionUnit::VP);
267     Dimension loadingDistance_;
268     Dimension progressDistance_;
269     Dimension showTimeDistance_;
270     Dimension refreshDistance_;
271     Dimension maxDistance_;
272     Dimension progressDiameter_;
273     Dimension timeOffset_;
274 
275     bool useOffset_ = false;
276     bool showLastTime_ = false;
277     bool refreshing_ = false;
278     RefreshType refreshType_ = RefreshType::AUTO;
279     bool isRefresh_ = false;
280 
281     int32_t friction_ = DEFAULT_FRICTION_RATIO;
282     TextStyle textStyle_;
283 
284 #ifdef WEARABLE_PRODUCT
285     Color backgroundColor_ = Color::BLACK;
286     Color progressColor_ = Color::WHITE;
287 #else
288     Color backgroundColor_ = Color::WHITE;
289     Color progressColor_ = Color::BLACK;
290 #endif
291     EventMarker refreshEventId_;
292     EventMarker pullDownEventId_;
293     EventMarker changeEvent_;
294 };
295 
296 } // namespace OHOS::Ace
297 
298 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_REFRESH_REFRESH_COMPONENT_H
299