1 /*
2  * Copyright (c) 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_FOLDER_STACK_LAYOUT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FOLDER_STACK_LAYOUT_PROPERTY_H
18 
19 #include "core/components_ng/base/inspector_filter.h"
20 #include "core/components_ng/layout/layout_property.h"
21 #include "core/components_ng/pattern/stack/stack_layout_property.h"
22 
23 namespace OHOS::Ace::NG {
24 constexpr int32_t HINGES_OFFSET_UP = 16;
25 constexpr int32_t HINGES_OFFSET_DOWN = 16;
26 class ACE_EXPORT FolderStackLayoutProperty : public StackLayoutProperty {
27     DECLARE_ACE_TYPE(FolderStackLayoutProperty, StackLayoutProperty);
28 
29 public:
30     FolderStackLayoutProperty() = default;
31 
32     ~FolderStackLayoutProperty() override = default;
33 
Clone()34     RefPtr<LayoutProperty> Clone() const override
35     {
36         auto layoutProperty = MakeRefPtr<FolderStackLayoutProperty>();
37         layoutProperty->UpdateLayoutProperty(this);
38         return layoutProperty;
39     }
40 
Reset()41     void Reset() override
42     {
43         StackLayoutProperty::Reset();
44         ResetEnableAnimation();
45         ResetAutoHalfFold();
46         ResetUpperItems();
47     }
48 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)49     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
50     {
51         LayoutProperty::ToJsonValue(json, filter);
52         /* no fixed attr below, just return */
53         if (filter.IsFastFilter()) {
54             return;
55         }
56         auto align = Alignment::CENTER;
57         if (GetPositionProperty()) {
58             align = GetPositionProperty()->GetAlignment().value_or(Alignment::CENTER);
59         }
60         json->PutExtAttr("alignContent", align.GetAlignmentStr(TextDirection::LTR).c_str(), filter);
61         if (HasUpperItems()) {
62             auto itemId = GetUpperItemsValue();
63             std::string str;
64             str.assign("[");
65             for (auto& id : itemId) {
66                 str.append(id);
67                 str.append(", ");
68             }
69             str = (itemId.size() > 1) ? str.substr(0, str.size() - 1).append("]") : str.append("]");
70             json->PutExtAttr("upperItems", str.c_str(), filter);
71             json->PutExtAttr("enableAnimation", propEnableAnimation_.value_or(true) ? "true" : "false", filter);
72             json->PutExtAttr("autoHalfFold", propAutoHalfFold_.value_or(true) ? "true" : "false", filter);
73         }
74     }
75 
76     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(EnableAnimation, bool, PROPERTY_UPDATE_MEASURE_SELF);
77     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(AutoHalfFold, bool, PROPERTY_UPDATE_MEASURE_SELF);
78     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(UpperItems, std::vector<std::string>, PROPERTY_UPDATE_MEASURE_SELF);
79 
80 private:
81     ACE_DISALLOW_COPY_AND_MOVE(FolderStackLayoutProperty);
82 };
83 } // namespace OHOS::Ace::NG
84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FOLDER_STACK_FOLDER_STACK_LAYOUT_PROPERTY_H
85