• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_PATTERN_REFRESH_LAYOUT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_REFRESH_LAYOUT_PROPERTY_H
18 
19 #include "core/components_ng/base/inspector_filter.h"
20 #include "frameworks/core/components_ng/layout/layout_property.h"
21 #include "frameworks/core/components_ng/property/property.h"
22 
23 namespace OHOS::Ace::NG {
24 
25 enum class RefreshStatus {
26     // The default status.
27     INACTIVE = 0,
28     // While being dragged but not enough to trig refresh.
29     DRAG,
30     // Dragging enough to refresh, and less than the max distance.
31     OVER_DRAG,
32     // While it is refreshing.
33     REFRESH,
34     // While it will scroll back to the top after refreshing.
35     DONE,
36 };
37 
38 class ACE_EXPORT RefreshLayoutProperty : public LayoutProperty {
39     DECLARE_ACE_TYPE(RefreshLayoutProperty, LayoutProperty);
40 
41 public:
42     RefreshLayoutProperty() = default;
43 
44     ~RefreshLayoutProperty() override = default;
45 
Clone()46     RefPtr<LayoutProperty> Clone() const override
47     {
48         auto value = MakeRefPtr<RefreshLayoutProperty>();
49         value->UpdateLayoutProperty(this);
50         value->propIsRefreshing_ = CloneIsRefreshing();
51         value->propIndicatorOffset_ = CloneIndicatorOffset();
52         value->propFriction_ = CloneFriction();
53         value->propLoadingText_ = CloneLoadingText();
54         value->propPullToRefresh_ = ClonePullToRefresh();
55         value->propRefreshOffset_ = CloneRefreshOffset();
56         value->propPullDownRatio_ = ClonePullDownRatio();
57         value->propMaxPullDownDistance_ = CloneMaxPullDownDistance();
58         value->propIsCustomBuilderExist_ = CloneIsCustomBuilderExist();
59         return value;
60     }
61 
Reset()62     void Reset() override
63     {
64         LayoutProperty::Reset();
65         ResetIsRefreshing();
66         ResetIndicatorOffset();
67         ResetFriction();
68         ResetLoadingText();
69         ResetPullToRefresh();
70         ResetRefreshOffset();
71         ResetPullDownRatio();
72         ResetMaxPullDownDistance();
73         ResetIsCustomBuilderExist();
74     }
75 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)76     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
77     {
78         LayoutProperty::ToJsonValue(json, filter);
79         /* no fixed attr below, just return */
80         if (filter.IsFastFilter()) {
81             return;
82         }
83         json->PutExtAttr(
84             "offset", propIndicatorOffset_.value_or(Dimension(0, DimensionUnit::VP)).ToString().c_str(), filter);
85         json->PutExtAttr(
86             "refreshOffset", propRefreshOffset_.value_or(Dimension(0, DimensionUnit::VP)).ToString().c_str(), filter);
87         json->PutExtAttr("pullToRefresh", propPullToRefresh_.value_or(true), filter);
88         json->PutExtAttr("friction", propFriction_.value_or(1), filter);
89         json->PutExtAttr("promptText", propLoadingText_.value_or(std::string()).c_str(), filter);
90         if (propPullDownRatio_.has_value()) {
91             json->PutExtAttr("pullDownRatio", propPullDownRatio_.value(), filter);
92         } else {
93             json->PutExtAttr("pullDownRatio", "", filter);
94         }
95         if (propMaxPullDownDistance_.has_value()) {
96             json->PutExtAttr("maxPullDownDistance", propMaxPullDownDistance_.value(), filter);
97         } else {
98             json->PutExtAttr("maxPullDownDistance", "", filter);
99         }
100     }
101 
102     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsRefreshing, bool, PROPERTY_UPDATE_LAYOUT);
103     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IndicatorOffset, Dimension, PROPERTY_UPDATE_LAYOUT);
104     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Friction, int32_t, PROPERTY_UPDATE_LAYOUT);
105     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LoadingText, std::string, PROPERTY_UPDATE_LAYOUT);
106     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PullToRefresh, bool, PROPERTY_UPDATE_LAYOUT);
107     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshOffset, Dimension, PROPERTY_UPDATE_LAYOUT);
108     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PullDownRatio, float, PROPERTY_UPDATE_LAYOUT);
109     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(MaxPullDownDistance, float, PROPERTY_UPDATE_LAYOUT);
110     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsCustomBuilderExist, bool, PROPERTY_UPDATE_LAYOUT);
111 
112 private:
113     ACE_DISALLOW_COPY_AND_MOVE(RefreshLayoutProperty);
114 };
115 } // namespace OHOS::Ace::NG
116 
117 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_TEXT_LAYOUT_PROPERTY_H
118