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 #include "bridge/declarative_frontend/jsview/models/row_model_impl.h"
17 
18 #include "base/memory/referenced.h"
19 #include "core/components/flex/flex_component.h"
20 #include "core/components/wrap/wrap_component.h"
21 #include "core/components_ng/pattern/flex/flex_model.h"
22 #include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h"
23 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
24 
25 namespace OHOS::Ace::Framework {
26 
Create(const std::optional<Dimension> & space,AlignDeclaration * declaration,const std::string & tag)27 void RowModelImpl::Create(const std::optional<Dimension>& space, AlignDeclaration* declaration, const std::string& tag)
28 {
29     std::list<RefPtr<Component>> children;
30     RefPtr<RowComponent> rowComponent =
31         AceType::MakeRefPtr<OHOS::Ace::RowComponent>(FlexAlign::FLEX_START, FlexAlign::CENTER, children);
32     ViewStackProcessor::GetInstance()->ClaimElementId(rowComponent);
33     rowComponent->SetMainAxisSize(MainAxisSize::MIN);
34     rowComponent->SetCrossAxisSize(CrossAxisSize::MIN);
35     if (space.has_value() && space->Value() >= 0.0) {
36         rowComponent->SetSpace(space.value());
37     }
38     if (declaration != nullptr) {
39         rowComponent->SetAlignDeclarationPtr(declaration);
40     }
41     ViewStackProcessor::GetInstance()->Push(rowComponent);
42 }
43 
SetAlignItems(FlexAlign flexAlign)44 void RowModelImpl::SetAlignItems(FlexAlign flexAlign)
45 {
46     FlexModel::GetInstance()->SetAlignItems(static_cast<int32_t>(flexAlign));
47 }
48 
SetJustifyContent(FlexAlign flexAlign)49 void RowModelImpl::SetJustifyContent(FlexAlign flexAlign)
50 {
51     FlexModel::GetInstance()->SetJustifyContent(static_cast<int32_t>(flexAlign));
52 }
53 
CreateWithWrap()54 void RowModelImpl::CreateWithWrap()
55 {
56     std::list<RefPtr<Component>> children;
57     RefPtr<OHOS::Ace::WrapComponent> component = AceType::MakeRefPtr<WrapComponent>(0.0, 0.0, children);
58 
59     component->SetDirection(WrapDirection::HORIZONTAL);
60     component->SetMainAlignment(WrapAlignment::START);
61     component->SetCrossAlignment(WrapAlignment::START);
62     component->SetAlignment(WrapAlignment::START);
63     component->SetDialogStretch(false);
64 
65     ViewStackProcessor::GetInstance()->Push(component);
66 }
67 
68 } // namespace OHOS::Ace::Framework
69