• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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_LIST_LIST_LAYOUT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_LAYOUT_PROPERTY_H
18 
19 #include <type_traits>
20 
21 #include "base/geometry/axis.h"
22 #include "base/utils/macros.h"
23 #include "core/components/common/layout/constants.h"
24 #include "core/components_ng/layout/layout_property.h"
25 #include "core/components_ng/property/property.h"
26 #include "core/components_v2/list/list_component.h"
27 
28 namespace OHOS::Ace::NG {
29 class InspectorFilter;
30 
31 struct CacheRange {
32     int32_t min;
33     int32_t max;
34     bool operator==(const CacheRange& other) const
35     {
36         return min == other.min && max == other.max;
37     }
38 };
39 
40 class ACE_EXPORT ListLayoutProperty : public LayoutProperty {
41     DECLARE_ACE_TYPE(ListLayoutProperty, LayoutProperty);
42 
43 public:
44     ListLayoutProperty() = default;
45 
46     ~ListLayoutProperty() override = default;
47 
Clone()48     RefPtr<LayoutProperty> Clone() const override
49     {
50         auto value = MakeRefPtr<ListLayoutProperty>();
51         value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this));
52         value->propSpace_ = CloneSpace();
53         value->propInitialIndex_ = CloneInitialIndex();
54         value->propListDirection_ = CloneListDirection();
55         value->propDivider_ = CloneDivider();
56         value->propLanes_ = CloneLanes();
57         value->propLaneMinLength_ = CloneLaneMinLength();
58         value->propLaneMaxLength_ = CloneLaneMaxLength();
59         value->propLaneGutter_ = CloneLaneGutter();
60         value->propListItemAlign_ = CloneListItemAlign();
61         value->propCachedCount_ = CloneCachedCount();
62         value->propShowCachedItems_ = CloneShowCachedItems();
63         value->propStickyStyle_ = CloneStickyStyle();
64         value->propContentStartOffset_ = CloneContentStartOffset();
65         value->propContentEndOffset_ = CloneContentEndOffset();
66         value->propScrollSnapAlign_ = CloneScrollSnapAlign();
67         value->propEditMode_ = CloneEditMode();
68         value->propScrollEnabled_ = CloneScrollEnabled();
69         value->propStackFromEnd_ = CloneStackFromEnd();
70         value->propSyncLoad_ = CloneSyncLoad();
71         value->propCacheRange_ = CloneCacheRange();
72         return value;
73     }
74 
Reset()75     void Reset() override
76     {
77         LayoutProperty::Reset();
78         ResetSpace();
79         ResetInitialIndex();
80         ResetListDirection();
81         ResetDivider();
82         ResetLanes();
83         ResetLaneMinLength();
84         ResetLaneMaxLength();
85         ResetLaneGutter();
86         ResetListItemAlign();
87         ResetCachedCount();
88         ResetShowCachedItems();
89         ResetStickyStyle();
90         ResetContentStartOffset();
91         ResetContentEndOffset();
92         ResetScrollSnapAlign();
93         ResetEditMode();
94         ResetScrollEnabled();
95         ResetStackFromEnd();
96         ResetSyncLoad();
97         ResetCacheRange();
98     }
99 
SetDefaultCachedCount(const int32_t cachedCount)100     void SetDefaultCachedCount(const int32_t cachedCount)
101     {
102         defCachedCount_ = cachedCount;
103     }
104 
GetCachedCountWithDefault()105     int32_t GetCachedCountWithDefault() const
106     {
107         if (propCacheRange_.has_value()) {
108             auto& range = propCacheRange_.value();
109             return std::max(range.min, range.max);
110         }
111         return GetCachedCountValue(defCachedCount_);
112     }
113 
GetMinCacheCount()114     int32_t GetMinCacheCount() const
115     {
116         if (propCacheRange_.has_value()) {
117             return propCacheRange_.value().min;
118         }
119         return GetCachedCountValue(defCachedCount_);
120     }
121 
122     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
123 
124     void FromJson(const std::unique_ptr<JsonValue>& json) override;
125 
126     void ScrollSnapPropToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const;
127 
128     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Space, Dimension, PROPERTY_UPDATE_MEASURE);
129     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(InitialIndex, int32_t, PROPERTY_UPDATE_MEASURE);
130     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ListDirection, Axis, PROPERTY_UPDATE_MEASURE);
131     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Divider, V2::ItemDivider, PROPERTY_UPDATE_MEASURE);
132     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Lanes, int32_t, PROPERTY_UPDATE_MEASURE);
133     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LaneMinLength, Dimension, PROPERTY_UPDATE_MEASURE);
134     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LaneMaxLength, Dimension, PROPERTY_UPDATE_MEASURE);
135     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LaneGutter, Dimension, PROPERTY_UPDATE_MEASURE);
136     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ListItemAlign, V2::ListItemAlign, PROPERTY_UPDATE_MEASURE);
137     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CachedCount, int32_t, PROPERTY_UPDATE_MEASURE);
138     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ShowCachedItems, bool, PROPERTY_UPDATE_MEASURE);
139     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(StickyStyle, V2::StickyStyle, PROPERTY_UPDATE_MEASURE);
140     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ScrollSnapAlign, ScrollSnapAlign, PROPERTY_UPDATE_MEASURE);
141     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ChainAnimation, bool, PROPERTY_UPDATE_MEASURE);
142     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ContentStartOffset, float, PROPERTY_UPDATE_MEASURE);
143     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ContentEndOffset, float, PROPERTY_UPDATE_MEASURE);
144     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EditMode, bool, PROPERTY_UPDATE_MEASURE);
145     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ScrollEnabled, bool, PROPERTY_UPDATE_MEASURE);
146     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(StackFromEnd, bool, PROPERTY_UPDATE_MEASURE);
147     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SyncLoad, bool, PROPERTY_UPDATE_NORMAL);
148     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DividerColorSetByUser, bool, PROPERTY_UPDATE_NORMAL);
149     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CacheRange, CacheRange, PROPERTY_UPDATE_MEASURE_SELF);
150 
151     int32_t defCachedCount_ = 1;
152 protected:
153     void UpdateLayoutProperty(const ListLayoutProperty* layoutProperty);
154 };
155 } // namespace OHOS::Ace::NG
156 
157 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_LAYOUT_PROPERTY_H
158