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 "frameworks/core/components_ng/layout/layout_property.h" 20 #include "frameworks/core/components_ng/property/property.h" 21 22 namespace OHOS::Ace::NG { 23 24 enum class RefreshStatus { 25 // The default status. 26 INACTIVE = 0, 27 // While being dragged but not enough to trig refresh. 28 DRAG, 29 // Dragging enough to refresh, and less than the max distance. 30 OVER_DRAG, 31 // While it is refreshing. 32 REFRESH, 33 // While it will scroll back to the top after refreshing. 34 DONE, 35 }; 36 37 class ACE_EXPORT RefreshLayoutProperty : public LayoutProperty { 38 DECLARE_ACE_TYPE(RefreshLayoutProperty, LayoutProperty); 39 40 public: 41 RefreshLayoutProperty() = default; 42 43 ~RefreshLayoutProperty() override = default; 44 Clone()45 RefPtr<LayoutProperty> Clone() const override 46 { 47 auto value = MakeRefPtr<RefreshLayoutProperty>(); 48 value->UpdateLayoutProperty(this); 49 value->propIsRefreshing_ = CloneIsRefreshing(); 50 value->propIndicatorOffset_ = CloneIndicatorOffset(); 51 value->propFriction_ = CloneFriction(); 52 value->propProgressColor_ = CloneProgressColor(); 53 return value; 54 } 55 Reset()56 void Reset() override 57 { 58 LayoutProperty::Reset(); 59 ResetIsRefreshing(); 60 ResetIndicatorOffset(); 61 ResetFriction(); 62 ResetProgressColor(); 63 } 64 ToJsonValue(std::unique_ptr<JsonValue> & json)65 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override 66 { 67 LayoutProperty::ToJsonValue(json); 68 69 json->Put("offset", propIndicatorOffset_.value_or(Dimension(0, DimensionUnit::VP)).ToString().c_str()); 70 json->Put("friction", propFriction_.value_or(1)); 71 } 72 73 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsRefreshing, bool, PROPERTY_UPDATE_LAYOUT); 74 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IndicatorOffset, Dimension, PROPERTY_UPDATE_LAYOUT); 75 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Friction, int32_t, PROPERTY_UPDATE_LAYOUT); 76 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ProgressColor, Color, PROPERTY_UPDATE_LAYOUT); 77 78 private: 79 ACE_DISALLOW_COPY_AND_MOVE(RefreshLayoutProperty); 80 }; 81 } // namespace OHOS::Ace::NG 82 83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_TEXT_LAYOUT_PROPERTY_H 84