• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/components_ng/pattern/animator/animator_model_ng.h"
17 
18 #include "bridge/declarative_frontend/declarative_frontend.h"
19 #include "core/common/container.h"
20 #include "core/components_ng/pattern/stage/page_pattern.h"
21 #ifdef PLUGIN_COMPONENT_SUPPORTED
22 #include "core/common/plugin_manager.h"
23 #endif
24 
25 namespace OHOS::Ace::Framework {
26 namespace {
GetCurrentPage()27 RefPtr<NG::PagePattern> GetCurrentPage()
28 {
29     RefPtr<NG::FrameNode> pageNode;
30 #ifdef PLUGIN_COMPONENT_SUPPORTED
31     if (Container::CurrentId() >= MIN_PLUGIN_SUBCONTAINER_ID) {
32         auto pluginContainer = PluginManager::GetInstance().GetPluginSubContainer(Container::CurrentId());
33         CHECK_NULL_RETURN(pluginContainer, nullptr);
34         pageNode = pluginContainer->GetPluginNode().Upgrade();
35         CHECK_NULL_RETURN(pageNode, nullptr);
36     } else
37 #endif
38     {
39         auto container = Container::Current();
40         CHECK_NULL_RETURN(container, nullptr);
41         auto frontEnd = AceType::DynamicCast<DeclarativeFrontend>(container->GetFrontend());
42         CHECK_NULL_RETURN(frontEnd, nullptr);
43         auto pageRouterManager = frontEnd->GetPageRouterManager();
44         CHECK_NULL_RETURN(pageRouterManager, nullptr);
45         pageNode = pageRouterManager->GetCurrentPageNode();
46         CHECK_NULL_RETURN(pageNode, nullptr);
47     }
48     return pageNode->GetPattern<NG::PagePattern>();
49 }
50 } // namespace
51 
Create(const std::string & animatorId)52 void AnimatorModelNG::Create(const std::string& animatorId)
53 {
54     auto page = GetCurrentPage();
55     CHECK_NULL_VOID(page);
56     auto animatorInfo = page->GetJsAnimator(animatorId);
57     if (!animatorInfo) {
58         animatorInfo = AceType::MakeRefPtr<AnimatorInfo>();
59         auto animator = AceType::MakeRefPtr<Animator>();
60         animatorInfo->SetAnimator(animator);
61         page->AddJsAnimator(animatorId, animatorInfo);
62     }
63 }
64 
GetAnimatorInfo(const std::string & animatorId)65 RefPtr<AnimatorInfo> AnimatorModelNG::GetAnimatorInfo(const std::string& animatorId)
66 {
67     auto page = GetCurrentPage();
68     CHECK_NULL_RETURN(page, nullptr);
69     auto animatorInfo = page->GetJsAnimator(animatorId);
70     return animatorInfo;
71 }
72 } // namespace OHOS::Ace::Framework