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