• 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 "bridge/declarative_frontend/jsview/js_tabs_controller.h"
17 
18 #include "bridge/declarative_frontend/engine/bindings.h"
19 
20 namespace OHOS::Ace::Framework {
21 namespace {
22 
23 int32_t g_tabControllerId = 0;
24 
25 } // namespace
26 
JSTabsController()27 JSTabsController::JSTabsController()
28 {
29     controller_ = CreateController();
30 }
31 
JSBind(BindingTarget globalObj)32 void JSTabsController::JSBind(BindingTarget globalObj)
33 {
34     JSClass<JSTabsController>::Declare("TabsController");
35     JSClass<JSTabsController>::Method("changeIndex", &JSTabsController::ChangeIndex);
36     JSClass<JSTabsController>::Bind(globalObj, JSTabsController::Constructor, JSTabsController::Destructor);
37 }
38 
Constructor(const JSCallbackInfo & args)39 void JSTabsController::Constructor(const JSCallbackInfo& args)
40 {
41     auto jsCalendarController = Referenced::MakeRefPtr<JSTabsController>();
42     jsCalendarController->IncRefCount();
43     args.SetReturnValue(Referenced::RawPtr(jsCalendarController));
44 }
45 
Destructor(JSTabsController * controller)46 void JSTabsController::Destructor(JSTabsController* controller)
47 {
48     if (controller != nullptr) {
49         controller->DecRefCount();
50     }
51 }
52 
CreateController()53 RefPtr<TabController> JSTabsController::CreateController()
54 {
55     return TabController::GetController(++g_tabControllerId);
56 }
57 
ChangeIndex(int32_t index)58 void JSTabsController::ChangeIndex(int32_t index)
59 {
60     if (controller_) {
61         controller_->SetIndexByController(index, false);
62     }
63 }
64 
65 } // namespace OHOS::Ace::Framework