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