• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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/js_blank.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(const JSCallbackInfo & info)22 void JSBlank::Create(const JSCallbackInfo& info)
23 {
24     auto specializedBox = AceType::MakeRefPtr<OHOS::Ace::BoxComponent>();
25     // specialized component should be firstly pushed.
26     ViewStackProcessor::GetInstance()->Push(specializedBox);
27     // Blank fill the remain space.
28     auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
29     flexItem->SetFlexGrow(1);
30     flexItem->SetFlexShrink(0);
31     flexItem->SetMustStretch(true);
32 
33     Dimension flexBasis;
34     if (info.Length() >= 1 && ParseJsDimensionVp(info[0], flexBasis)) {
35         flexItem->SetFlexBasis(flexBasis);
36     }
37 }
38 
JSBind(BindingTarget globalObj)39 void JSBlank::JSBind(BindingTarget globalObj)
40 {
41     JSClass<JSBlank>::Declare("Blank");
42     MethodOptions opt = MethodOptions::NONE;
43     JSClass<JSBlank>::StaticMethod("create", &JSBlank::Create, opt);
44     JSClass<JSBlank>::StaticMethod("color", &JSViewAbstract::JsBackgroundColor, opt);
45     JSClass<JSBlank>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
46     JSClass<JSBlank>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
47     JSClass<JSBlank>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
48     JSClass<JSBlank>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
49     JSClass<JSBlank>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
50     JSClass<JSBlank>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
51     JSClass<JSBlank>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
52     JSClass<JSBlank>::StaticMethod("remoteMessage", &JSInteractableView::JsCommonRemoteMessage);
53 
54     JSClass<JSBlank>::Inherit<JSViewAbstract>();
55     JSClass<JSBlank>::Bind<>(globalObj);
56 }
57 } // namespace OHOS::Ace::Framework
58