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/navigator_model_impl.h" 17 18 #include "core/components/box/box_component.h" 19 #include "core/components/navigator/navigator_component.h" 20 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" 21 22 namespace OHOS::Ace::Framework { 23 Create()24void NavigatorModelImpl::Create() 25 { 26 RefPtr<OHOS::Ace::Component> child; 27 auto navigatorComponent = AceType::MakeRefPtr<OHOS::Ace::NavigatorComponent>(child); 28 ViewStackProcessor::GetInstance()->Push(navigatorComponent); 29 } 30 SetType(NavigatorType value)31void NavigatorModelImpl::SetType(NavigatorType value) 32 { 33 auto navigator = AceType::DynamicCast<NavigatorComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 34 navigator->SetType(value); 35 } 36 SetActive(bool active)37void NavigatorModelImpl::SetActive(bool active) 38 { 39 auto navigator = AceType::DynamicCast<NavigatorComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 40 if (navigator) { 41 navigator->SetActive(active); 42 } 43 } 44 SetUri(const std::string & uri)45void NavigatorModelImpl::SetUri(const std::string& uri) 46 { 47 auto navigator = AceType::DynamicCast<NavigatorComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 48 if (navigator) { 49 navigator->SetUri(uri); 50 } 51 } 52 SetParams(const std::string & params)53void NavigatorModelImpl::SetParams(const std::string& params) 54 { 55 auto navigator = AceType::DynamicCast<NavigatorComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 56 if (navigator) { 57 navigator->SetParams(params); 58 } 59 } 60 SetIsDefWidth(bool isDefWidth)61void NavigatorModelImpl::SetIsDefWidth(bool isDefWidth) 62 { 63 auto navigator = AceType::DynamicCast<NavigatorComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 64 if (navigator) { 65 navigator->SetIsDefWidth(true); 66 } 67 } 68 SetIsDefHeight(bool isDefHeight)69void NavigatorModelImpl::SetIsDefHeight(bool isDefHeight) 70 { 71 auto navigator = AceType::DynamicCast<NavigatorComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 72 if (navigator) { 73 navigator->SetIsDefHeight(true); 74 } 75 } 76 77 } // namespace OHOS::Ace::Framework 78