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->propIsCustomBuilderExist_ = CloneIsCustomBuilderExist(); 58 return value; 59 } 60 Reset()61 void Reset() override 62 { 63 LayoutProperty::Reset(); 64 ResetIsRefreshing(); 65 ResetIndicatorOffset(); 66 ResetFriction(); 67 ResetLoadingText(); 68 ResetPullToRefresh(); 69 ResetRefreshOffset(); 70 ResetPullDownRatio(); 71 ResetIsCustomBuilderExist(); 72 } 73 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)74 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 75 { 76 LayoutProperty::ToJsonValue(json, filter); 77 /* no fixed attr below, just return */ 78 if (filter.IsFastFilter()) { 79 return; 80 } 81 json->PutExtAttr( 82 "offset", propIndicatorOffset_.value_or(Dimension(0, DimensionUnit::VP)).ToString().c_str(), filter); 83 json->PutExtAttr( 84 "refreshOffset", propRefreshOffset_.value_or(Dimension(0, DimensionUnit::VP)).ToString().c_str(), filter); 85 json->PutExtAttr("pullToRefresh", propPullToRefresh_.value_or(true), filter); 86 json->PutExtAttr("friction", propFriction_.value_or(1), filter); 87 json->PutExtAttr("promptText", propLoadingText_.value_or(std::string()).c_str(), filter); 88 if (propPullDownRatio_.has_value()) { 89 json->PutExtAttr("pullDownRatio", propPullDownRatio_.value(), filter); 90 } else { 91 json->PutExtAttr("pullDownRatio", "", filter); 92 } 93 } 94 95 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsRefreshing, bool, PROPERTY_UPDATE_LAYOUT); 96 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IndicatorOffset, Dimension, PROPERTY_UPDATE_LAYOUT); 97 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Friction, int32_t, PROPERTY_UPDATE_LAYOUT); 98 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LoadingText, std::string, PROPERTY_UPDATE_LAYOUT); 99 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PullToRefresh, bool, PROPERTY_UPDATE_LAYOUT); 100 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshOffset, Dimension, PROPERTY_UPDATE_LAYOUT); 101 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PullDownRatio, float, PROPERTY_UPDATE_LAYOUT); 102 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsCustomBuilderExist, bool, PROPERTY_UPDATE_LAYOUT); 103 104 private: 105 ACE_DISALLOW_COPY_AND_MOVE(RefreshLayoutProperty); 106 }; 107 } // namespace OHOS::Ace::NG 108 109 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_TEXT_LAYOUT_PROPERTY_H 110