1 /* 2 * Copyright (c) 2022 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_SCROLL_SCROLL_LAYOUT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_LAYOUT_PROPERTY_H 18 19 #include <memory> 20 #include <unordered_map> 21 22 #include "base/geometry/axis.h" 23 #include "base/utils/macros.h" 24 #include "core/components/common/layout/constants.h" 25 #include "core/components_ng/base/inspector_filter.h" 26 #include "core/components_ng/layout/layout_property.h" 27 #include "core/components_ng/pattern/scroll/scroll_edge_effect.h" 28 #include "core/components_ng/property/property.h" 29 30 namespace OHOS::Ace::NG { 31 class ACE_EXPORT ScrollLayoutProperty : public LayoutProperty { 32 DECLARE_ACE_TYPE(ScrollLayoutProperty, LayoutProperty); 33 34 public: 35 ScrollLayoutProperty() = default; 36 Clone()37 RefPtr<LayoutProperty> Clone() const override 38 { 39 auto value = MakeRefPtr<ScrollLayoutProperty>(); 40 value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this)); 41 value->propAxis_ = CloneAxis(); 42 value->propScrollEnabled_ = CloneScrollEnabled(); 43 value->propScrollSnapAlign_ = CloneScrollSnapAlign(); 44 value->propScrollContentEndOffset_ = CloneScrollContentEndOffset(); 45 return value; 46 } 47 Reset()48 void Reset() override 49 { 50 LayoutProperty::Reset(); 51 ResetAxis(); 52 ResetScrollEnabled(); 53 ResetScrollContentEndOffset(); 54 } 55 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)56 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 57 { 58 LayoutProperty::ToJsonValue(json, filter); 59 std::unordered_map<Axis, std::string> scrollableMap { { Axis::VERTICAL, "ScrollDirection.Vertical" }, 60 { Axis::HORIZONTAL, "ScrollDirection.Horizontal" }, { Axis::FREE, "ScrollDirection.Free" }, 61 { Axis::NONE, "ScrollDirection.None" } }; 62 Axis axis = GetAxisValue(Axis::VERTICAL); 63 json->PutFixedAttr("scrollable", scrollableMap[axis].c_str(), filter, FIXED_ATTR_SCROLLABLE); 64 /* no fixed attr below, just return */ 65 if (filter.IsFastFilter()) { 66 return; 67 } 68 json->PutExtAttr("enableScrollInteraction", propScrollEnabled_.value_or(true), filter); 69 std::unordered_map<ScrollSnapAlign, std::string> scrollSnapAlignMap { 70 { ScrollSnapAlign::NONE, "ScrollSnapAlign.NONE" }, { ScrollSnapAlign::START, "ScrollSnapAlign.START" }, 71 { ScrollSnapAlign::CENTER, "ScrollSnapAlign::CENTER" }, { ScrollSnapAlign::END, "ScrollSnapAlign::END" } 72 }; 73 ScrollSnapAlign scrollSnapAlign = propScrollSnapAlign_.value_or(ScrollSnapAlign::NONE); 74 json->PutExtAttr("scrollSnapAlign", scrollSnapAlignMap[scrollSnapAlign].c_str(), filter); 75 } 76 77 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Axis, Axis, PROPERTY_UPDATE_MEASURE); 78 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ScrollEnabled, bool, PROPERTY_UPDATE_MEASURE); 79 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ScrollSnapAlign, ScrollSnapAlign, PROPERTY_UPDATE_MEASURE); 80 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ScrollWidth, float, PROPERTY_UPDATE_MEASURE); 81 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ScrollContentEndOffset, float, PROPERTY_UPDATE_MEASURE); 82 }; 83 84 } // namespace OHOS::Ace::NG 85 86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_LAYOUT_PROPERTY_H 87