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 #include "frameworks/bridge/declarative_frontend/jsview/models/blank_model_impl.h"
17 
18 #include "base/utils/utils.h"
19 #include "core/components/box/box_component.h"
20 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
21 
22 namespace OHOS::Ace::Framework {
Create()23 void BlankModelImpl::Create()
24 {
25     auto specializedBox = AceType::MakeRefPtr<OHOS::Ace::BoxComponent>();
26 
27     // specialized component should be firstly pushed.
28     ViewStackProcessor::GetInstance()->ClaimElementId(specializedBox);
29     ViewStackProcessor::GetInstance()->Push(specializedBox);
30 
31     // Blank fill the remain space.
32     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
33     flexItem->SetFlexGrow(1);
34     flexItem->SetFlexShrink(0);
35     flexItem->SetMustStretch(true);
36 }
37 
SetBlankMin(const Dimension & blankMin)38 void BlankModelImpl::SetBlankMin(const Dimension& blankMin)
39 {
40     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
41     flexItem->SetFlexBasis(blankMin.IsValid() ? blankMin : Dimension());
42 }
43 
SetHeight(const Dimension & height)44 void BlankModelImpl::SetHeight(const Dimension& height)
45 {
46     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
47     if (height > flexItem->GetFlexBasis()) {
48         flexItem->SetFlexBasis(height);
49     }
50 }
51 
SetColor(const Color & color)52 void BlankModelImpl::SetColor(const Color& color)
53 {
54     auto blank = ViewStackProcessor::GetInstance()->GetBoxComponent();
55     CHECK_NULL_VOID(blank);
56     blank->SetColor(color);
57 }
58 } // namespace OHOS::Ace::Framework
59